Repository navigation
fix(parser): an invalid account starts bison's recovery, and three more recovery shapes count as bean-check does - #3043
Merged
Conversation
robcohen
force-pushed
the
fix/recovery-invalid-account
branch
from
November 26, 2026 06:49
51d39f3 to
a4c1ff4
Compare
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 |
…re recovery shapes count as bean-check does The shapes #3040 left in cst/recovery.rs's model of bison's error recovery. - An invalid account (P0006, rledger's line error for an unreadable line that holds an account like `Assets:Café` or `Assets:<BOM>A`) started no recovery window, so the lines bison keeps quiet after it kept their errors. beancount's lexer reads such an account into an ACCOUNT (or, glued to more, an invalid token) and its grammar fails on the line as on any other: the error now starts the window like rledger's other line errors. Not on a line holding a stray `\r` (unmodeled, as before). - An undated declaration bison's recovery starts mid-line and that fails past its first three tokens (`popmeta pushmeta kk: @`) builds nothing: bison reports that failure and restarts its recovery there. The failure is now reported (an error is added where rledger has none) and the window goes on from it. - An indented line after an `option` bison builds inside a transaction's body fails at its indent; on ` $x` the indent's error is added beside the invalid token's, which rledger names already. - A line's grammar failure counts as one error beside its invalid tokens where it is known to be bison's own (a column-0 statement failing among its first three tokens, a body line failing at its first token, nothing before keeping bison recovering), so a misgrouped number there is reported. An indented line whose date starts no statement (` date: 2024-01-02`) no longer ends the read-back recovery. Parity corpus: 107,435 -> 107,631 matching, 0 regressions. BOM matrix: 52 more rows match, none fewer. Generated differentials (1.26M inputs, main vs branch): 8,105 gained, 473 closer, 48 moved away (44 with a stray `\r`, a BOM or control characters). WASM cache 139. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
force-pushed
the
fix/recovery-invalid-account
branch
from
November 26, 2026 14:53
a4c1ff4 to
17f78fd
Compare
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 changed
These are the shapes #3040 left in
cst/recovery.rs, rledger's model of bison's error recovery.An invalid account starts the recovery window.
P0006is rledger's line error for a line it cannot read that holds an account such asAssets:CaféorAssets:<BOM>A. It started no window, so the lines bison keeps quiet after it kept their errors. For example,Assets:FundoInclusão:X 1 BRLat the top of a file followed byAssets:Eventos:Ygave two errors where bean-check gives one.beancount's lexer reads that account into an
ACCOUNT: its account rules (ACCOUNTTYPE/ACCOUNTNAMEinlexer.l) admit any UTF-8 character, a BOM included. Glued to more text, it reads it into an invalid token. Either way the grammar fails on the line as it does on any other. So the error now starts the window, exactly as rledger's other line errors do. The existing token-by-token machine then decides where bison fails.The one exception is a line holding a stray
\r(#2980). No recovery is modeled there, and the lines after keep their errors, as before. Starting a window there would trade one unmodeled case for another, and the differential showed it moving ~180 BOM/\rinputs away.An undated declaration that bison starts mid-line and that then fails. In
popmeta pushmeta kk: @,~ pushmeta kk: "v" @orx option "title" "t" 5, bison's recovery shifts the declaration's first three tokens and resumes reporting. It then fails again at the next token. The declaration builds nothing, so it changes no state. Bison reports the second failure and starts its recovery over there.Before, rledger reported one error on such a line and treated the lines after it as reported. Now that failure is reported. Where rledger has no error at that token, one is added:
unexpected "@" in the pushmeta directive: expected the end of the line. The window then goes on from the failing token. The completion is modeled foroption/pluginwith two strings,popmeta KEY:, andpushmeta KEY:with an optional string, account, date, currency, tag or bool value. A numeric value or expression, and a string running over a line end, are left unmodeled.An indented line after an
optionin a transaction's body (#3040 item 2). Bison builds the option whole and is back at adeclarations, so the next indented line fails at its indent. rledger reads that line as part of the transaction. On$xbean-check reports two errors (unexpected INDENTandInvalid token: '$x') and rledger reported one. Since rledger's error already names$x, the indent's error is the one added:unexpected indent: no entry continues on this line.Counting a grammar failure beside the invalid tokens. A line that fails and also has invalid tokens reports one error per token plus one for the failure. The old guard never let rledger add a missing token error past its own error count, so
Assets:B Assets:a # 1.5 1,50 @@lost the1,50. The failure now counts as its own error only where it is known to be bison's own failure, with nothing before keeping bison recovering:Restricting it this way matters: unrestricted, the change moved ~100 realistic g3 inputs away (for example
Z 1,50, whereZis a posting flag beancount takes).Separately, the read-back over lines before an orphan indent used to treat any indented line holding a date or keyword as ending the recovery. It now runs the recovery machine over that line (
recovery_ends_on_line), sodate: 2024-01-02(a DATE shift, then an EOL that is not taken) no longer ends it.The pass stays linear. Each new lexing reuses what the read-back already covered, and the dated header kind is cached per header.
test_quiet_bison_recovery_scans_linear_bytesgains four shapes: invalid accounts, lines after options in a body, undated declarations failing mid-line, and date lines in a recovery.Measurements (beancount 3.2.3)
--update.BOM_MATRIX_RELABEL=1.STRICT_BASELINE=1parser-corpus and cst-corpus manifests: pass, no drift.\r, a BOM or control characters. The other 4 are random-token lines:2000-01-01Z open 1,50 |, rledger now reports beancount's1,50error, which exposes its ownP0024pipe note as one extra.\rs. Of the 2 closer ones, one holds a BOM and\r; the other differs only on the posting line after anoption(below).Left as is, and why
optionin a body (option "a" "b"thenAssets:B 1 USD). bean-check reportsunexpected INDENTthere and drops the posting. rledger keeps the posting in the transaction ("entries beancount drops are kept"), so it reports nothing.$then2024-01-02 open Assets:Ztwice, or anoptioninside a phantom transaction's body followed by$. Modeling it needs a second level ofphantom_errorsre-parsing, which is quadratic on chains of such lines.\r, BOM and control-character inputs. Most of the 48 that moved away hold these (fix(parser): read a stray \r before an invalid token as a blank, as beancount does #2980, compat(parser): a BOM at the start of a line ends its block, and hides the rest of a comment line, unlike beancount #2956), where the two lexers part and no recovery is modeled.WASM
CACHE_VERSION139 (137 is #3041, 138 is #3042). Loader cache unchanged (v78, after #3041).How to test
New tests in
crates/rustledger-parser/tests/bison_recovery_model.rspin each shape, with every count checked againstbeancount.parser.parser.parse_string3.2.3:test_parse_invalid_account_starts_the_recovery_windowtest_parse_indented_line_after_an_option_in_a_body_reports_its_indenttest_parse_undated_declaration_failing_mid_line_is_reportedtest_parse_date_on_an_indented_line_does_not_end_the_recoverytest_parse_grammar_failure_counts_beside_the_invalid_tokens🤖 Generated with Claude Code