Repository navigation
fix(parser): keep the lines after a column-0 line beancount cannot read as quiet as beancount does - #3000
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?
|
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
…ad as quiet as beancount does After a column-0 line whose statement fails (a first token beancount's lexer rejects, a marker alone on its line, an undated declaration holding such a token), bean-check 3.2.3 reports only the lexer's own errors until its grammar has shifted three tokens again. quiet_after_failed_line_starts now models that window for these lines with the dated line's rules, and quiets a line only where beancount's recovery surely discards it: a line holding a date or an undated keyword (which bison shifts in its recovery, per its one error rule declarations: declarations error), a line holding a BOM, and a line right after another failed line keep their errors. Part of #2993 (part A: column-0 unreadable lines). Co-Authored-By: Claude Opus 5.5 <[email protected]>
beancount reads a stray CR then a comment as a blank line; this parser reports an error there. That line no longer starts an unreadable-line window, counts as a blank line inside one, and is looked past when deciding whether a line follows another failed line. A date glued to the first token of an unreadable line now counts as one bison shifts. Tests for each reported shape; parity manifest updated. Part of #2993. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A line holding a stray CR (one not right before a newline, anywhere on the line) is read here differently from beancount by context. Such a line now starts no unreadable-line window, ends one before it, and counts as a failed line in the look-back, so every line around it keeps its errors as on main. This replaces the line-start-only handling of the previous commit, which missed the mid-line forms (option \r;c, poptag\t\r#c, 2024-01-02\r;c). Tests for each reported shape; parity manifest updated. Part of #2993. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- LSP surface_cleanup test: open / # / @@@ junk is now 2 errors, as bean-check 3.2.3 reports (the marker line and the invalid token). - Doc comments: a string unclosed to the end of the input is cut at its line and does start a window, matching beancount; pin it with a test. - unreadable_lines: skip nodes not at a line start before scanning for the line end. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
force-pushed
the
fix/quiet-after-unreadable-col0
branch
from
November 25, 2026 04:19
3d8009c to
c165a0b
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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
After a column-0 line whose statement fails, bean-check 3.2.3 reports only the lexer's own errors on the lines after it until its grammar has shifted three tokens again. rledger reported each of those lines. This models that window after three more kinds of column-0 line:
$,$x,2<BOM>?02,'Z);!,*,:,#);pushmeta k: "v").This is part A of #2993: column-0 unreadable lines. Part B, an indented line after a failed header with a blank or comment line between and the
optionrows, is not changed here, so #2993 stays open.Why it works, and where it stops
beancount's grammar has one error rule,
declarations: declarations error(grammar.y). During recovery bison discards every token except one adeclarationscan take next: an end of line, aDATE, or an undated declaration's keyword (option,include,plugin,pushtag,poptag,pushmeta,popmeta). It reports no syntax error until it has shifted three tokens. So an indented posting, or another unreadable line, is discarded to its end. Its lexer errors are still reported, because beancount's lexer reports those itself.quiet_after_failed_line_starts(crates/rustledger-parser/src/cst/convert.rs) already models this window after a line a BOM starts (#2956) and after a dated line that opens no directive (#2979). The new lines walk with the dated line's rules, the ones calibrated over #2985's review rounds. Where a correct model would need bison's exact token accounting, the window stops and keeps main's errors:\t1poptag #t,key:2024/01/03 P | 1, and the unreadable line itself past its first word): bison shifts these and may end its recovery inside the line, and then builds or reports what follows. The check is a byte scan for the date shape and the keyword substrings. That over-detects (inside strings and invalid runs), which only makes more lines keep their errors.\r(one not right before a\n, anywhere on the line, or at the end of the input): this parser reads it differently from beancount depending on context (\r;cis an error here and a blank line there; fix(parser): read a stray \r before an invalid token as a blank, as beancount does #2980). Such a line starts no window, ends one before it, and counts as a failed line when deciding whether the next line starts one, so the lines around it keep main's errors. Two review rounds found stray-\rshapes the window got wrong (19, then 109 of over a million inputs), so this blanket exclusion replaces shape-by-shape handling and gives up those gains. A plain CRLF line ending is no stray\r. The unreadable line's own date check skips only its first character, so a date glued to it (@2024-1-2) counts as one bison shifts.;comment line inside an unreadable window counts as a line with tokens, as on main: the round-1blank_or_comment_linehelper that looked past it was removed with the blanket stray-\rrule. Against the intermediate head f407d26 this moved 38 of 50,000 no-\rcontrol inputs (27 closer to bean-check, 11 back to main's count, e.g.x/;pushmeta/~: bean-check {1}, main {1,3}, this PR {1,3}); against main nothing is worse. Looking past such lines again is left for part B of compat(parser): stay quiet after any line beancount cannot read, until its grammar has read three tokens #2993.Results
Issue rows in scope: all match bean-check 3.2.3:
!\n!\n,*\n:\n,#\n#\n,!\n!\n!\n,!\n!\n<directive>);$\n2<BOM>?02, with and without a final newline,1-2-3#x\n2<BOM>?02);pushmeta k: "v"then2<BOM>024-01-02 close Assets:Aor2$024-01-02 close Assets:A).Parse-error parity corpus (pinned fuzz
9bc79f4f, matrix, tracked, compat): 82,846 → 92,500 inputs match, with 0 regressions against main's committed manifest. 10,055 pins are stale: 9,654 inputs now match, and 402 others changed category, so their pins are rewritten. The fourledger2beancountrows that local fetching flags as unpinned upstream drift are left out, as in #2988 and #2990.Generated differentials: three designs, three seeds each, comparing per-line counts of bean-check 3.2.3 (the harness's
run_beancount), main91f2b8c6273and this branch.\rs at line start and mid-line (\r;c,option \r;c,poptag\t\r#c,2024-01-02\r;c,x \r;c); CRLF, no final newline, file BOMlexer.lclasses, glued, blank-separated or separated by stray\rs (\r,\r,\r\t,\r;c)examples/, parser test data) and the fuzz corpus, with unreadable and stray-\rlines insertedG1's changed controls hold a file-start BOM before a BOM line, which leaves an unreadable
$line. G3's hold the unreadable lines already in the fuzz-corpus files. Neither is a true control change.Caches: WASM 123 → 124, since it archives parse errors. The loader stays at 75: every changed source has a parse error on its trigger line before and after, and the pass only drops errors, so parsed directives do not move.
Timing: linear. Seconds at 20k / 40k / 80k / 160k repetitions, main then branch:
$lines!lines$and a postingpushmeta k:lines$ $ $line$then postings2<BOM>?02lines$thenx 1poptag$ xand a blank lineA new counter,
RECOVERY_SHIFT_SCANNED_BYTES, guards it:test_parse_unreadable_line_windows_scan_linear_bytesrequires at most four times the input over seven shapes. The answer to whether an invalid token is a BOM-led account is now cached per token, so a long BOM run is asked about once. That keepstest_tokenize_long_bom_runs_are_linearwithin its bound.Tests
crates/rustledger-parser/tests/unreadable_line_recovery.rs. It pins the issue rows, the postings and metadata under an unreadable line (LF and CRLF), the window's end at blank, skipped and directive lines, and every unmodeled shape above at main's count. All counts were checked against bean-check 3.2.3.indented_star_line.rs:@@ junk/* heading/* indnow gives line 4 one error, as bean-check does.line_start_bom_recovery.rs: the plain-account line after5now gives one error, as bean-check does. The BOM-led account line keeps its count, since the window hands over at a BOM line.BOM_MATRIX_UPDATE=1 BOM_MATRIX_RELABEL=1. Two rows moved from the known list to matching (11,164 → 11,166). One listed exception is now explained by the existinginner-bom-under-line-errorrule, so it is relabelled with the same counts and removed from the exceptions file.-D warnings(parser, wasm) andcargo doc -Dwarningspass. All parser tests pass (1,108, includingcorpus_baselineagainst the fetched compat corpus), as do the wasm cache tests. The loader suite shows only the two known localdiscoverfailures (a stray/tmp/rec_before.beancount).How to test
Not changed (documented)
pushtag #a $/ blank /2024-02-30 5: bean-check {2, 4}, main and branch {2, 4x2}), the unterminated-string and comment-line rows, and theoptionrows.AB-C/key:2024/01/03 P | 1: bean-check reports the pipe too;$ 2024-01-02 * "y"with a posting;$/Assets:A 1 USD 2024-01-02;$/2024-01-02 123/ posting.Part of #2993
🤖 Generated with Claude Code