Repository navigation
fix(parser): drop a sign check that ends at its line's first invalid token, as beancount does - #2981
Merged
Merged
Conversation
…token, as beancount does A posting's sign check covers the sign and the blanks after it, so in `-$x` it ends exactly where the invalid token starts. quiet_after_invalid_tokens dropped a construct check only when it ran past the token's start, so this one was kept beside the token's own error, one more per line than bean-check 3.2.3, whose grammar reads the sign and fails at the token. The same held for a balance or price amount check. A check that ends at the token is now dropped like one that runs past it, still only when the line's grammar reads up to the token. Parity corpus: 79,511 -> 79,549 matching, none lost. WASM cache 115 -> 116; loader cache unchanged (every affected file errors before and after). Closes #2967 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
📊 Benchmark Results
vs base, measured in this run
A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: What do these numbers mean?
|
… in for The round-1 review differential found the known mismatch is wider than `-.5 <word>`: a sign before any first invalid token, and a balance or price amount check, both followed by a word our lexer reads as valid tokens (U~SD, U?SD, U%SD). Pin posting and header rows, each checked against bean-check 3.2.3, and reword the CHANGELOG. The lexer gap is #2982. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
robcohen
added a commit
that referenced
this pull request
Nov 14, 2026
…r, and report a header defect before a tag (#2968) (#2983) * fix(parser): no error for a BOM-led account after a line's first error, and report a header defect before a tag A BOM that beancount reads into an account (`<BOM>Assets:A`) after an earlier error on its line got its own BomInDirectiveBody, one error more than bean-check 3.2.3, whose grammar is already recovering there. It is now dropped after an invalid token or a defect the grammar fails at first; an error that stands for the whole line does not count as one. A directive that does not take tags or links was reported only through its tag's error, so the header check never looked for an earlier defect (`close Assets:A TRUE $x #t`), and the tag's error is dropped after an invalid token. The header check now runs there too, and a defect before the tag is reported in its place. The BOM combination matrix takes in the moved counts: 618 more rows match bean-check, and the 9 that no longer do are a mid-line `T#!` that already counts one fewer here, which the dropped BOM error used to make up for; each is accepted with its reason. WASM cache v117 (v116 is held by #2981); the loader cache is unchanged. Closes #2968 Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(parser): pin and document the tag-side counts change 2 moves (#2968) Where the header defect now replaces a directive's tag and link errors, a line whose extra tag errors made up for a token rledger misses (`T#!`, `U?SD`, a second grammar error after `NULL`) counts one fewer than bean-check, and `{#t #u` one more, as `{#t` alone does. Each counts what main counts with its tags and links removed; pinned with those versions, and named in the CHANGELOG entry. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
What
A posting's sign check that ends right where its line's first invalid token starts is no longer reported beside the token's own error. The same goes for a
balanceorpriceamount check that ends there.opens and a*header)Assets:A -$xAssets:A +$Assets:A -$~ 2 USD,-$~@@,-$~ "s",-$~ 1,000Assets:A -$ {Assets:A -<BOM> {Assets:A +<BOM>x EUR \x112024-01-02 balance Assets:A 1 +2x EUR(header)2615-2-3#/\tG:Ψ+t+{(fuzz input), line 2Why
quiet_after_invalid_tokens(cst/convert.rs) drops a construct check that starts before a line's first invalid token, when the line's grammar reads up to that token, because beancount's grammar fails at the token and reports nothing else for the line. It required the check to run past the token's start (e.span.end > at). A sign check covers the sign and the blanks after it, so in-$xit ends exactly at the token and was kept. The condition is now>=. The existing guards are unchanged: only construct checks (not line errors), and only when the line's grammar reads up to the token (indented_grammar_reaches/header_grammar_reaches).Generated differential
Two generators, each input run through bean-check 3.2.3 (the harness's
run_beancount), main (9e834a94ac2) and this branch, comparing per-line counts:$,~,`,\x11, BOM,?,%,|, ...). Each fragment is followed by 0 to 2 blanks and one of 15 tails, with LF, CRLF or EOF endings, 2-space, 4-space or tab indents, an erroring line before (or not), postings after (or not), and a BOM at file start (or not). Controls are the same shapes with a valid token in place of the invalid one and no invalid token anywhere.Only two messages are ever dropped: the posting sign check (6,915 + 1,650 inputs) and the
balance/priceheader's "malformed amount" (13).Known mismatch: a word our lexer does not read as invalid (#2982)
The round-1 review ran its own differential: 394,277 inputs, 3,513 gained, 205 regressed, 292 closer. Every regression there, and the 16 from the offset generator above, has one mechanism. A sign, or a
balance/priceamount, is followed by any invalid token, and later on the same line comes a capital-led word with a character our lexer reads as a token of its own (U~SD,U?SD,U%SD,U$ D). beancount reads that word as one more invalid token; our lexer reads valid tokens. On main, the dropped sign or amount check stood in for the missing error. Without it, the line counts what main counts with no check there.$(46),-$(15),'(13),<BOM>x(12),x(11),$~, a backtick,\x7f,$x,=,<,\,€,\x11, a BOM,.5(7).Assets:A -$ U~SD$ U~SD)Assets:A -' 1 U%SDAssets:A -x U?SDAssets:A -.5 U~SD2024-01-02 balance Assets:A 1 + 2x U?SDbalance Assets:A 2x U?SD)2024-01-02 price HOOL -1 + 2< U?SDprice HOOL 2x U?SD)Posting rows are in a transaction after two
opens andAssets:B 1 USD. Every row was checked with bean-check 3.2.3.test_parse_check_dropped_before_a_word_we_do_not_read_as_invalidpins posting and header rows with each analog. The fix belongs in the lexer and is tracked in #2982.Parity corpus
38 inputs newly match and none are lost. 4 still-mismatching fuzz inputs change category (
lexer-token-splittorl-indented-line); on each, every changed line moved to beancount's count, and what remains is the existing orphan-indented-line gap. The manifest is updated with--update, and--checkpasses.Caches
How to test
Parser tests (all 42 suites),
rustledger-wasmcache tests, clippy-D warnings,cargo fmt --checkandcargo docwith-Dwarningspass. Tworustledger-loaderdiscovertests fail locally on main as well (they walk up from a temp dir); they are not touched here.Closes #2967
🤖 Generated with Claude Code