Repository navigation
fix(parser): report an indented * line instead of silencing it as a heading - #2785
Merged
Merged
Conversation
…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]>
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✅ 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]>
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
is_section_markerincrates/rustledger-parser/src/cst/convert.rs): a top-levelERROR_NODEline is a section marker only if its first non-trivia token is aSTARwith 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 withInvalid 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.*line is an ordinary error line (parse error: unexpected input), no longer a silenced heading.CACHE_VERSION46 -> 47, WASM 61 -> 62 (pin and fixture versions follow).Why
The walkers matched a line's first NON-TRIVIA token, and leading whitespace is trivia, so an indented
* hwas treated as a heading and silenced. Beancount does not ignore it: it reportssyntax error, unexpected INDENT(andunexpected ASTERISKafter a directive). With a"on such a line, the string swallowed the directives after it inside the silenced node:On
main:rledger checkreports "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:*line (two spaces, a tab,**, at file start and after a directive) gives exactly oneunexpected inputerror with its exact span, keeps exactly the surrounding opens, and no section-marker comment;"on the indented line: exactly one error, starting on that line, and no section comment (not silent any more);*posting flag inside a transaction is unchanged;parseandparse_red_onlyagree on directives, errors and comments.Pinned by mutation: making
is_section_markerignore the column, or reverting only the green walkers, or only the red walkers, to the old "first non-trivia isSTAR" 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 passrledger checkandformat; they are now refused, asbean-checkrefuses 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
format_sourcededenting an indented first line into a silenced heading (reachable through the FFI component's best-effortformat.source): fix(format): the error-tolerant formatter dedents an indented first line into a silenced heading #2786.*, trailing*, overlapping errors, one-character metadata keys): compat: small leniencies vs beancount (lone *, trailing *, overlapping errors, 1-char metadata keys) #2787."swallows: fix(parser): an unterminated quote hides every directive after it behind one error #2784.format_source(the error-tolerant formatter path) drops leading whitespace on the FIRST line of a file, as it does for any indentation there, so a file that starts with* hcomes out as a column-0 heading. Mid-file indented*lines are kept verbatim, andrledger format(try_format_source) refuses these files because of the parse error.Closes #2783
🤖 Generated with Claude Code