Repository navigation
fix(parser): read a stray \r after a line's first token as a blank - #3099
Merged
Merged
Conversation
robcohen
force-pushed
the
fix/stray-cr-posting
branch
from
November 29, 2026 01:15
8a8d625 to
0052798
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?
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
robcohen
force-pushed
the
fix/stray-cr-posting
branch
from
November 29, 2026 04:21
0052798 to
11378a2
Compare
` Assets:A 10 USD @@\r 9 EUR` and ` Assets:A 10\r USD` are clean in beancount 3.2.3, which reads a `\r` that is not part of a CRLF line end as a blank. rledger reported the `\r` as an error of its own (P3, kept from when the formatter folded a bare `\r` into a line break, #2804), and the parser then dropped what followed it from the posting (the price, the units), so the transaction also failed to book. The lexer now turns any `[ \t\r]` run holding a stray `\r` into `Whitespace` trivia once the line has a token. A run that starts its line keeps its error (beancount does not take it as an indent, so it reads the line as unindented), unless it ends the line or the token after it is an error anyway. With mid-line runs always trivia, the longer needed: a line-start run peeks one token. P3 in compatibility.md and the overlay doc say only the line-start case now. Parse-error parity: 122,478 of 123,394 (was 122,378); the 13 inputs that newly mismatch read the same as with a space for the `\r`. Loader cache v85, WASM cache v167. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
force-pushed
the
fix/stray-cr-posting
branch
from
November 29, 2026 08:03
11378a2 to
70fdebb
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]>
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 stray
\r(one that is not part of a CRLF line end) after a line's first token is now a blank, as beancount 3.2.3 reads it:On main, rledger gave two errors here and dropped the total price. It did the same with
Assets:A 10\r USD, where it dropped the units, and then booking reported an interpolation error on top. bean-check accepts both. The parity manifest pinned this asimpl-more|impl:P0012|indented|INDENT ACCOUNT(42 inputs). Dropping a value changes the file's meaning, and P3 incompatibility.mdpromised at most one error.How
There is still one lexer and one rule.
TokenIter::stray_cr_trivia_endturns any[ \t\r]run that holds a stray\rintoWhitespacetrivia once the line has a token. So it applies between tokens, inside cost specs and prices, before a comment, and in metadata. The bytes stay in the CST, so lossless round-trip is unchanged.A run that starts its line is different in beancount too: its indent rule does not accept a run that holds a
\r. I checked this black-box.\r Assets:Ainside a transaction givesunexpected ACCOUNT, and\r2024-01-01 open …parses as anopen. rledger keeps that\ras an error of its own (P3, now narrowed to this case). The exceptions are unchanged: the run is trivia if it ends the line, or if the token after it is an error anyway (#2966).Because a mid-line run is now always trivia, the #2966 chain walk (
cr_chain_is_trivia, thepeekingclones,cr_chain_until) is no longer needed and is removed. A line-start run peeks one token (line_start_run_is_trivia).Docs: the P3 section and the
stray-carriage-returnoverlay doc now describe only the line-start case.Tests
stray_cr.rs:test_parse_cr_between_tokens_is_a_blankchecks units, cost, price, arithmetic, tags, metadata and flags. Each posting must parse error-free and identical to the same text with a space in place of every\r.test_parse_cr_in_a_line_start_run_stays_an_errorpins the line-start case.bison_recovery_model,unreadable_line_recovery,mid_line_hash_bang:Assets:A 1 USD\r#!xnow gives beancount's two errors (#!andx).\rexceptions now agree with beancount, so the exception is removed.cargo test -p rustledger-parserpasses, including the format tests and the strict corpus/CST baselines. Clippy with-D warningsis clean on parser, loader and wasm.Parity (beancount 3.2.3)
compat-parse-error-parity.py --check: 122,478 / 123,394 match, up from 122,378.\r. So they are existing mismatches that the extra\rerror happened to cancel out: a BOM-led indented line, and a builder error (too many strings) on a transaction beancount drops for an error in its body. They are left out of this PR's scope. The manifest is updated.compat-semantic-parity.py --check: passes, unchanged (9,563 match, 7 mismatch).Loader cache v85, WASM cache v167 (pin 85). Other open parser PRs take 83/165 and 84/166; whichever merges later rebases its number.
How to test
🤖 Generated with Claude Code