Repository navigation
Read ×, ÷ and − as operators, and several words before = as a label - #15
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Merge after #5. It merges cleanly on top of #5.
This fixes HIS-17. In the Riverbank sample note,
looker connector = 29 usdandoutreach seats = 3 × 49 usdshowed no result, sototalread 129.00 USD where Paper shows 305.00 USD.3 × 49 usdon its own showed 49.00 USD. There are two causes, one commit each.Signs
Cause
Lexer._isIdentStarttreats 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 usdthen failed to parse, and the labelled-amount fallback read3 ×as a label and kept only49 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.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.3 × 49 usd10 ÷ 410 − 3−51920×10803 x 49 usdand3 * 49 usdstill give 147.00 USD. Lines with dashes give exactly what they did before:Lunch — 12 usdis 12.00 USD, and2020–2024,pages 10–20and10 – 3give 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, solooker connector = 29 usdgave nothing, whilelooker connector: 29 usdgave 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 laterlooker connector * 12still gives nothing.looker connector = 29 usdoutreach seats = 3 × 49 usdmonthly rent = 1200 usdmy budget = 120totalin the sample noteA single name before
=is still an assignment, and lines such asmeeting = 12:30andn = Room 12give what they did before. Colons are still read first, soQ1: revenue = 1000still definesrevenue. Colours don't change.Verification
flutter analyzereports no issues.calc_engine_test.dartcover:xand*unchanged, and dashes left as text=, the label naming nothing, a single name still assigning, and a colon read firsttotalat 305.00 USDhighlight_test.dartcover operator colouring for the signs and plain text for dashes.×,÷or−changed among 20. For names, only lines with more than a single name before=changed among 81. Colours were identical for every line.~/dev/flutter), because the pinned 3.47.2 on this Mac can't run tests:desktop_dark_note_pinned.png, which fails by the same 68 pixels on unchanged main because it calculatesTodayagainst the real clock