Repository navigation
fix(parser): an indented tag or link line in a transaction, then an invalid token, is one error - #3028
Merged
Conversation
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?
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
…nvalid token, is one error beancount's grammar reads a line of tags and links in a transaction's body (posting_or_kv_list INDENT tags_links EOL), so on ` #tag h` bean-check 3.2.3's first error is the lexer's `Invalid token: 'h'`, and its recovery discards the rest of the line. drop_errors_inside_a_line_error only took nothing, a flag or a posting start as a readable prefix, so the line error was reported beside the token's own. In a transaction node a prefix of tags and links now counts as readable too; under any other directive the tag is a syntax error first and both errors stay, as in beancount. A line where a lone capital glued to what follows it (`Z\r`, `Z` at the end of the input) comes after the token keeps both errors: beancount reports that capital as one more invalid token, which the parser does not yet, so main only matched there by coincidence. Parse-error parity: 92,482 -> 92,545 inputs match, 0 regressions. BOM combination matrix: 11,166 -> 11,172 matching. WASM cache v126; the loader cache stays at v75 (parsed directives do not move). Closes #2997 Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
force-pushed
the
fix/indented-tag-line-invalid-token
branch
from
November 25, 2026 19:05
7034d80 to
48d55cb
Compare
robcohen
added a commit
that referenced
this pull request
Nov 26, 2026
…ledger is as quiet as beancount after every failed line beancount's one error rule is `declarations: declarations error`: after a failed statement bison discards what a `declarations` cannot start with, shifts only an end of line, a date or an undated keyword, and reports no syntax error until it has shifted three tokens; only its lexer's errors are reported meanwhile. The earlier windows modeled this for a few line kinds. A new pass, `cst/recovery.rs`, ports beancount's lexer (`lexer.l`) and runs bison's recovery over its tokens from each error rledger reports while bison is not recovering. On every line inside the window it keeps as many of rledger's errors as beancount's lexer finds there. An entry bison builds at a date it shifts mid-line (#2979) is parsed on its own for its body's errors and not emitted, a recovery artifact not copied. A lone capital glued to a `\r` or the end of the input is the invalid token it is to beancount (#3028's leftover). The parity harness moves beancount's `unexpected EOL` errors back one line: rledger reports an end-of-line error on the line it ends, on purpose. Also makes three error lookups linear (multi-line string placement, the posting and metadata line checks), which were quadratic in a file with many parse errors. Parity corpus: 93,185 -> 106,447 matching, 0 regressions. WASM cache 132. Closes #2993 Closes #2979 Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 26, 2026
…ledger is as quiet as beancount after every failed line beancount's one error rule is `declarations: declarations error`: after a failed statement bison discards what a `declarations` cannot start with, shifts only an end of line, a date or an undated keyword, and reports no syntax error until it has shifted three tokens; only its lexer's errors are reported meanwhile. The earlier windows modeled this for a few line kinds. A new pass, `cst/recovery.rs`, ports beancount's lexer (`lexer.l`) and runs bison's recovery over its tokens from each error rledger reports while bison is not recovering. On every line inside the window it keeps as many of rledger's errors as beancount's lexer finds there. An entry bison builds at a date it shifts mid-line (#2979) is parsed on its own for its body's errors and not emitted, a recovery artifact not copied. A lone capital glued to a `\r` or the end of the input is the invalid token it is to beancount (#3028's leftover). The parity harness moves beancount's `unexpected EOL` errors back one line: rledger reports an end-of-line error on the line it ends, on purpose. Also makes three error lookups linear (multi-line string placement, the posting and metadata line checks), which were quadratic in a file with many parse errors. Parity corpus: 93,185 -> 106,447 matching, 0 regressions. WASM cache 132. Closes #2993 Closes #2979 Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 26, 2026
…ledger is as quiet as beancount after every failed line (#3035) beancount's one error rule is `declarations: declarations error`: after a failed statement bison discards what a `declarations` cannot start with, shifts only an end of line, a date or an undated keyword, and reports no syntax error until it has shifted three tokens; only its lexer's errors are reported meanwhile. The earlier windows modeled this for a few line kinds. A new pass, `cst/recovery.rs`, ports beancount's lexer (`lexer.l`) and runs bison's recovery over its tokens from each error rledger reports while bison is not recovering. On every line inside the window it keeps as many of rledger's errors as beancount's lexer finds there. An entry bison builds at a date it shifts mid-line (#2979) is parsed on its own for its body's errors and not emitted, a recovery artifact not copied. A lone capital glued to a `\r` or the end of the input is the invalid token it is to beancount (#3028's leftover). The parity harness moves beancount's `unexpected EOL` errors back one line: rledger reports an end-of-line error on the line it ends, on purpose. Also makes three error lookups linear (multi-line string placement, the posting and metadata line checks), which were quadratic in a file with many parse errors. Parity corpus: 93,185 -> 106,447 matching, 0 regressions. WASM cache 132. Closes #2993 Closes #2979 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
An indented line of tags and links in a transaction, then an invalid token (
#tag h,^link h,#tag $), is now one error, as in bean-check 3.2.3. rledger reported the line's grammar error beside the token's own.Why it works
beancount's grammar reads a tags-and-links line in a transaction's body (
posting_or_kv_list INDENT tags_links EOL). So on#tag hits first error is the lexer'sInvalid token: 'h', and its recovery discards the rest of the line.drop_errors_inside_a_line_error(crates/rustledger-parser/src/cst/convert.rs) merges the generic line error with a line's first invalid token when the prefix before that token is one beancount reads. It accepted nothing, a flag, or a posting start. Inside a transaction node (span ranges gathered during the directive loop), a prefix made only of tags and links now counts as readable too. The line error then stands for the token and takes its name (unexpected input: invalid token 'h'), and each later invalid token is still one more.This is the same place the issue named. The table's misses reach
drop_errors_inside_a_line_error'sreadable_startclosure, notreadable_start_of_an_error_line: inside a transaction the line is not anERROR_NODE, so the latter never sees it.Under
open,balance,note,eventandcustomsuch a line is a syntax error at the tag first. Both errors stay there, as in beancount.Narrowed: one shape keeps main's two errors. That is a line where a lone capital glued to what follows it (
Z\r, orZat the end of the input) comes after the token. beancount reports that capital as one more invalid token, and this parser does not yet do so on any line (h1 Z\r\nis 1 here, 2 in beancount, on main too). main matched there only because the extra line error stood in for it. Applying the fix there would have turned 10 generated inputs from matching to mismatching. The underlying miss is left for a follow-up.Results
Issue rows: all match bean-check 3.2.3 (
P=2024-01-01 open Assets:A\n,T=2024-01-02 * "n"\n):P + T + " #tag h\n"33x23P + T + " ^link h\n"33x23P + T + " #tag $\n"33x23P + T + " #tag hh\n"33x23P + " #tag h\n"2x22x22x2P + T + " h\n"333P + T + " Assets:A 1 USD h\n"333P + T + " #tag\n" + postings---Parse-error parity corpus (pinned fuzz
9bc79f4f, matrix, tracked, compat; beancount 3.2.3 from nixpkgs): 92,482 → 92,545 inputs match, with 0 regressions against main's committed manifest. 67 pins were stale: 63 inputs now match and 4 changed category. The manifest is rewritten with--update, and only id lines move.Generated differential: a generator built transaction bodies (and
open/balance/custom/event/note/commodity/price/padbodies). Their lines held tag and link runs with invalid tokens inserted, glued and repeated, plus other tokens, postings, metadata, comments, blank lines, mixed indentation, CRLF and no final newline. It compared per-line counts of beancount 3.2.3 (parse_string), mainbf195c80321and this branch over 3 seeds × 40,000 inputs:All 27 further or sideways inputs already mismatched on main. Each holds an indented lone posting flag (
!,\t?,Z) before the tag line. beancount reports that flag'sunexpected EOL, expecting ACCOUNTon the next line, and rledger reports it on the flag's own line. main's extra error on the tag line offset that by coincidence. The tag line now counts as a plain invalid-token line does in the same spot (!\n h\n, unchanged).Caches: WASM 125 → 126, since it archives parse errors. (The open WASM validation PR also takes 126; whichever merges second renumbers.) The loader stays at 75: every changed source has a parse error on the line before and after, and the pass only drops errors, so parsed directives do not move.
Timing: linear. 40k / 160k
#a ^l h xlines: main 0.12 / 0.43 s, branch 0.10 / 0.39 s. The extra scan of the rest of the line is added toERROR_LINE_SCANNED_BYTES, and the existing linearity test passes.Tests
crates/rustledger-parser/tests/indented_tag_line_invalid_token.rs. It pins the issue rows and controls, and more prefixes, indentations and line endings (#a ^l h,\t^l h,#a$,#a h #b,#a h ;c, CRLF, EOF). It also pins a tag line after a posting, two invalid tokens (#a h x→ 2), prefixes beancount fails on first (#a 1 h,#a 2024-01-03 h,#a Assets:B h→ 2), other directives (→ 2) and the narrowed lone-capital shapes (→ 2). Every count was checked against bean-check 3.2.3, and green and red agree on each.BOM_MATRIX_UPDATE=1 BOM_MATRIX_RELABEL=1. Six rows moved from known to matching (11,166 → 11,172), and two known rows are relabelled with the same counts.worse_than_main.tsv, theT#!row is no longer worse than main, so it is removed.open ... #t ^l\t<BOM>row's line now counts 1 alone, as beancount does, so its cause is the recovery causeindented-line-after-error, alone 1, replacinglike-main-without-bom.T#!as the token.cargo fmt --checkand clippy-D warnings --all-targets --all-features(parser, wasm) pass, as doescargo docwith-Dwarnings.cargo test -p rustledger-parser,-p rustledger-lspand-p rustledger-wasmall pass (1,700 tests, 0 failed).How to test
Not changed (documented)
\ror to the end of the input, after an invalid token on an indented line, is not reported as its own invalid token (h1 Z\r\n: bean-check 2, rledger 1). Tag lines holding it keep main's count.unexpected EOLis reported on the flag's line, where beancount reports it on the next line.Closes #2997
🤖 Generated with Claude Code