Repository navigation
fix(parser): report a line beancount cannot read as often as beancount does - #2885
Merged
Merged
Conversation
…t does Beancount reports an `Invalid token` error for each token its lexer cannot read, and a syntax error only when its grammar fails at a readable token first (once the lexer has reported, bison's recovery reports nothing more for the statement). rledger reported the line error and, on top of it, an inline error for the line's unreadable token, so ` * h` after a transaction's postings, ` k: 1` in a transaction, `Assets:A -39.65 oops NZD` and ` ofxid*: "x"` each gave two overlapping errors where bean-check gives one. `drop_errors_inside_a_line_error` runs on the sorted errors: inside a syntax error, the first generic error on its first line is dropped when the tokens before it are a readable start of an indented line (nothing, a posting flag, an account and a prefix of a plain amount). Later unreadable tokens keep their errors (` * h x` is two, as there), and so does a line whose grammar fails first (` ** h`, ` @ x`, `Assets:A****7f855c`). The outer error is the one kept, since the formatter reads its verbatim-copy ranges from it. A counter test pins it linear. The other #2787 rows (lone `*` line, trailing `*`, one-character key) were already errors as in beancount; they are pinned by tests. - Parser-corpus baseline rows for the three parser-lima error files whose error lists moved (all three now match bean-check's counts); the CST rows do not move. - Loader CACHE_VERSION 59, WASM 76 (v75 is #2881). Closes #2787 Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # CHANGELOG.md # crates/rustledger-wasm/src/cache.rs
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?
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Review round 1 on #2787: with the inner error dropped, the editor showed only a whole-line "unexpected input" for ` * h`, where bean-check says `Invalid token: 'h'`. A generic line error that stands for a dropped inner error now reads `unexpected input: invalid token 'h'`, the token escaped and capped at 40 characters. The outer range is unchanged, so the formatter's verbatim-copy ranges are too. The one parser-corpus row whose error text moved (parser-lima examples_data_error-parse) is updated. Also: the dates linear-test doc comment is back on its test, and two long lines are wrapped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
to MoTechnicalities/rustledger
that referenced
this pull request
Nov 7, 2026
Brings in rustledger#2885-rustledger#2889. The only conflict was CHANGELOG.md, in Breaking and in Fixed, where both sides added entries; both are kept. 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
#2787 listed four small leniencies against beancount 3.2.3. Each was checked against bean-check 3.2.3 before coding:
*line at column 0*after a directive* hline after a transaction's postings gives overlapping errorsk: 1)The overlapping errors
The issue suggested "one error" per line. That turns out not to be beancount's rule:
Invalid tokenerror for each token its lexer cannot read.So bean-check counts per line come out like this:
* his 1 error: the*is a posting flag, thenhis unreadable.* h xis 2:handx.** his 2: the grammar fails at the second*, thenh.@ xis 2.Assets:A****7f855c 1 USDis 2.rledger reported the line error plus an inline error for each
ERROR_TOKENon the line. The first unreadable token was therefore counted twice: once by the line error and once by itself.The new
drop_errors_inside_a_line_errorruns on the final, sorted error list. Inside a syntax error, it drops the first genericunexpected inputerror on that error's first line, but only when the tokens before it are a readable start of an indented line:[-+]? NUMBER CURRENCY).In every other case both errors are kept, as on main. Other details:
ErrorRanges) from the outer errors.Why
Issue #2787: match beancount. No deviation is introduced.
How to test
Verification
open, plus the issue's own shapes and 5 posting shapes. The parse-error lines and counts now match on 11 more probes than on main, and none matches on main that does not match here.open, which bean-check counts as a grammar error plus an invalid token; a posting error after a header error; a later metadata line after a broken one.parser-lima, and all now match bean-check's per-line counts exactly:examples_data_error-parse.beancount: lines 16, 17 and 22.examples_data_error-includes.beancount: line 30.examples_data_error-includes_simple-errors.beancount: lines 2 and 6.tests/baselines/parser-corpus.manifestare updated. Their source hashes are unchanged; the errors are part of the fingerprinted output. Their CST rows do not move.STRICT_BASELINE=1corpus and CST baselines pass.format_sourceand whole-fileformat_parsed_range(the LSP range path) give byte-identical output on main and the branch for all 1,112 readable ledgers.rledger formatand the LSP whole-document path only format files with no errors. LSP surface cleanup and WASM/FFI do not read the error list, or fall back toformat_source.test_drop_errors_inside_a_line_error_is_linear_in_the_inputcounts the bytes the pass scans: the source once for line starts, plus each lexed line prefix. It tests 20,000 broken lines, and 20,000 unreadable tokens on one line.cargo test --workspace --all-features --no-fail-fastcargo clippy --all-features --all-targets -- -D warningsRUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-depscargo fmt --checkCACHE_VERSION59 (withFIXTURE_VERSION), WASM 76 (withLOADER_CACHE_VERSION_PIN59). WASM v75 is refactor: one rule for when a query answers despite load errors #2881's.#2872 rows
None of the #2872 rows is changed by this PR. The "unterminated string followed by
;x" row still shows its duplicated line-2 error. There, the line error and the inline error sit on a directive header (2024-01-02 note Assets:A "x), and this PR's rule only covers indented lines. Extending it to headers through the header grammar's failure point is a natural follow-up for that row.Review round 1
unexpected input: invalid token 'h', like bean-check'sInvalid token: 'h'. The token text is escaped withchar::escape_debugand capped at 40 characters, with...after a longer one. The outer range is unchanged, so the formatter's verbatim-copy ranges are unchanged too.unexpected trailing tokens after postingkeeps its own message.parser-lima/examples_data_error-parse.beancount, and it is updated. Its source hash is unchanged and its CST row does not move.test_parse_line_error_names_the_invalid_tokencovers the plain, capped and control-character cases.test_report_invalid_dates_is_linear_in_the_input. The two long lines are wrapped (theis_genericclosure is now amatch, so rustfmt keeps it wrapped).#tag hgives 2 errors where bean-check gives 1.^link hgives 2 errors where bean-check gives 1.Assets:a 1 USDgives 2 errors where bean-check gives 1.opencontext (a broken metadata line under a non-transaction directive), rledger reports one error where bean-check reports the grammar error plus the invalid token.Verification for this round: parser and LSP tests,
STRICT_BASELINE=1corpus and CST baselines, clippy-D warnings, rustdoc-Dwarningsandcargo fmt --checkall pass.Closes #2787
🤖 Generated with Claude Code