Skip to content

Read ×, ÷ and − as operators, and several words before = as a label - #15

Merged
sanjaydotpro merged 2 commits into
mainfrom
capy/calc-operator-signs
Nov 17, 2026
Merged

sanjaydotpro merged 2 commits into
mainfrom
capy/calc-operator-signs

Conversation

@sanjaydotpro

@sanjaydotpro sanjaydotpro commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Merge after #5. It merges cleanly on top of #5.

This fixes HIS-17. In the Riverbank sample note, looker connector = 29 usd and outreach seats = 3 × 49 usd showed no result, so total read 129.00 USD where Paper shows 305.00 USD. 3 × 49 usd on its own showed 49.00 USD. There are two causes, one commit each.

Signs

Cause

Lexer._isIdentStart treats every character past ASCII that isn't a currency symbol as a letter, and the lexer looks for names before it looks for operators. So ×, ÷ and − (U+2212) became words, and neither the parser's × and ÷ rules nor the engine's label rules ever saw them as operators. 3 × 49 usd then failed to parse, and the labelled-amount fallback read 3 × as a label and kept only 49 usd. The result was a wrong answer rather than no answer.

Change

  • ×, ÷ and − are no longer read as letters, so they lex as the operators the lexer already lists.
  • En and em dashes stay text. Prose joins ranges with them (2020–2024, pages 10–20), and they have never worked as operators. They come out of the operator list, and so do the dash entries in the parser's additive and unary rules and in the engine's label rules, which could never be reached.
Line Before After
3 × 49 usd 49.00 USD 147.00 USD
10 ÷ 4 nothing 2.5
10 − 3 nothing 7
−5 nothing -5
1920×1080 nothing 2,073,600

3 x 49 usd and 3 * 49 usd still give 147.00 USD. Lines with dashes give exactly what they did before: Lunch — 12 usd is 12.00 USD, and 2020–2024, pages 10–20 and 10 – 3 give nothing. In the editor, ×, ÷ and − are now coloured as operators, like *, and dashes stay plain text.

Several words before =

A name before = had to be a single word, so looker connector = 29 usd gave nothing, while looker connector: 29 usd gave 29.00 USD. As Sanjay chose (option A on HIS-17), several words before the first = now label the amount the way a colon does. The line shows its amount and counts in the total, but it names nothing, so a later looker connector * 12 still gives nothing.

Line Before After
looker connector = 29 usd nothing 29.00 USD
outreach seats = 3 × 49 usd nothing 147.00 USD
monthly rent = 1200 usd nothing 1,200.00 USD
my budget = 120 nothing 120
total in the sample note 129.00 USD 305.00 USD

A single name before = is still an assignment, and lines such as meeting = 12:30 and n = Room 12 give what they did before. Colons are still read first, so Q1: revenue = 1000 still defines revenue. Colours don't change.

Verification

  • flutter analyze reports no issues.
  • New tests in calc_engine_test.dart cover:
    • the three signs, x and * unchanged, and dashes left as text
    • several words before =, the label naming nothing, a single name still assigning, and a colon read first
    • the sample note line by line, with total at 305.00 USD
  • New tests in highlight_test.dart cover operator colouring for the signs and plain text for dashes.
  • I ran sample lines through the engine and the highlighter before and after each commit. For the signs, only the five lines with ×, ÷ or − changed among 20. For names, only lines with more than a single name before = changed among 81. Colours were identical for every line.
  • I ran the whole suite on Flutter 3.47.4 (~/dev/flutter), because the pinned 3.47.2 on this Mac can't run tests:
  • CI analyzes and builds the desktop apps but runs no tests.

Open in Capy

The lexer treated every character past ASCII that isn't a currency
symbol as a letter, and it looks for names before operators, so ×, ÷
and the minus sign − lexed as words. `3 × 49 usd` failed to parse and
the label fallback kept only `49 usd`, showing 49.00 USD, while
`10 ÷ 4` and `10 − 3` showed nothing. They now lex as the operators
the parser already handles.

En and em dashes stay text, as they always have in practice: prose
joins ranges with them, as in `2020–2024` and `pages 10–20`. They come
out of the operator list, along with the dash handling in the parser
and the label rules that could never be reached.
A name before = had to be a single word, so `looker connector = 29 usd`
gave nothing while `looker connector: 29 usd` gave 29.00 USD. Several
words before the first = now label the amount the way a colon does: the
line shows it and counts in the total, and names nothing a later line can
use. A single name is still an assignment, and colons are still read
first, so `Q1: revenue = 1000` still defines revenue.

With the sign fix, Riverbank's sample note computes as Paper shows it:
29.00 USD, 147.00 USD and a total of 305.00 USD.
@capy-ai capy-ai Bot changed the title Read ×, ÷ and − as operators in calculations Read ×, ÷ and − as operators, and several words before = as a label Nov 17, 2026
@sanjaydotpro
sanjaydotpro merged commit 6d50d5f into main Nov 17, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant