Skip to content

fix(parser): report an indented * line instead of silencing it as a heading - #2785

Merged
robcohen merged 2 commits into
mainfrom
fix/indented-star-line
Oct 28, 2026
Merged

robcohen merged 2 commits into
mainfrom
fix/indented-star-line

Conversation

@robcohen

@robcohen robcohen commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

What changed

  • One rule for which lines are org-mode headings (is_section_marker in crates/rustledger-parser/src/cst/convert.rs): a top-level ERROR_NODE line is a section marker only if its first non-trivia token is a STAR with nothing before it on its line in the source, i.e. a * at column 0 (a * after a BOM is not one: beancount rejects that line with Invalid token, as rledger already does before a directive). All four walkers that treat heading lines specially use it: error silencing (error_node_check / tl_error_node_check) and the empty section-marker comment (section_marker_check / tl_section_marker_check), on both the red and green paths. Each walker records the flag when it sees the line's first non-trivia token; the two section walkers now take the source text.
  • An indented top-level * line is an ordinary error line (parse error: unexpected input), no longer a silenced heading.
  • Loader CACHE_VERSION 46 -> 47, WASM 61 -> 62 (pin and fixture versions follow).
  • Tests and a CHANGELOG entry.

Why

The walkers matched a line's first NON-TRIVIA token, and leading whitespace is trivia, so an indented * h was treated as a heading and silenced. Beancount does not ignore it: it reports syntax error, unexpected INDENT (and unexpected ASTERISK after a directive). With a " on such a line, the string swallowed the directives after it inside the silenced node:

  * h "x
2024-01-02 open Assets:B
2024-01-03 open Assets:C

On main: rledger check reports "No errors found" and a query counts 0 entries. With this PR the line is reported, so the loss is visible. Bringing the swallowed directives back on top of the error is #2784 (a stray " should not run past its line); this PR makes the failure loud, which is the part that was silent.

The cache bump is needed because such a file parsed with no errors on main, so the CLI cached it as clean (and the WASM cache archives parse errors); a stale blob would keep reporting it clean.

How to test

cargo test -p rustledger-parser --test indented_star_line:

  • an indented * line (two spaces, a tab, **, at file start and after a directive) gives exactly one unexpected input error with its exact span, keeps exactly the surrounding opens, and no section-marker comment;
  • with a " on the indented line: exactly one error, starting on that line, and no section comment (not silent any more);
  • column-0 headings are unchanged: no error, exactly one section-marker comment spanning the heading line, the following directive kept;
  • a * posting flag inside a transaction is unchanged;
  • every case: the green-wired parse and parse_red_only agree on directives, errors and comments.

Pinned by mutation: making is_section_marker ignore the column, or reverting only the green walkers, or only the red walkers, to the old "first non-trivia is STAR" rule each fails 4 of the 5 tests; re-adding a BOM allowance fails the BOM test. (The per-line reset of the walkers' flag is defensive: no blank or whitespace-only line was found inside an error node, so no test pins it.) Full workspace suite (strict corpus baselines included): 6173 passed, 0 failed; workspace clippy, docs (including private items) and fmt clean. The local compatibility corpus has no indented * lines, so neither corpus baseline moves locally.

Release note

Files with an indented top-level * line used to pass rledger check and format; they are now refused, as bean-check refuses them. In the compatibility suite such a file moves from a mismatch to an agreement with beancount (821/821 check matches on CI).

No fuzz regression input: neither fuzz oracle (lossless round-trip, column-0 heading containment, green == red) can detect this bug, because both paths agreed and the round-trip stayed lossless; the exact tests pin it instead.

Not in this PR

Closes #2783

🤖 Generated with Claude Code

…eading

Only a * at column 0 is an org-mode heading. The four walkers that
silence heading lines (error silencing and the section-marker comment,
on both the green and red paths) matched a line's first NON-TRIVIA
token, so an indented "  * h" passed rledger check, where beancount
reports "syntax error, unexpected INDENT". With a quote on such a line
the string swallowed the following directives inside the silenced node,
and rledger check reported nothing.

- is_section_marker (convert.rs, shared by all four walkers): a section
  marker is a STAR whose line has nothing but BOMs before it in the
  source. The walkers record the flag when they see the line's first
  non-trivia token; the section walkers now take the source text.
- An indented top-level * line is an ordinary error line, so the loss
  is reported (keeping the swallowed directives is #2784). Column-0
  headings and posting flags are unchanged; green and red agree.
- Loader CACHE_VERSION 47, WASM 62: such a file parsed clean, so it
  was cached as clean.
- Tests with exact error kinds and spans, directives, comments and
  green/red parity; CHANGELOG.

Closes #2783

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen requested a review from a team as a code owner October 28, 2026 18:10
@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 31.4ms ± 1.7ms 464.4ms ± 33.0ms 14.8x 34.5 MB / 51.1 MB
investment 45.6ms ± 0.7ms 1658.6ms ± 35.6ms 36.4x 44.7 MB / 59.2 MB
fifo 46.0ms ± 3.9ms 8648.4ms ± 110.8ms 187.9x 40.7 MB / 58.9 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 30.2ms ± 0.4ms 31.4ms ± 1.7ms +4.2% ✅ within noise 34.4 MB → 34.5 MB (+0.2%)
investment 47.2ms ± 0.8ms 45.6ms ± 0.7ms -3.4% ✅ within noise 44.5 MB → 44.7 MB (+0.6%)
fifo 44.8ms ± 1.7ms 46.0ms ± 3.9ms +2.7% ✅ within noise 40.4 MB → 40.7 MB (+0.6%)

A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: simple 0.8ms, investment 0.5ms, fifo 1.9ms), 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 821
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 Oct 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

- is_section_marker: a section marker is a STAR with nothing before it
  on its line. The BOM allowance is gone: only a doubled leading BOM
  reached it, and beancount rejects that line (Invalid token), as
  rledger does before a directive.
- Cross-referencing comments at is_section_marker and the lexer Star arm:
  the lexer may skip more lines than are silenced, never fewer.
- Tests pin exact errors, comments and directives for 15 inputs (EOF,
  CRLF, bare *, after a comment, BOMs, a multi-line error node with a
  column-0 heading and an indented * line, the quote cases) and the
  posting flag value.
- CHANGELOG: beancount says unexpected INDENT, or unexpected ASTERISK
  after a directive.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen merged commit f3782b9 into main Oct 28, 2026
67 of 68 checks passed
@robcohen
robcohen deleted the fix/indented-star-line branch October 28, 2026 19:04
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.

fix(parser): an indented * line with a quote silently drops the following directives

1 participant