Repository navigation
fix(parser): report a second BOM at the start of a file, as on any later line - #3101
Merged
Merged
Conversation
robcohen
force-pushed
the
fix/double-bom-line1
branch
from
November 29, 2026 01:11
6463ce7 to
3c6f918
Compare
Contributor
📊 Benchmark ResultsInstruction counts vs base (cachegrind, 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?
|
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! |
robcohen
force-pushed
the
fix/double-bom-line1
branch
from
November 29, 2026 04:12
3c6f918 to
75c6b2a
Compare
…ter line The parser strips the file's leading BOM and then built its tree with `SourceFile::parse`, whose token stream strips a leading BOM again. A second BOM at byte 3 was taken for the leading one and the rest of line 1 lexed at column 0, so `<BOM><BOM>; x`, `% x`, `! x` (and a bare `<BOM><BOM>`) were a skipped comment line with no error, where bean-check 3.2.3 reports `Invalid token` on line 1. The converter now builds its tree with `parse_structured_stripped`, which does not strip again: line 1 lexes as a line a BOM starts does anywhere else (`<BOM>;x` is one invalid token). The tree keeps that BOM as a `BOM` token of its own, the shape the formatter keys on, with the rest of its invalid token after it, and both converter walks report it (`P0026`). Parse-error parity: 5 pinned `bc-only` fuzz inputs now match (fuzz 43994 -> 43999), no regressions. Loader cache v84, WASM cache v166. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
force-pushed
the
fix/double-bom-line1
branch
from
November 29, 2026 07:31
75c6b2a to
a20ccd3
Compare
robcohen
added a commit
that referenced
this pull request
Nov 29, 2026
…ndants walk Since #3101 the descendants walk reports every BOM token in the tree (the leading BOM is stripped before the build, so one there is a second BOM), but the recorder only asked for the walk on an invalid token: the lean parse skipped it on such a file and lost the BomInDirectiveBody error. The recorder now flags a BOM token as it does an invalid one. The node-shape fixtures gain a second BOM at the start of the file and on a later line, and stray \r blanks after a line first token (#3099). Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 29, 2026
… built (ADR 0010) (#3113) * perf(parser): record the lines a defect check reads while the tree is built The tree builder hands each line, in the role it gives it (header, posting, metadata, other body line), to a BuildObserver. The converter builds with a recorder that runs the canonical line rules on the builder's own token slice once and keeps only which top-level items hold a line some check could report on. The checks then read the tree for those items alone; a clean file flags nothing. Co-Authored-By: Claude Opus 5.5 <[email protected]> * perf(parser): skip the descendants walk when the tree builder saw nothing it reports The recorder now also notes what the descendants walk could report on (an invalid token, a cost spec with a shape defect or no closing brace, a link as a metadata value, a custom or pushmeta directive) and collects the column-0 comments by the walk's own rule as the tokens go by. Without occurrences to collect, a file with none of those needs no walk. The line extraction is now slice-based, so the recorder copies no tokens for a clean line. Co-Authored-By: Claude Opus 5.5 <[email protected]> * perf(parser): cheaper recorder verdicts for metadata and sale postings Inline the recorder's per-token hook; a plain metadata line skips the walk's link scan; the plain-posting shortcut takes a sale's empty cost {}; and unevaluable_meta_value answers None before allocating when the value holds no operator or parenthesis, as cost_region_read would. Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs: ADR 0010, the tree builder records which lines the defect checks read Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs(changelog): record the build-time line checks Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(parser): the line-check recorder flags a second BOM for the descendants walk Since #3101 the descendants walk reports every BOM token in the tree (the leading BOM is stripped before the build, so one there is a second BOM), but the recorder only asked for the walk on an invalid token: the lean parse skipped it on such a file and lost the BomInDirectiveBody error. The recorder now flags a BOM token as it does an invalid one. The node-shape fixtures gain a second BOM at the start of the file and on a later line, and stray \r blanks after a line first token (#3099). Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs(changelog): re-measure the build-time line checks against main Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs: ADR 0010 names a second BOM among the walk's triggers Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs(parser): drop a redundant intra-doc link target in line_checks Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 30, 2026
`<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]>
robcohen
added a commit
that referenced
this pull request
Nov 30, 2026
…ne (#3168) `<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]>
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
A second BOM at the start of a file is now reported (
P0026, an invalid token on line 1), the same way one at the start of any later line is.<BOM><BOM>;x/%x/!xInvalid tokenP0026<BOM><BOM>(rest of the line empty)Invalid tokenP0026<BOM><BOM>; c x<BOM><BOM>$x,<BOM><BOM>2024-01-01 open ...P0026)Why
convertstrips the file's leading BOM, then built its tree withSourceFile::parse(stripped). That token stream (KindTokenIter::new) strips a leading BOM too. So a second BOM at byte 3 was taken for the leading one, and the rest of line 1 was lexed at column 0. Under beancount's line-skip rules,;x,%xand!xthere are comment lines, so nothing was reported. Thebom.rstest said the second BOM was left "for the lexer to flag", but it never got to the lexer.How
parse_structured_stripped/SourceFile::parse_stripped/KindTokenIter::new_strippedbuild the tree from an already-stripped source without stripping it again. Onlyconvertcalls them.ParseResult::syntax_rootis still that tree, and thesyntax_rootround-trip test now compares against this entry.<BOM>;xis one invalid token, as in beancount.BOMtoken of its own. The formatter keys on that token to keep the leading BOM, so its shape is unchanged. Anything else the lexer reads into the same invalid token follows as anERROR_TOKEN. Both converter walks (green and red) report aBOMtoken asBomInDirectiveBody. In the converter's tree it can only be a second BOM.test_parse_second_bom_at_file_start_is_reported: line 1 and a later line give the same per-line counts for; % ! & ? : # $ *, an empty rest, and; c x.test_parse_star_after_second_leading_bom_is_reported.test_format_source_reads_line_endings_as_the_tree_reads_a_second_bom: the tree now reads<BOM>"""and<BOM>"as beancount does, so the\r\nlands inside or outside a string as there.docs/reference/compatibility.mdP1 notes the second BOM. Changelog entry added under Fixed.Not changed:
<BOM><BOM>*xstill names its errorinvalid token 'x', where beancount names the whole run'*x'. The line count matches. The oracle's reconciler keeps the narrowest diagnostic on the slot, and fixing that is outside this change.Parity
compat-parse-error-parity.py --check: no regressions. 5 pinned fuzzbc-onlyinputs now match.bc-only: 20 → 15.impl-fewer|oracle:lex:token|top|^ errorcategory (5) is gone.compat-semantic-parity.py --check: no regressions. Match rate 99.93%.How to test
🤖 Generated with Claude Code