Repository navigation
fix(parser): keep each header string in its own field after an invalid token - #2944
Merged
Merged
Conversation
…d token A transaction whose header holds an invalid token is kept under error recovery, but its payee and narration were read by counting only the strings that survived, so `* "p" <bad>` loaded with no payee and the narration `p`. The LSP, WASM and FFI, which load despite parse errors, showed the shifted fields. Both walks (red `convert_transaction`, green `convert_transaction_header`) now read the fields through one shared rule, `txn_header::header_payee_narration`: an invalid token before the first tag or link holds the string slot it sits in. A lone string followed by one is the payee, with an empty narration; a lone string after one is the narration; two strings are the payee and narration whatever surrounds them. Error counts and spans are unchanged. Loader cache v73, WASM cache v98. Closes #2932 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 |
…rule Review round 1 of the header recovery fix (#2932): - A lone string is the payee only when an unexpected token follows it and none comes before it, so `* <bad> "n" <bad>` keeps the narration `n`: a token written after a string no longer changes its field. - Every token the header grammar has no place for holds its slot, not only an invalid token: a number, a currency, an account, `~`, `@`, a brace, a comma, a keyword, a second flag, a mid-line `#!`. `* "p" 123` keeps payee `p`, as `* "p" <bad>` does. - The rule is `txn_header::header_strings`, which returns string indexes, so the typed `ast::Transaction::payee()` / `narration()` accessors use it too and cannot drift from the directive. Formatter output is unchanged. - The loader cache v73 note says the bump only follows the pin convention: that cache is never saved for a load with errors. - The parser corpus baseline entry for lima's ErrorInTransactionLine (`* "Dinner" A:*:B`) moves: `Dinner` is now the payee. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t the payee Review round 2 of the header recovery fix (#2932): - Narrow the rule to the one token that can have swallowed a string: an invalid token (a mid-line BOM lexes as one). A lone string right after the flag, followed by an invalid token, is the payee with an empty narration. Every other case keeps beancount's count rule, so `* "Coffee" 5.00 USD` (a forgotten newline) keeps the narration `Coffee`, and anything before the string (`* 123 "n" <bad>`, `* 2024-01-03 "n" <bad>`, `* <bad> "n" <bad>`) leaves it the narration. - `header_strings` now reads token kinds only; the date and flag are told apart by position, so the green walk no longer tracks offsets and the dead `k != DATE` guard is gone. - The `tests/ast.rs` flip and the lima parser-corpus manifest change are reverted: neither header has an invalid token. - Cache notes name the actual holders of the skipped versions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…o-shift # Conflicts: # CHANGELOG.md
Reword the header_strings doc: a transaction node opens only on a flag token, a string, a tag or a link, not on an invalid token. Add the [date, bad, s, bad] case, so dropping the ERROR_TOKEN guard in the flag arm (which would read the invalid token as the flag and move the string to the payee) fails a test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 11, 2026
… and escape query's option messages Review round 3 of #2945. - Loader CACHE_VERSION 69 -> 71 (WASM pin 71). Ignoring an included `documents` option (E7009) changes loader output: a v69 blob of a ledger whose include sets an existing `documents` root kept serving the `document` entries with no E7009. v70 is held by #2931 and v73 by #2944. The CostNumber and MetaValue fixture tripwires move to 71; no archived layout moved. - rledger query escapes an option diagnostic's message on the terminal path, as Diagnostic::to_line does (#2538), with a test. - CHANGELOG: ag-rledger query warnings carry optional file and line keys; rledger merge refuses a tree whose include sets documents. Refs #2925 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 11, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…id token The control-chars load-error tests from #2922 use the header `* "bell\u{7}" junk`. With this branch the invalid token after the lone string keeps that string in the payee, so the control character is reported in the payee rather than the narration. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
robcohen
added a commit
that referenced
this pull request
Nov 12, 2026
Brings in #2947. Conflicts resolved keeping both sides: - CHANGELOG Fixed section: both entries kept. - rustledger-wasm cache.rs: main's v97 note kept, this branch's v99 note follows it (v98 is held by #2944). CACHE_VERSION stays 99. - rustledger-wasm api.rs and parsed_ledger.rs: main's reported_ledger_errors (drops advisory-only E1004) plus this branch's located option diagnostics. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…o-shift # Conflicts: # CHANGELOG.md # crates/rustledger-wasm/src/cache.rs
robcohen
added a commit
that referenced
this pull request
Nov 12, 2026
…nd locate every option diagnostic (#2945) * fix(loader)!: validate options in included files as beancount does, and locate every option diagnostic beancount parses each included file with its own Builder and fresh options: every value an option's converter rejects is an error at the included file's line (bean-check exits 1), and only the top-level file's values are kept. rledger reported every included option as the E7009 warning, valid or not, and exited 0. set_scoped_inner now reads an included non-accumulating option into a scratch Options, keeps its diagnostics and drops the value. E7009 is left for a value the converter accepts. An included name_* root still does not root that file's own accounts (E1005), a deliberate deviation now commented and pinned. Every option diagnostic (E7001 to E7011) carries the option's file and line: OptionWarning gains `site`, stamped by set_scoped_at, and E7006 / E7010 are located from the applied values. rledger check (text, JSON, and ag-rledger check through it), the LSP (diagnostic on the option line, in the file it is in), WASM option_errors and multi-file Ledger errors read it. WASM validateMultiFile now reports option diagnostics at all. Drift guards pin check's JSON and text, the LSP's two paths and WASM's two multi-file paths to the loader's sites. WASM cache v99; the loader cache never stores a ledger with option diagnostics, so it stays at v69. Refs #2925 Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(loader): one canonical option-diagnostic mapping, and keep a ledger's options off unrelated LSP buffers Review round 1 of #2945. - rustledger_loader::option_warnings_to_errors maps OptionWarning::site to LedgerError::location (column 1). rledger check, the LSP and WASM (via From<LedgerError>) read it; the WASM helper is a one-argument wrapper and single-source entry points drop the file with without_files. - LSP: a buffer the ledger does not include gets its own options' diagnostics, never the ledger's drawn on its lines. - LSP option range stops before a `; comment`; the live-buffer limitation is documented. - Options::locate is by occurrence, so a repeated documents value is located at each of its lines. - validate_with_filesystem reports option diagnostics beside a fatal load error or a processing failure. Refs #2925 Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(loader): ignore an included documents option as beancount does, and locate query's option diagnostics Review round 2 of #2945. - documents leaves ACCUMULATE_ACROSS_INCLUDES: beancount 3.2.3 keeps only the top-level file's (load_file gives documents == [] for an included root and bean-check exits 0 with it missing), so an included value is read by the scratch converter and ignored with E7009, never scanned or checked (no E7006). - rledger query prints option diagnostics through the canonical mapping, with file and line; ag-rledger's query warnings carry them. - WASM Ledger::from_file_map's processing-error arm keeps the option diagnostics, as validate_with_filesystem does. - LSP option_error_file_id uses SourceFile::id. - Tests pin site_of's last-line choice (E7010), without_locations clearing every site, and included documents. Refs #2925 Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(loader): bump the loader cache for the included documents option, and escape query's option messages Review round 3 of #2945. - Loader CACHE_VERSION 69 -> 71 (WASM pin 71). Ignoring an included `documents` option (E7009) changes loader output: a v69 blob of a ledger whose include sets an existing `documents` root kept serving the `document` entries with no E7009. v70 is held by #2931 and v73 by #2944. The CostNumber and MetaValue fixture tripwires move to 71; no archived layout moved. - rledger query escapes an option diagnostic's message on the terminal path, as Diagnostic::to_line does (#2538), with a test. - CHANGELOG: ag-rledger query warnings carry optional file and line keys; rledger merge refuses a tree whose include sets documents. Refs #2925 Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
#2945 took loader v71 and WASM v99, so this branch keeps loader v73 and moves WASM to v102 (v100 and v101 are held by #2931 and #2952). Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 12, 2026
Resolve the CHANGELOG and WASM cache conflicts with #2944. Main is now at WASM cache v102 (loader v73), so this PR moves its WASM CACHE_VERSION from 101 to 103, with its note after main's v102 note; v101 was never released. LOADER_CACHE_VERSION_PIN stays at main's 73, since this PR does not move the loader cache. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 12, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 12, 2026
Loader cache v74 and WASM cache v104 for #2931, above main's v73 / v102 (#2944) and #2952's WASM v103. 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
A transaction whose header holds an invalid token is kept under rledger's error recovery. An invalid token runs to the next blank, as in beancount's lexer, so it can swallow a string: in
* "p" \x11"y"the"y"is part of the invalid token. Counting only the strings that survived then moved them to another field:* "p" \x11"y"/* "p" \x11pp, narration""txn "p" \x11 #t ^lpp, narration"", tags/links unchanged* \x11"x"""* \x11 "n"/* \x11 "n" \x11n* 123 "n" \x11/* 2024-01-03 "n" \x11n* \x11 "p" "n"/* "p" \x11 "n"p, narrationn* "n" #t \x11n* "Coffee" 5.00 USD(forgotten newline)CoffeeOne rule decides the fields:
txn_header::header_strings, documented in its rustdoc. It reads token kinds only and returns string indexes. Redconvert_transaction, greenconvert_transaction_header, and the typedast::Transaction::payee()/narration()accessors (read by the formatter) all use it.#!) holds a slot. A mid-line BOM lexes as an invalid token.Why
Issue decision: keep the transaction and never shift fields. The CLI refuses ledgers with parse errors, but the LSP (outline, folding, payee completion), WASM
parseand FFI embedders load despite them and showed the shifted data. WASM BQL refuses on parse errors, so it is unaffected.Error counts and spans are unchanged:
compat-parse-error-parity.py --checkreports no regressions.BASELINE_UPDATE=1leaves lima'sErrorInTransactionLineentry as on main.Over 30,000 random headers compared against
origin/main(662aa9f), status, errors and formatter output are identical. Fields change on 130 headers, all of which hold an invalid token. Each change is the same: a lone narrationXbecame payeeXwith an empty narration. No valid header changes.Caches: WASM v102 is needed, because the WASM cache can hold a ledger with parse errors. Loader v73 only follows the pin convention, because the loader cache is never saved for a load with errors. Both sit above main (loader v71, WASM v99 after #2945). Holders of the skipped numbers: loader v72 is #2931 and v74 is #2946; WASM v100 is #2931, v101 is #2952 and v103 is #2946 (v98 was never released).
How to test
cargo test -p rustledger-parser --test txn_header_invalid_token_fields: payee, narration, tags, links, posting count, error count and first-error span, green/red parity, and the typed AST accessors. It covers invalid tokens and 16 other unexpected-token kinds after the string, before it, around it and after a tag.cargo test -p rustledger-parser test_header_strings_moves_no_string test_convert_transaction_header_invalid_token_moves_no_string: the rule over every kind, and the green header walk itself compared againstparse_red_only.cargo test -p rustledger-lsp test_document_symbols_invalid_token_after_payee_keeps_the_payeecd crates/rustledger-wasm && wasm-pack test --node(wasm_header_invalid_token.rs)Review round 1
* <bad> "p" <bad>no longer movespto the payee.ast::Transaction::payee()/narration()read the shared rule.count > 0nit was removed in the rewrite.Review round 2
#!cannot swallow a quoted string, so it holds no slot and the count rule stands:* "Coffee" 5.00 USDkeeps the narration. Thetests/ast.rsflip and the lima manifest change are reverted, since neither header has an invalid token, and both files now match main. The unit, integration, green and WASM tables, the rustdoc, the red-side comment and the CHANGELOG are updated to match.* 2024-01-03 "n" \x11gives narrationn, as* 123 "n" \x11does. More generally, the payee exception needs the string straight after the flag. The missing error for a date in the flag position is left for the separate fix.k != DATEguard is gone.ERROR_TOKENarm.origin/main(perf(lsp): coalesce diagnostics during bursts of edits #2941, test(ffi-component): find the component under CARGO_TARGET_DIR #2943).Final round
header_stringsdoc now says a transaction node opens only on a flag token, a string, a tag or a link.[date, bad, s, bad]givesNarration(0). Deletingk != SyntaxKind::ERROR_TOKENin the flag arm makes it givePayee(0), so the test now catches that mutation (checked locally, then reverted).origin/main(test(core): shrink the slow rustledger-core tests under Miri #2939, fix(wasm): restore cached ledgers holding custom directives or metadata #2942, fix(loader)!: validate options in included files as beancount does, and locate every option diagnostic #2945, fix: make check, WASM, FFI and LSP agree on close-with-balance and after a booking error #2947, test(loader): bound exact_decimal by digits scanned, not wall-clock time #2950). The control-chars load-error tests from fix(lint): load every lint's ledger through one shared helper, and refuse failed processing in closed-nonempty #2922 use* "bell\u{7}" junk, a lone string before an invalid token, so they now expect the control character in the payee.Closes #2932
🤖 Generated with Claude Code