Repository navigation
fix(parser): count a line-start BOM as beancount does, and keep the lines after it quiet - #2984
Merged
Merged
Conversation
…ines after it quiet (#2956) A mid-file BOM at the start of a line is beancount's invalid token, so the statement it starts or breaks into fails there and bison's recovery reports nothing more until it has shifted three tokens. Each indented line after it was an orphan `unexpected input` here, and a transaction the line broke into was kept with a balance residual beancount never reports. - quiet_after_line_start_bom_lines: the lines after a line a BOM starts keep only the lexer's errors until a column-0 directive, two blank or skipped lines, or a dated header ends the quiet. - The lexer: a line-start BOM glued to a comment start, a line start beancount skips, or a run holding a quote or `;` is one invalid token with it, so the rest of the line is read; one before a `:` account takes in that account. - transaction_holds_invalid_token also answers for a transaction a BOM line breaks into, so the validator reports no residual for it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…, parity manifest and BOM matrix data regenerated Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report❌ Patch coverage is
📢 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?
|
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
…t does A line a mid-file BOM starts after a transaction discards the transaction in beancount only when the BOMs are its invalid token. Where its lexer reads them into an account (<BOM>Assets:A, <BOM>assets:A, a run of BOMs before one), its grammar reduces the transaction first and fails at the account, so the transaction is kept and its residual reported. The new branch of transaction_holds_invalid_token now asks bom_led_account for that. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 15, 2026
#2979 review) Round-1 review of #2985: - A declaration bison's recovery shifts after a blank on the failed line or on a quiet line (a dated header, or `option` / `include` / `plugin` / `pushtag` / `poptag` / `pushmeta` / `popmeta`) ends the recovery there: it and its block take the errors a parse of them gives, its own line's grammar errors only from its fourth token (counted again after a lexer error), as bison is still recovering until then. - That block's end follows a string that runs over line ends; a quote that never closes opens no string. - The pushtag/pushmeta state stays the whole file's. - A date with nothing after it but blanks or a comment starts no window (beancount reports it on the next line, not modeled). BOM matrix: one known row moves closer; 7 rows relabelled (same counts). Parity corpus 79,558 -> 82,649 against the #2984 head, none lost. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 15, 2026
…hout modeling it (#2979 review) Round-2 review of #2985: drop the separate parse of a resynchronized declaration and the fourth-token rule. Where bison's recovery would shift a declaration (a dated header after a blank, or an undated declaration's keyword, also glued to punctuation), a dated line starts no quiet window and a line ends one before it, keeping the errors main gives there. The invalid-second-date rule applies only to a line with no such declaration. BOM windows are as #2984 has them again (matrix data restored). Linear: no scans past a line (the escaped-quote shape was quadratic). Generated differential: 3 seeds x 150k, no regressions; the one family left is an `open` with no account on the line before (pre-existing). Parity corpus 79,558 -> 82,649, none lost. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 15, 2026
#2984 landed as de17d7d (same tree as its head 61225a7, which this branch was built on); conflicts resolved to this branch's side; the WASM cache note now says v118 was taken by #2984. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 15, 2026
… beancount (#2979) (#2985) * fix(parser): count a line-start BOM as beancount does, and keep the lines after it quiet (#2956) A mid-file BOM at the start of a line is beancount's invalid token, so the statement it starts or breaks into fails there and bison's recovery reports nothing more until it has shifted three tokens. Each indented line after it was an orphan `unexpected input` here, and a transaction the line broke into was kept with a balance residual beancount never reports. - quiet_after_line_start_bom_lines: the lines after a line a BOM starts keep only the lexer's errors until a column-0 directive, two blank or skipped lines, or a dated header ends the quiet. - The lexer: a line-start BOM glued to a comment start, a line start beancount skips, or a run holding a quote or `;` is one invalid token with it, so the rest of the line is read; one before a `:` account takes in that account. - transaction_holds_invalid_token also answers for a transaction a BOM line breaks into, so the validator reports no residual for it. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(parser): keep a transaction before a BOM-led account, as beancount does A line a mid-file BOM starts after a transaction discards the transaction in beancount only when the BOMs are its invalid token. Where its lexer reads them into an account (<BOM>Assets:A, <BOM>assets:A, a run of BOMs before one), its grammar reduces the transaction first and fails at the account, so the transaction is kept and its residual reported. The new branch of transaction_holds_invalid_token now asks bom_led_account for that. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(parser): a dated line that opens no directive is one error, as in beancount (#2979) When the token after a column-0 line's date is no directive keyword and no transaction flag (`2024-01-02 123 * "n"`, a second date, an account, a currency), each indented line under it was an orphan error too. beancount reads the date, fails at the next token, and stays quiet until its grammar has read three tokens again. Generalize the BOM-line recovery pass (now `quiet_after_failed_line_starts`) to start after such a dated line too. When the line holds a transaction's header after a blank, beancount builds that transaction, so its body takes the errors a parse of that transaction gives. A failed dated line in a quiet window is reported when its date is the last token owed. An invalid date right after the line's date is the line's one error. WASM cache v119; loader cache unchanged (every changed source has a parse error before and after; directives do not move). Parity corpus 79,558 -> 82,650 matching, none lost; manifest updated. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(parser): end the quiet at a declaration bison shifts, and parse it (#2979 review) Round-1 review of #2985: - A declaration bison's recovery shifts after a blank on the failed line or on a quiet line (a dated header, or `option` / `include` / `plugin` / `pushtag` / `poptag` / `pushmeta` / `popmeta`) ends the recovery there: it and its block take the errors a parse of them gives, its own line's grammar errors only from its fourth token (counted again after a lexer error), as bison is still recovering until then. - That block's end follows a string that runs over line ends; a quote that never closes opens no string. - The pushtag/pushmeta state stays the whole file's. - A date with nothing after it but blanks or a comment starts no window (beancount reports it on the next line, not modeled). BOM matrix: one known row moves closer; 7 rows relabelled (same counts). Parity corpus 79,558 -> 82,649 against the #2984 head, none lost. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(parser): end the quiet where bison would shift a declaration, without modeling it (#2979 review) Round-2 review of #2985: drop the separate parse of a resynchronized declaration and the fourth-token rule. Where bison's recovery would shift a declaration (a dated header after a blank, or an undated declaration's keyword, also glued to punctuation), a dated line starts no quiet window and a line ends one before it, keeping the errors main gives there. The invalid-second-date rule applies only to a line with no such declaration. BOM windows are as #2984 has them again (matrix data restored). Linear: no scans past a line (the escaped-quote shape was quadratic). Generated differential: 3 seeds x 150k, no regressions; the one family left is an `open` with no account on the line before (pre-existing). Parity corpus 79,558 -> 82,649, none lost. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(parser): hand a dated window over to a BOM line, and end it at a lone date (#2979 review) Round-3 review of #2985: - A line a BOM starts inside a dated line's window starts its own window there under #2956's rules; the dated walk no longer runs over it. - A date alone on its line where the window owes its last token ends a dated line's window (the line keeps its error), as one with a token after the date does; in a BOM window only the latter, as before. Generated differential (now with BOM lines under a failed dated line and lone dates): 5 seeds x 150k, no regressions. Corpus unchanged (82,649). Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(parser): leave BOM windows as they are, and refine the dated window (#2979 review) Round-4 review of #2985: - Inside a BOM line's window none of the new rules apply (the lone-date and dated-line breaks, the resync break); its behavior is the baseline's. - The invalid-second-date rule moves into the quiet pass: only for a dated line walked there (so never inside a BOM window), and not after a line with an error of its own, which beancount may report on the dated line. - A declaration on an indented line in a dated window is quiet and ends the window after it; only a column-0 one ends it before the line. - A date with a comment glued to it (`2024-01-02;c`, `%x`) is a lone date. Line-grammar differential (3 seeds x 150k): no regressions, no further or sideways, controls unchanged. Body generator (3 x 150k): no regressions, 30 documented further/sideways. Corpus unchanged (82,649). Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(parser): a lone capital is a transaction flag after a second date (#2979 review) Round-5 review of #2985: - `first_dated_header` takes a lone capital (`T`, `P`, `X`, lexed as a currency) after a date as a transaction's flag, as beancount shifts it, after a dated line only (a BOM line's window keeps #2956's reading). - The invalid-second-date rule does not apply when a lone capital glued to the line's end (`T\r`, `T` at EOF) is an invalid token of its own. Both generators now cover lone capitals: 6 seeds x 150k, no regressions; line grammar has no further or sideways. Corpus unchanged (82,649). Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(parser): a date after punctuation, and a capital glued to a quote, end the model (#2979 review) Round-6 review of #2985: - After a dated line, `first_dated_header` takes a date glued after punctuation beancount lexes as its own token (`,` `:` `|` `~` `@` `{` `}` `(` `)` `+` `-` `/`) as after a blank (a BOM window keeps #2956's reading). - A lone capital glued to punctuation (`T"`, `X(`) is the start of an invalid run to beancount: a dated line holding one starts no window, a line holding one ends a dated window before it, and the invalid-second-date rule does not apply to it. Generators now cover both: 6 seeds x 150k, no regressions, 16 documented further/sideways. Corpus 79,558 -> 82,645, none lost. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(parser): a badly grouped number is beancount's lexer error, and a glued date is shifted (#2979 review) Round-7 review of #2985: - `holds_a_misgrouped_number`: a digits-and-commas run whose commas are not thousands groups (`1,50`, `1,0`, `1,000,0`) is beancount's lexer error. On a quiet line after a dated line its line error stands for it and is kept; the invalid-second-date rule leaves such a line alone. - A column-0 date glued to anything but a flag (`2024/1/3:`, `2024-01-03,`) counts as a dated line for the owed-1 break (it still opens no window). - Tests for the `open`-without-account exception, the other glued punctuation (`@ { } ( ) + - /`) and a later ` X(` line ending a window. Generators now cover both: 6 seeds x 150k, no regressions, 5 family-I inputs. Corpus unchanged (82,645). Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(parser): update the corpus baseline for parser-lima examples_data_full (#2979) The file's parser output moved toward bean-check 3.2.3. Line 107, `2023-05-31 'Z "Z Energy ;" "Rather expensive" #petrol`, is a dated line that opens no directive (`'Z` is an invalid token), so the posting lines under it are quiet: line 108 keeps its lexer error (`'B`), and line 109, ` ! Expenses:Car:Fuel`, is no longer reported. bean-check reports lines 107 and 108 there; main also reported 109. The file had parse errors before and after (13 lines on both sides), the pass only filters errors, and directives do not change, so no cache moves. Only this file's output hash changes (source hash unchanged), checked against the corpus fetched by scripts/fetch-compat-test-files.sh as in CI; the parse-error parity manifest needs no update against that corpus. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This was referenced Nov 15, 2026
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 UTF-8 BOM (U+FEFF) at the start of a line other than the file's first is now counted as beancount 3.2.3 counts it, and so are the lines after it.
The lines after a line a BOM starts are quiet. beancount's lexer reads a line-start BOM as the start of an invalid token, so the statement it starts or breaks into fails right there, and bison's recovery reports no syntax error until it has shifted three tokens again. Here the BOM line ended its block, so each indented line after it was an orphan
unexpected input. A new post-pass,quiet_after_line_start_bom_lines(cst/convert.rs, run on the shared error path afterquiet_after_invalid_tokens), models that recovery line by line:beancount_ignores_line) is one more; two of them end the quiet;5,$x, another BOM line), fails again and starts the count over;holds_a_dated_header), which bison shifts in the middle of the line.On a quiet line only grammar errors go (syntax errors, construct checks, and the account-name and booking-method checks beancount makes only of an entry it builds). Kept: each invalid token's own error, the line error when it stands for the line's first invalid token (after a start beancount reads), the BOM diagnostic when it stands for a token with a BOM inside it, the line error when the line holds a lone capital glued to the next character (
T#!,A\ron a CRLF line,Aat the end of the input), which beancount reads as an invalid token and the lexer here as a currency, an invalid date, and the end-of-file pushtag/pushmeta state.A transaction a BOM line breaks into has no balance residual. beancount discards that statement whole. rledger keeps the postings above the line, so it reported
E3001.transaction_holds_invalid_token(the canonical the validator asks, Recovery drops a posting's price or cost after an invalid token, then reports a spurious imbalance #2954) now also answers true when the node right after the transaction, with no blank or comment line between, starts with a line-start BOM; a directive's span runs to the next directive, so the validator's text holds that line. Not when the BOMs start an account in beancount (<BOM>Assets:A,<BOM>assets:A,<BOM><BOM>Assets:A,<BOM>:A, asbom_led_accountreads them): there its grammar reduces the transaction first and fails at the account, so the transaction is kept with its residual, as on main. After a blank or comment line the transaction is complete in beancount too and keeps its residual. The one-posting warningE3004still shows for such a transaction, as it does for one holding a mid-line invalid token.A line-start BOM glued to a comment start is one invalid token with it. The lexer kept a line-start BOM as its own token (layout transparency, compat(parser): an invalid run should swallow a following quote, #! or #+ mid-line, as beancount's lexer does #2928), so
<BOM>; c xlexed as a BOM and a comment: one error, where bean-check reports'<BOM>;','c'and'x'. The run of BOMs that starts a line now takes in the rest of its blank-free run when that run starts with a line start beancount skips (;,%,#,!,&,?,:) or holds a"or;, so the rest of the line is lexed and a quote no longer opens a string that hid the directives after it (<BOM>~"x). Where the BOMs start an account in beancount and that account starts with:(<BOM>:A), the token takes in the account, so:Ais no skipped line. Decided once at the run's first BOM; linear (the BOM-run linearity guard passes).The
P0026and its LSP "Remove BOM" quick fix are unchanged; a new LSP test pins the quick fix on<BOM>; c xand<BOM><BOM>:A c(each edit deletes exactly one BOM).Why
Closes #2956. Issue rows, line 3 onward after two
openlines:<BOM>2024-01-02 * "x"+ 2 postings2024-01-02 * "x"/<BOM> Assets:A 1 USD/Assets:B -1 USD<BOM> key: "v"/ postingE3001<BOM>; c x/ postingE3001<BOM>; c x(and%,!,:,&,?,#,#!,#+)Measurements
All against main
7eb5a5372bd(after #2983) and bean-check 3.2.3, per-line parse-error counts.Parse-error parity corpus (111,323 inputs): 79,549 -> 79,558 matching. 9 inputs newly match, 0 that matched stop matching, and all 140 other inputs whose counts changed moved closer to bean-check (none further). Manifest updated with
--update(9 stale pins removed, 4 re-categorized).BOM combination matrix (13,438 inputs, updated through its own
BOM_MATRIX_UPDATE=1 BOM_MATRIX_RELABEL=1): matching 7,607 -> 11,004 (+3,397, none lost); known list 5,828 -> 2,432; worse-than-main 674 -> 536 (138 entries now no longer worse, removed; none added); exceptions 11 -> 7 (4 now explained or matching). 10 rows keep their counts but now name the tokens beancount names (<BOM>;c,<BOM>%,<BOM>!,<BOM>#!d), hence the relabel. Theline-start-bom-before-commentcause stays for 3 rows the lexer still reads apart (<BOM>*heading rest,<BOM>*<BOM>/<BOM>#<BOM>after a brokenopen); its tests now pin it on made-up counts and assert the old real rows count as bean-check.hash_bang_cut(the test's model of pre-#2928 main) keeps a#!line after leading BOMs whole, as main read it.Generated differential (own generator: random ledgers of transactions, opens with metadata, single-line directives, comments, headings, junk lines; line-start BOM runs of 1-3 BOMs inserted at random lines, alone or before
; % # ! & ? : " *, quotes, accounts, dates, words; CRLF, no final newline, leading file BOM; 3 seeds):No crashes. All 152 regressed or further inputs fall in three documented families; none adds an error on another line or drops a directive bean-check keeps:
5,$x, a failed metadata linek: 1, an orphan indented line). Example after the two opens:5/<BOM>:A"/; c: bean-check {3:1, 4:1}, main {3:1, 4:1}, PR {3:1, 4:2}. bean-check's recovery after5keeps the account's grammar error quiet; that recovery is Parse-error recovery differences from bean-check around invalid dates and column-0 markers #2872 and not modeled here. The PR counts exactly what main counts for the same line with a plain account (5/Assets:A"), pinned bytest_parse_bom_account_after_another_unreadable_line_counts_as_a_plain_account. Main matched only because it lexed:A"as a skipped line hiding the rest.2024-01-02 closealone): rledger reports it on its own line, bean-check on the next (it reads the line ending as the missing token), as on main without any BOM. Main matched only where a quote glued to an earlier line-start BOM (<BOM>"x) opened a multi-line string that swallowed that line; the quote now opens no string, as in bean-check.<BOM>:A"), the line where it closes fails, and the lines after that line are not kept quiet (the same non-BOM recovery, Parse-error recovery differences from bean-check around invalid dates and column-0 markers #2872).Validation (
rledger check, full output vsbean-check): a transaction a BOM line breaks into no longer reportsE3001; after a blank or comment line, or before a BOM-led account, it keeps it, as in bean-check. A full-check differential of 918 ledgers (three unbalanced transaction shapes; directly after, after a blank line or after a comment; 17 BOM-line shapes including the account ones; then nothing, a posting or a directive; LF and CRLF) agrees with bean-check on whether each residual is reported in 918 of 918 (main 738). Pinned by two surface-agreement cases (every surface) and the account shapes intest_transaction_holds_invalid_token_counts_a_bom_line_after_it.E3004(rledger's one-posting warning) still shows for such a transaction, as for one holding a mid-line invalid token (#2954).Caches: WASM
CACHE_VERSION117 -> 118 ((v117 was taken by #2983.)): parse errors and, after a quote that no longer opens a string, directives change. Loader stays 75: every changed source holds a mid-file BOM and so a parse error before and after, and the loader caches only error-free loads.Tests run: parser (all), validate, loader, LSP, wasm
cache; clippy-D warningson parser, validate, loader, LSP, wasm (all targets, all features);cargo fmt --all -- --check;RUSTDOCFLAGS=-Dwarnings cargo docon parser, validate, LSP, wasm. Local-only failures, identical on main: loaderdiscover::tests::{a_non_utf8_file_is_not_a_candidate, skips_files_that_declare_no_include}and LSPan_unrelated_root_is_probed_once_not_once_per_file(they walk up into a stray file in/tmp).How to test
Every expected count in
tests/line_start_bom_recovery.rs(54 inputs with their CRLF and tab variants) and the surface-agreement case was checked against bean-check 3.2.3.Closes #2956
🤖 Generated with Claude Code