Skip to content

fix(parser): an orphan indented line reports beancount's indent error and each invalid token on it; pin the tag-line deviation - #3040

Merged
robcohen merged 1 commit into
mainfrom
fix/orphan-indent-errors
Nov 26, 2026
Merged

robcohen merged 1 commit into
mainfrom
fix/orphan-indent-errors

Conversation

@robcohen

@robcohen robcohen commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

What changed

Orphan indented lines (the general shape #3036 left). beancount's grammar takes an indent only inside a dated entry's body. On an indented line that no entry continues, bison reports syntax error, unexpected INDENT and starts its recovery at the indent. That happens at the top of the file, after a blank or whitespace-only line, after a column-0 comment or a line its lexer skips, after an undated directive (option, pushtag, ...), or after a statement bison built whole inside a body. The rest of the line is then quiet except for its lexer's errors, so beancount reports 1 + (invalid tokens, invalid dates and malformed numbers on the line) there. rledger's single line error covered both the indent and the line's first invalid token, so $x, "abc, 1,50 and Assets:A 1,50 USD each got one error where bean-check 3.2.3 gives two.

  • cst/recovery.rs now adds the missing lexer error on those lines, named the same way as the line's later invalid tokens (unexpected input: invalid token '$x', invalid number '1,50'), so the second error tells you which token is wrong.
  • Lines where the second error would add nothing are left alone. ! has no invalid token, so it stays one error. A BOM already has its own P0026, which names it.
  • If bison is still recovering at the indent, it reports nothing for the indent and the line keeps only its lexer errors. That covers two cases:
    • within two gap lines after an indented comment rledger accepts on purpose ( ; c then $x is one error; with two blank lines between, it is two);
    • after an indented line bison fails at that rledger reads as part of the entry (an indented option "a" "b" in a transaction).
  • Nothing is added after a stray \r, a BOM, or an error that started no recovery window (an invalid account), because that recovery is not modeled.
  • The pass stays linear. A one-pass block index answers "is this inside a dated body". The read-back over earlier lines stops at the previous window start, so each line is read about once. test_quiet_bison_recovery_scans_linear_bytes gains three shapes for this.

Tag line after the first posting (deliberate deviation, #2575). rledger keeps reporting this error on the tag line, where the mistake is. bean-check reports Tags or links not allowed after first Posting on the transaction's header line. This PR:

  • documents the deviation at the shared constructor and at both body checks;
  • pins it with test_parse_tags_after_first_posting_are_reported_on_the_tag_line;
  • makes scripts/compat-parse-error-parity.py move beancount's report to the k-th late tag line of its transaction, with a self-test for it.

The indented-comment deviation (test_parse_indented_comment_after_a_column_0_comment_is_accepted) is unchanged.

Measurements (bean-check 3.2.3)

WASM CACHE_VERSION 136 (134 is #3037, merged; 135 is held by #3039). Rebased onto #3037; loader cache v77.

How to test

cargo test -p rustledger-parser --test bison_recovery_model --test parser_integration_test
python3 -I scripts/compat-parse-error-parity.py --self-test
python3 -I scripts/compat-parse-error-parity.py --rledger target/release/examples/parse_error_lines --fuzz-dir DIR --fuzz-commit 9bc79f4f35f52c50813164f43307e7d151d70d8c --compat-dir tests/compatibility/files --check

Clippy (-D warnings) and the parser, loader, wasm, lsp and rustledger test suites pass locally.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 41.7ms ± 0.6ms 510.9ms ± 5.5ms 12.3x 43.4 MB / 51.3 MB
investment 62.7ms ± 1.7ms 2002.7ms ± 7.5ms 31.9x 47.1 MB / 59.2 MB
fifo 60.8ms ± 0.7ms 11680.0ms ± 92.4ms 192.1x 49.4 MB / 59.1 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 42.1ms ± 0.9ms 41.7ms ± 0.6ms -1.0% ✅ within noise 43.2 MB → 43.4 MB (+0.7%)
investment 62.1ms ± 0.9ms 62.7ms ± 1.7ms +1.0% ✅ within noise 47.1 MB → 47.1 MB (+0.1%)
fifo 60.4ms ± 0.7ms 60.8ms ± 0.7ms +0.7% ✅ within noise 49.2 MB → 49.4 MB (+0.3%)

A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: simple 0.5ms, investment 0.9ms, fifo 0.4ms), and is at least 5%.
10,000 transactions per shape · 20 runs, 3 warmup · hyperfine

What do these numbers mean?
  • simple — Two-posting transfers, one currency. The historical workload — keep as the floor, not as the benchmark.
  • investment — Cost specs, per-unit prices and lot reductions. Exercises booking and inventory, which simple leaves at 0.3%.
  • fifo — Bare {} reductions against a FIFO account — how FIFO sells are normally written. The other four shapes reach the ordered-selection path twice in 2k transactions between them, so it was effectively unprofiled until it turned out to be quadratic (plan_ordered scans every lot per reduction: FIFO ledgers are quadratic (8.8s at 20k transactions) #2083).
  • vs base: the PR and the base-branch commit it is built on, built and measured in the same job
  • RSS: peak resident set size, a single sample — reported without a verdict because there is no spread to test it against
  • A shape with no beancount column is one bean-check reports errors on; it is timed for rledger only

@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100% (raw 93%, 179 masked)
Full AST Match 100%
Total Files 828
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
    The headline is the EFFECTIVE rate, after pairs where beanquery
    itself is wrong are masked. raw is the same run with nothing
    masked. A widening gap means the registry grew, not that rledger
    changed.
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

@codecov

codecov Bot commented Nov 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.68421% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger-parser/src/cst/recovery.rs 98.68% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

… and each invalid token on it; pin the tag-line deviation

beancount's grammar takes an indent only inside a dated entry's body. On an
indented line no entry continues (top of file, after a blank or
whitespace-only line, a column-0 comment or skipped line, an undated
directive, or a statement bison built whole inside a body) bison reports
`syntax error, unexpected INDENT` and starts its recovery at that indent:
the line then carries that error plus one per lexer error on it (invalid
token, invalid date, malformed number). rledger's one line error stood for
both, so `  $x` was one error where bean-check 3.2.3 gives two.

- The recovery pass adds the missing lexer error on such a line, named like
  the line's later invalid tokens (`invalid token '$x'`, `invalid number
  '1,50'`). `  !` stays one error; a BOM keeps its own P0026.
- Where bison is still recovering at the indent (within two gap lines of an
  indented comment rledger accepts on purpose, or after an indented line
  bison fails at that rledger reads as part of the entry), the line keeps
  its lexer errors only.
- After a stray `\r`, a BOM or an error that started no window, nothing is
  added (that recovery is not modeled).
- Tag line after the first posting: rledger keeps reporting it on the tag
  line (bean-check uses the header line). Documented at both body checks,
  pinned by a test, and the parity harness moves beancount's report to the
  tag line.

Parity corpus: 107,279 -> 107,435 matching, 0 regressions (107,280 from the
tag normalization alone). BOM matrix unchanged. Generated differentials
(1.26M inputs): 51,974 gained, 1,076 closer, 16 moved away. WASM cache 136.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen force-pushed the fix/orphan-indent-errors branch from d1a0b3f to 6ceb680 Compare November 26, 2026 05:16
@robcohen
robcohen merged commit c991e0f into main Nov 26, 2026
62 of 63 checks passed
@robcohen
robcohen deleted the fix/orphan-indent-errors branch November 26, 2026 05:50
robcohen added a commit that referenced this pull request Nov 26, 2026
…breadth-first order, each currency once (#3038)

beancount 3.2.3 parses its files breadth first and `aggregate_options_map`
merges `operating_currency` in that order, `uniquify`d (first occurrence
wins, the top-level file's own repeats included). rledger merged it depth
first and kept repeats: `main` (MMM) including `x` (XXX, including `z`
ZZZ) then `y` (YYY) gave [MMM, XXX, ZZZ, YYY] against [MMM, XXX, YYY, ZZZ],
and USD in main and an include gave [USD, USD, EUR] against [USD, EUR].

Auditing the other options beancount aggregates across files:
`display_precision` is merged into the top-level file's display context
with `DisplayContext::update_from`, which keeps a fixed precision, so the
top-level file's value wins; rledger let the last file read win (an
include's USD:0.001 rendered 1.23456 USD as 1.235 where bean-query gives
1.23). `insert_pythonpath` becomes a sorted set there (no order) and has
no effect in rledger. Included plugins are ignored by beancount and run by
rledger deliberately; their order is unchanged.

- `Options::set_in_file_at` records each merged option's values with its
  file; `Options::merge_across_files(ranks)` is the one merge, called by
  `Loader::load` over `SourceMap::parse_ranks` before the display context
  and the cache see the options. Every surface (CLI, LSP, WASM, FFI) reads
  the loader's options or the cache's merged copy.
- `apply` lists a repeated operating currency once, for options set
  without the loader.
- Loader CACHE_VERSION 77 -> 78 (cached values change), WASM pin 78, WASM
  CACHE_VERSION 137 (135, 136 taken by #3039, #3040).
- Tests: unit tests for the merge; loader tests for the issue's trees, a
  duplicate include, a disk glob and a cache round trip, all checked
  against bean-check 3.2.3; drift guards across the loader, WASM `Ledger`
  (and restored), ffi-wasi, the LSP, and the CLI cold and on a cache hit
  (`report returns` currency, `query` precision).

Closes #3038

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen added a commit that referenced this pull request Nov 26, 2026
…breadth-first order, each currency once (#3041)

* fix(loader): merge operating_currency across includes in beancount's breadth-first order, each currency once (#3038)

beancount 3.2.3 parses its files breadth first and `aggregate_options_map`
merges `operating_currency` in that order, `uniquify`d (first occurrence
wins, the top-level file's own repeats included). rledger merged it depth
first and kept repeats: `main` (MMM) including `x` (XXX, including `z`
ZZZ) then `y` (YYY) gave [MMM, XXX, ZZZ, YYY] against [MMM, XXX, YYY, ZZZ],
and USD in main and an include gave [USD, USD, EUR] against [USD, EUR].

Auditing the other options beancount aggregates across files:
`display_precision` is merged into the top-level file's display context
with `DisplayContext::update_from`, which keeps a fixed precision, so the
top-level file's value wins; rledger let the last file read win (an
include's USD:0.001 rendered 1.23456 USD as 1.235 where bean-query gives
1.23). `insert_pythonpath` becomes a sorted set there (no order) and has
no effect in rledger. Included plugins are ignored by beancount and run by
rledger deliberately; their order is unchanged.

- `Options::set_in_file_at` records each merged option's values with its
  file; `Options::merge_across_files(ranks)` is the one merge, called by
  `Loader::load` over `SourceMap::parse_ranks` before the display context
  and the cache see the options. Every surface (CLI, LSP, WASM, FFI) reads
  the loader's options or the cache's merged copy.
- `apply` lists a repeated operating currency once, for options set
  without the loader.
- Loader CACHE_VERSION 77 -> 78 (cached values change), WASM pin 78, WASM
  CACHE_VERSION 137 (135, 136 taken by #3039, #3040).
- Tests: unit tests for the merge; loader tests for the issue's trees, a
  duplicate include, a disk glob and a cache round trip, all checked
  against bean-check 3.2.3; drift guards across the loader, WASM `Ledger`
  (and restored), ffi-wasi, the LSP, and the CLI cold and on a cache hit
  (`report returns` currency, `query` precision).

Closes #3038

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(loader): don't link the private MERGED_ACROSS_FILES from public docs

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
robcohen added a commit that referenced this pull request Nov 26, 2026
…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 added a commit that referenced this pull request Nov 26, 2026
…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 added a commit that referenced this pull request Nov 26, 2026
…re recovery shapes count as bean-check does (#3043)

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant