Repository navigation
fix(parser): start bison's recovery at a BOM beancount reads as an invalid token, and model four more recovery shapes - #3036
Merged
Merged
Conversation
…valid token, and model four more recovery shapes #3035's differential left eight inputs that moved away from bean-check 3.2.3, each holding a BOM or a `\r`. The port of beancount's lexer in `cst/recovery.rs` was not the cause: it agrees with `lexer.l` token for token on about 190,000 BOM- and `\r`-heavy inputs. The causes, and what fixing them led to: - A mid-file BOM's diagnostic never started bison's recovery. It now does where beancount's lexer reads that BOM into an invalid token (not an account, a string or a comment, nor on a stray-`\r` line), checked with a forward-only probe lexer. - An entry bison builds mid-line whose own line holds an invalid token is dropped at that token's YYerror: its line counts as that line parsed on its own, and the window goes on from the line's end, so its indented lines are quiet. A BOM inside such an entry no longer leaves it unmodeled. - A misgrouped number (`1,50`) inside the window is reported as `InvalidNumber`, as beancount's lexer reports it, where rledger had no error of its own; a lone BOM token no longer blocks that addition. - A header failing at a token after a multi-line string is reported on that token's line (`report_at_multi_line_string_ends`). Also documents and pins rledger's deliberate acceptance of an indented comment after a column-0 comment, a blank line or the top of the file, and the parse-error parity harness drops beancount's `unexpected INDENT` there. Parity corpus: 106,447 -> 107,279 matching, 0 regressions. BOM matrix: 11,854 -> 12,762. WASM cache 133. 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 |
This was referenced Nov 26, 2026
robcohen
added a commit
that referenced
this pull request
Nov 27, 2026
… four more BOM and pipe line shapes (#3052) A stray `\r` is a blank to beancount's lexer; rledger reports one before a token that lexes as an error of its own (deliberate, #2980) and started no model of bison's recovery from such a line, so the lines bison keeps quiet after a statement failing there kept their errors. The input is now parsed once more as beancount reads it (`recovery::stray_cr_analog`), and from the first line holding a stray `\r` on, each line takes that parse's errors, except a line where rledger reports the `\r` itself, which keeps its own. Also: a line's BOM diagnostic stands for a first invalid token with no BOM; a misgrouped number beside a BOM-led token or a BOM inside an account is reported in the recovery; a pipe after a header failure gives no warning; an invalid booking method is reported on its `open`'s line. Generated differential (1.26M inputs, #3035/#3036 generators): 24,188 gained, 25,725 closer, 237 moved away (168 reproduce on the \r-free analog, 66 are the booking line where beancount drops the open). Parity corpus 107,647 -> 108,454, no regressions; BOM matrix 12,853 -> 12,917. WASM cache 142. 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
#3035's differential left 8 inputs that moved away from bean-check 3.2.3: 2 further and 6 sideways, all on lines with a BOM or a
\r. This PR finds their causes and fixes them. It also documents one deliberate deviation the maintainer asked for: rledger accepts an indented comment after a column-0 comment.Cause
Not the lexer port. I checked
BcLexertoken by token against beancount's own lexer (lexer.lex_iter_string). About 190,000 generated BOM- and\r-heavy inputs gave 0 differences.The 8 cases come from four gaps in the recovery driver:
starts_recoveryexcluded everyBomInDirectiveBody(P0026).\t<BOM>or<BOM>g, the lines bison discards kept their errors.\t<BOM>/\tT 2024-01-02 commodity EUR "a b"gave 2 errors on line 2.\t$gives 1.\r.bom_is_invalid_token) decides this.$ 2024-01-02 * "y" $or<BOM>g 2024-01-02 * "n" $x, each followed by postings.YYerrordrops the entry and starts the recovery over.phantom_errors). The window then continues from the end of the line, so the postings are quiet.1,50) inside a window had no error.ValueError: Invalid number formatthere. rledger reads it as a number and a comma.ParseErrorKind::InvalidNumber(P0005; the kind existed but was never emitted).2024/1/3 event "x\nb" xis line 2 in beancount, line 1 in rledger.grammar_failures).report_at_multi_line_string_endsonly moved it when the string itself was the failing token. It now also covers a failure past the string.Also:
invalid token '"x').rledger'seg_start,line_from lone capital) are restored.Deliberate deviation: indented comment after a column-0 comment
The input
; notefollowed by; continued(also after a blank line, a* heading, or at the top of the file):syntax error, unexpected INDENT;Per the Python Compatibility Policy:
cst/parser.rs, the top-level trivia loop);test_parse_indented_comment_after_a_column_0_comment_is_accepted;is_indented_comment_indent_error), documented with its other normalizations and covered by the self-test.Scope of the harness rule: it is context-aware. After a directive that takes no metadata (
option,include,pushtag, ...), both sides report the line, so it stays an error.The BOM matrix generator deliberately does not apply this drop. Applying it would mean regenerating the whole table, including its main columns. Its docstring says so.
Results (bean-check 3.2.3 from nixpkgs)
The 8 #3035 cases:
INDENTerror plus the lexer's, and rledger reports one. That is the general shape ($xalone is 2 vs 1).Parse-error parity corpus (pinned fuzz
9bc79f4f, matrix, tracked, compat):0 regressions. The manifest is rewritten with
--update.BOM combination matrix: 11,854 → 12,762 rows match.
customrow now give thebom-glued-to-accountreason (compat(parser): an invalid run should swallow a following quote, #! or #+ mid-line, as beancount's lexer does #2928's deliberate P0026 on a BOM-led account, inside the entry bison builds).BOM_MATRIX_UPDATE=1 BOM_MATRIX_RELABEL=1.Generated differential, branch vs main. The first three rows reuse #3035's own input files.
\rWhat still moves away (31 inputs of 1.26M):
$analog (BOM replaced by$, same count on main and branch): all 3 G2 regressions and 23 of the 31 overall. Main matched the BOM version only because a BOM never started a window.<BOM> 2024-01-02 * "a" "b" "c"/x), as with$.Timing. Every new path is linear. The scanned-bytes unit test gains 5 shapes. Wall clock, 20k vs 80k repetitions:
How to test
Run locally:
-D warnings, whole workspace;STRICT_BASELINE=1corpus and CST baselines (unchanged).WASM
CACHE_VERSION132 → 133, since parse errors move.🤖 Generated with Claude Code