Repository navigation
fix(parser): a dated line that opens no directive is one error, as in beancount (#2979) - #2985
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]>
…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]>
… 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]>
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❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
#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]>
…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]>
…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]>
…ow (#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]>
…#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]>
…, 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]>
… 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]>
#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]>
…a_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]>
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 column-0 dated line whose second token opens no directive is now one error, as in bean-check 3.2.3. The second token can be a number, an account, a currency, an invalid date, and so on (
2024-01-02 123 * "n"). rledger also reported every indented line under it as an orphanunexpected input.opens and a blank line), then two postings2024-01-02 2024-01-03 * "n"2024-01-02 2024-01-03 "n"2024-01-02 123 * "n"2024-01-02 Assets:A * "n"2024-01-02 USD * "n"2024-01-02 2024-13-45 "n"Why and how
identify_directiveopens no node for such a line, so the indented lines after it were orphans, each reported. beancount reads the date, fails at the token after it, and bison's recovery reports no syntax error until it has shifted three tokens again.That is the recovery
quiet_after_line_start_bom_lines(#2984, for #2956) models after a line a mid-file BOM starts. This PR generalizes that pass rather than copying it, and renames itquiet_after_failed_line_starts. Its walk now also starts after a column-0ERROR_NODEline that starts with a valid date followed by a blank and a token: a dated line.A BOM line's window is untouched. From a line a BOM starts until #2984's window ends, every rule here is off, so behavior there is identical to the baseline. A line a BOM starts inside a dated line's window starts its own window there, under #2984's rules. Line-grammar controls with BOM lines (88,000 inputs over three seeds) are byte-identical to the baseline.
In a dated line's window:
The lines after the failed line. They keep only the lexer's errors (invalid tokens such as
k:, invalid dates, and a number beancount's lexer rejects,1,50,1,0,1,000,0, for which the line's error stands) until the recovery would report again (fix(parser): count a line-start BOM as beancount does, and keep the lines after it quiet #2984's token count).A failed dated line, or a date alone on its line or glued to anything but a flag (
2024/1/3:,2024-01-03,), inside the window. Its date is a token bison shifts. So when that date is the last token owed (after a skipped comment line), the line is reported and starts a window of its own. A date counts as alone with nothing after it but blanks or a comment, including a glued one (2024-01-02;c,2024-01-02%x).A declaration bison would shift ends the recovery. That is a dated header (a flag,
txn, a lone capital such asT, or a directive keyword after the date). The date may come after a blank or glued after punctuation beancount lexes as a token of its own (,:|~@{}()+-/). It may also be an undated declaration's keyword (option,include,plugin,pushtag,poptag,pushmeta,popmeta, also glued to punctuation as in~,option), found byfirst_resync_point. bison builds that declaration, which is not modeled:A line holding a lone capital glued to punctuation (
T",X(), which beancount reads as the start of an invalid run, is treated the same way: such a dated line starts no window, and such a line ends a window before it.This is why the issue's first row,
2024-01-02 2024-01-03 * "n", is not changed.Outside the window:
2024-01-02 2024-02-30: 1, was 2). This is applied in the pass, only to dated lines outside a BOM window, and not:!, anopenwith no account;T\r,Tat the end of the input) or to punctuation (T"), which beancount reads as an invalid token of its own;1,2024), for which the line's error stands.The walk lexes each line after a failed line at most once. There are no scans past a line.
What this does not touch: only error lists change. The CST and
identify_directiveare untouched, so every directive built is identical.Caches
CACHE_VERSION118 → 119. Both payloads archive parse errors. The note ends "(v118 was taken by fix(parser): count a line-start BOM as beancount does, and keep the lines after it quiet #2984.)".rledger check --format jsonwere identical on main and the branch for 3,000 sampled differential inputs (round 0; directives are unchanged since).Parser corpus baseline
One real-ledger output hash moves:
parser-lima/examples_data_full.beancount.2023-05-31 'Z "Z Energy ;" "Rather expensive" #petrol, is a dated line that opens no directive ('Zis 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.tests/baselines/parser-corpus.manifestwas updated for that line only. It was checked against the corpusscripts/fetch-compat-test-files.shfetches, as CI does; the parity manifest needs no update against it.Parity corpus (pinned fuzz 9bc79f4, BOM matrix, tracked, compat)
Against main, 3,087 inputs newly match and none stop matching. The manifest was updated with
--update, and--checkpasses.Generated differentials (baseline: main with #2984, 61225a7)
Line grammar. These are sequences of 2 to 7 lines:
Half have two
opens first, 15% are CRLF, 20% have no final newline, and 10% start with a file BOM. Controls use no F or L lines.Both generators now also cover:
",(,#, CRLF line ends and the end of the file;1,50,1,0,1,2024,1,000,0,1234,567);2024/1/3:,2024-01-03,,2024-01-03:x,2024-01-03*).The controls hold
2024-01-02 t "n", itself a failed dated line, so they change, always toward beancount. Their BOM windows stay identical to the baseline.Body generator (from earlier rounds). A failed dated line with 77 kinds of second token, a body of 0 to 4 lines (BOM lines and lone dates included), a tail and an optional line before; controls use a directive-opening second token.
"0 regressions" holds for these generators, as run here. Each review round has found shapes they lacked, so it is a measurement over these inputs, not a proof.
Families: every further and sideways input (5 in 900,000 inputs over six seeds, under 1 per 100,000)
2024-01-04 * "x"right below the failed line, or one line further)T") followed by quote linesT"as an invalid token, while rledger's lexer opens a string there, so later quotes pair differently (pre-existing lexer difference).Assets:"10) that closes on the next line, followed there by an invalid token2024-01-01 ,\n Assets:"10\n k: "-5"\nis bean-check [1,2,3], main [1,2,3], this PR [1,3]: the quiet window silences line 2. Each is off by one on that one line; it does not happen withAssets:A "10or after a valid header.The round-7 review measured its generator at about 9,000 gains per 100,000 inputs, with I-type leftovers its only remainder after these fixes.
None drops a directive. The round-5 review's two token-accounting shapes now match bean-check:
2024-01-02 2024-13-45 ( 1,0002024 'x(bean-check 3, main 3, PR 3) holds a mis-grouped number, which the invalid-second-date rule now leaves alone;2024-01-02 x 2023-02-29 @@2024-01-02 ?/@@ $x pad 2024 commoditygives bean-check's {1:2, 2:2} too.The round-7 reviewer's shapes (rebuilt as probes)
opens, blank line,2024-01-02 123 * "n"/Assets:A 1,50 EUR2024-1-2 y/1,02024-1-3 2024-0-0 1,20242024-1-3 c/ blank line /2024/1/3:(also2024-01-03,)2024-01-02 Assets:A * "n"/; note/2024-01-03:x2024-01-02 @2024-01-03 */#x(also{ } ( ) + - /)2024-01-02 123/X( 1/Assets:A 1 USDX()The round-6 reviewer's shapes (rebuilt as probes)
2024-01-01 open Assets:Aand a blank line where it applies)2024-01-02 ,2024-01-03 */#x(also:...txnthenUSD, `,2024-01-03:2024-01-04 *,~`, CRLF)2024-01-02 2024-13-45 T" 1 USD/; c/Assets:A 1 USD/2024-01-02 t "n"2024-01-02 2024-13-45 T"/"(alsoP"a/b")The round-5 reviewer's shapes (rebuilt as probes)
2024-01-01 open Assets:Aand a blank line where it applies)2024-01-02 2024-01-03 T/#x(alsoP,T "n",T ; c)2024-01-02 2024-01-03 T/;c/Assets:A 1 USD2024-01-02 2024-13-45 T(CRLF, or at the end of the input)2024-01-02 2024-13-45 : 2024-00-10 T(CRLF or EOF)2023-12-31 2024-13-45 USD T(CRLF, after abalance)2024-01-02 2024-01-03 Tthen postingsThe round-4 reviewer's shapes (rebuilt as probes)
; a/<BOM>x/ blank line /2024-01-02 2024-13-45 include "x"(also;cfor the blank,popmeta k:); a/<BOM>x/;c/2024-01-02 $x pushmeta k: 1/;c/#comment; a/<BOM>x/;c/2024-01-02 'x/2024-01-02/~,option "a" "b"2024-01-02 'x/2024-01-02/~,option "a" "b"2024-01-02 123/;c/2024-01-02;c(also%x)2024-01-02/2024-01-02 2024-13-45(also2024-01-02 ; c)The reviewer's shapes from rounds 1 to 3 also give main's count, or beancount's where main differed.
Speed
Linear on adversarial inputs at 20k/40k/80k repetitions, in seconds (main's numbers from round 2):
2024-01-02 2024-01-03 * "n\"~,optionlinesNot changed (documented)
2024-01-02 2024-01-03 * "n"and postings: bean-check L4, main and PR L4 L5 L6). beancount builds that declaration, and modeling it is Parse-error recovery differences from bean-check around invalid dates and column-0 markers #2872's general recovery.holds_a_misgrouped_numberis slightly stricter than beancount on two lexer corner cases that changed no count in a 163,000-input check: beancount accepts one leading digit, a double comma, then three digits (1,,000lexes as 1000), which the predicate calls misgrouped; and the predicate lexes past a stray\rinside a;comment, where beancount's comment runs to\n.2024-01-02then postings is bean-check L5, main and PR L4 L5 L6.openwith no account, a flag-only posting, a lone date) before a dated line: counts as main.2024-01-02 pushtag #athenpoptag #a: beancount pushes the tag, which the whole parse does not see. Main is the same.How to test
Every expected count in
dated_line_no_directive.rswas checked against bean-check 3.2.3.#2984 is merged (de17d7d), and main is merged in, so this diff holds only #2985's changes.
Fixes most of #2979 (all rows but the first; see "Not changed").
🤖 Generated with Claude Code