Repository navigation
fix(parser): report a second leading BOM on line 1 as on any later line - #3168
Conversation
✅ 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! |
📊 Benchmark ResultsInstruction counts and wasm fuel vs base (deterministic)
Instruction counts (cachegrind Wall clock (hyperfine)
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?
|
`<BOM><BOM>*x` on line 1 reported `P0012 unexpected input: invalid token 'x'` at column 8, where the same line anywhere else, and `<BOM><BOM>$x` on line 1, report the BOM (`P0026`). bean-check 3.2.3 reports one `Invalid token: '<BOM><BOM>*x'` on each. The tree keeps line 1's second BOM as a token of its own (#3101) and lexes the rest of the word apart, so the line held a diagnostic on the `x` as well as the BOM's, both on the token the reference reports, and the reconciler named the slot with the tightest. `reconcile` gains a `names(e, slot)` hook, taken before width when it pairs a slot with a diagnostic on its token; beancount's names that second BOM's `P0026` for the token beancount reads from it, on line 1 only (P1). Later lines are unchanged (a wider rule took a mid-file `InvalidAccount` message over a BOM-led account word). The line keeps its error count. The header-defect error that line 1 had sat inside the transaction after the BOM, so `transactions_beancount_drops` asked it and left it out, as beancount builds nothing there; the BOM's `P0026` starts before the transaction's span. The rule now reads a directive from the start of its header line (past a byte-0 BOM, as P1 strips it), so such a transaction stays out of the ledger. Loader cache v86, WASM cache v170. Co-Authored-By: Claude Opus 5.5 <[email protected]>
e4457d5 to
f76b3e9
Compare
…3162 and #3168 (#3175) Parser Baselines has been red on main since #3158: the parser-output hash moved on 54 corpus files whose source is unchanged (49 parser-lima, 2 double-entry-generator, 2 beancount-lazy-plugins, 1 jcornaz-parser). These are the intended output changes of #3158 (a typed number error on every ParseError), #3162 (a line-start stray \r read at column 0) and #3168 (a second leading BOM on line 1). Regenerated with scripts/regen-corpus-baselines.sh on a freshly fetched corpus (751 files); every changed entry keeps its path and source hash, and the CST manifest does not move. Co-authored-by: Claude Opus 5.5 <[email protected]>
What
<BOM><BOM>*xon line 1 now reportsP0026(the BOM), as the same line does anywhere later in a file, and as<BOM><BOM>$xon line 1 already did. The error count is unchanged.Before / after (bean-check 3.2.3: one
Invalid token: '<BOM><BOM>*x'on the line in every row)<BOM><BOM>*x(review reprosi14a,i14d)P0012 unexpected input: invalid token 'x', col 8P0026at the BOM<BOM><BOM>*x(i14b)P0026P0026(unchanged)<BOM><BOM>$x(i14c)P0026P0026(unchanged)Why it happened
The tree keeps line 1's second BOM as a token of its own (#3101) and lexes the rest of the word apart (
*, thenx), so line 1 carried a BOM diagnostic, a line error and anxdiagnostic, all on the one token the error oracle's reference reports there. The reconciler names a slot with the tightest diagnostic on its token, soxwon. On later lines the BOM-led word is one error token andP0026is the only diagnostic.How
reconcile(the format-generic reconciler incst/oracle/mod.rs) takes anames(e, slot)hook, consulted before width when it pairs a slot with a diagnostic on its token.names_line_1_bom_led_token: theP0026of a second BOM at byte 3 names the lexical slot starting there. Restricted to that one place on purpose: a version that preferred any BOM diagnostic at a BOM-led slot's start also replaced a pinned mid-fileInvalidAccountmessage (bom_mid_line_run::test_parse_partly_invalid_account_word_keeps_mains_message).transactions_beancount_dropsnow reads a directive from the start of its header line (past a byte-0 BOM, which P1 strips). Without it this change regressed the loaded ledger: line 1's old header-defect error sat inside the transaction, so the transaction was left out; the BOM'sP0026starts before its span, so it was kept (fuzz22c82db5d04b). The same rule now also leaves out an indented dated line beancount reads asunexpected INDENT(3 fuzz inputs), and 11 line-1 double-BOM transactions that main kept: in every case beancount builds nothing there.compatibility.mdsays it.Proof
overlays::tests::test_byte_zero_bom_then_a_second_reports_line_1_as_a_later_line(7 line shapes: line 1 has the same error count as the same line on line 2, and its first error isP0026; bean-check gives the same count on both, checked for each), andtransactions_beancount_drops::test_transactions_beancount_drops_one_a_second_leading_bom_starts(a double-BOM line-1 transaction is left out; a byte-0 BOM alone keeps a transaction whose error is a builder check).parse_error_lines --jsonl+semantic_snapshot, 45,182 inputs, release builds oforigin/main1f4b9dc and this branch): 46 fuzz inputs differ in parse errors, all the same change: a line-1P0012becomesP0026, same line, same count.semantic_snapshotadditionally differs on 14 fuzz inputs, each one transaction fewer (11 line-1 double-BOM, 3 indented dated lines), as above. No compat or tracked ledger changes.compat-parse-error-parity --checkno regressions, 122,533 / 123,394 (unchanged);compat-semantic-parity --checkno regressions, unchanged. No re-pin.cargo test -p rustledger-parser -p rustledger-loader -p rustledger-lsp -p rustledger-wasm --all-features: 2,430 passed, 0 failed. Clippy-D warnings: clean.Merge note
Independent branch off
main; the other parser PRs of this batch bump the caches to the same numbers (rebasecache.rs). The oracle line-index PR also editsreconcile_errors_with's call toreconcile, and the broken-directive PR renamestransactions_beancount_drops: trivial conflicts either way.🤖 Generated with Claude Code