Repository navigation
feat(parser): a table-driven beancount error oracle, behind RLEDGER_ERROR_ORACLE - #3061
Merged
Merged
Conversation
robcohen
force-pushed
the
feat/lalr-error-oracle
branch
from
November 27, 2026 07:00
6d986aa to
3b97161
Compare
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 |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
This was referenced Nov 27, 2026
…RROR_ORACLE Replace the hand-modeled bison recovery step by step with beancount's own grammar. This adds the pieces, off by default: - scripts/gen-beancount-lalr-tables.py compiles pta-standards' clean-room, MIT-licensed beancount.y (vendored at 1463db773ac5, hash-checked) with the flake's bison 3.8.2 into cst/oracle/beancount/tables.rs; a new CI job regenerates and diffs them. - cst/oracle/beancount/lr.rs replays yacc.c's semantics over the tables: default reductions, error shift and yyerrstatus 3, discard, a lexer YYerror entering recovery without a report, YYMAXDEPTH 10000, EOF abort. No recursion, no panics, linear time; slots plus a reduction trace. - cst/oracle/beancount/lexer.rs: beancount's tokenization written from LEXICAL.md only. - cst/oracle/mod.rs: the format-neutral ReferenceOracle / reconcile / DeviationOverlay seam; ten named overlays for the documented deliberate differences, each citing a new compatibility.md section. - scripts/compat-beancount-oracle-drift.py (in the parity job) holds the model to beancount itself: 122,917 of 122,917 inputs agree on tokens and syntax errors. With RLEDGER_ERROR_ORACLE=1 the parity harness matches 119,952 of 123,304 inputs where main matches 119,048, with no regression. The oracle runs only when rledger's own parse reports an error, so a clean ledger pays nothing. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…_lexer_drift The drift test from #3056 compared BcLexer, the recovery model's port of beancount's lexer, with lex_iter_string. Point it at the oracle's reference lexer, written from pta-standards' clean-room LEXICAL.md, which the remaining recovery code is being replaced with: 123,833 pinned inputs agree. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
force-pushed
the
feat/lalr-error-oracle
branch
from
November 27, 2026 10:45
3b97161 to
cb67c38
Compare
This was referenced Nov 30, 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
Phase 2, part 1 of replacing the hand-modeled bison recovery (
cst/recovery.rs, the convert.rs quieting passes) with a table-driven error oracle. This PR adds the oracle and wires it intoconvertbehind a switch, off by default (RLEDGER_ERROR_ORACLE=1). Nothing changes for users until a follow-up turns it on.Tables —
scripts/gen-beancount-lalr-tables.pyruns the flake's bison 3.8.2 (it refuses any other version) on pta-standards' clean-room, MIT-licensedformats/beancount/v3/grammar/beancount.y. The grammar is vendored at rustledger/pta-standards@1463db773ac5 ascrates/rustledger-parser/grammar/beancount.y, and the script checks its SHA-256. The output is the checked-incst/oracle/beancount/tables.rs. A new CI job,Beancount LALR tables freshness, regenerates the tables and diffs them, andbuildrequires it.Driver —
cst/oracle/beancount/lr.rsreplaysyacc.cexactly:yyerrstatus3, with discard;YYerrorentering recovery with no report;YYMAXDEPTH10000 ("memory exhausted");It has no recursion and no panics (every table read goes through
get), and runs in linear time. It emits slots plus a reduction trace (built and dropped statements).Clean lexer —
cst/oracle/beancount/lexer.rsis written fromLEXICAL.md/harness/reflexer.pyonly. It does not touchBcLexer; deletingBcLexeris a later PR.Reconciler + overlays
cst/oracle/mod.rsis format-neutral, with no beancount types. It holdsReferenceOracle,Slot/Reference, theDeviationOverlaytrait, andreconcile. The trait's hooks are: an input/token rewrite before the reference lexes; a transform of the reference; and claims on rledger errors or lines as rledger's own.reconcileworks line by line:is_a_builder_*canonicals.Deviations — ten named overlays in
cst/oracle/beancount/overlays.rs, each citing a new "Parse-Error Differences" section ofdocs/reference/compatibility.md: byte-0 BOM, EOL error on the failing line (compat(parser): stay quiet after any line beancount cannot read, until its grammar has read three tokens #2993), stray\r(fix(parser): read a stray \r before an invalid token as a blank, as beancount does #2980), tags after first posting (A #tag after a transaction's first posting is kept by rledger, not by beancount #2575), indented comment after a gap, BOM orphan line, kept entries,{*}cost merge, divide-by-zero (a fixable beancount crash), and numbers beyond 28 digits. A test checks that every overlay's section exists. No deviation's behaviour changes: measured, see below.Gate — the oracle runs only when rledger's own parse reports an error, so a clean ledger pays nothing.
scripts/compat-beancount-oracle-drift.pychecks the gate (below).Lexer drift —
cst::bc_lexer_drift(feat(parity): name parse-error mismatches by category key through ptadiff #3056) now checks the new lexer instead ofBcLexer.Measurements
The parity harness here is main's, after #3056: it uses ptadiff and includes its generator sample.
scripts/compat-beancount-oracle-drift.py)cst::bc_lexer_drift, now on the new lexerwasm-pack --target web --release)STRICT_BASELINE— unchanged with the switch off, since the default path is untouched. With the switch on, 13 parser tests change, the BOM matrix among them. Those are re-pinned in the follow-up that turns the switch on.2229-4/3G). Those stay as they are on main and are counted.\r(the documented fix(parser): read a stray \r before an invalid token as a blank, as beancount does #2980 difference). The rest are mostly builder or state errors the token grammar doesn't model: push/pop built mid-line during recovery, repeated pipe warnings.Follow-ups (separate PRs)
quiet_bison_recoveryand the phantom recursion,accepts(),model_stray_cr_lines/stray_cr_analog, the convert.rs quieting passes,BcLexerand the logos patches that depend on it. Each deletion is gated on parity--check, the BOM matrix,STRICT_BASELINEand the parser suite.How to test
Clean-room note: nothing here was derived from beancount's
grammar.y/lexer.l/ generated parser, or fromBcLexer's rule logic. The provenance is recorded in each new module.🤖 Generated with Claude Code