Repository navigation
fix(parser): count the lines after a stray \r as bean-check does, and four more BOM and pipe line shapes - #3052
Merged
Merged
Conversation
… four more BOM and pipe line shapes A stray `\r` is a blank to beancount's lexer; rledger reports one before a token that lexes as an error of its own (deliberate, #2980) and started no model of bison's recovery from such a line, so the lines bison keeps quiet after a statement failing there kept their errors. The input is now parsed once more as beancount reads it (`recovery::stray_cr_analog`), and from the first line holding a stray `\r` on, each line takes that parse's errors, except a line where rledger reports the `\r` itself, which keeps its own. Also: a line's BOM diagnostic stands for a first invalid token with no BOM; a misgrouped number beside a BOM-led token or a BOM inside an account is reported in the recovery; a pipe after a header failure gives no warning; an invalid booking method is reported on its `open`'s line. Generated differential (1.26M inputs, #3035/#3036 generators): 24,188 gained, 25,725 closer, 237 moved away (168 reproduce on the \r-free analog, 66 are the booking line where beancount drops the open). Parity corpus 107,647 -> 108,454, no regressions; BOM matrix 12,853 -> 12,917. WASM cache 142. 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?
|
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 |
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
Item 1 of the parse-error parity long tail #3043 left: stray
\r, mid-file BOM lines, and the random-token case that turned out to be a pipe warning.Stray
\r(the main change)A stray
\r(one not part of a CRLF line end) is a blank to beancount's lexer ([ \t\r]+). rledger reports one before a token that lexes, or at a line start, as an error of its own. That is a documented deliberate difference (#2980,test_parse_cr_with_more_of_the_line_after_it_stays_an_error).cst/recovery.rsstarted no recovery from such a line, so after a statement failing there, the lines bison keeps quiet kept rledger's errors:\r$/Assets:A 1 USDpushtag #a\r$/2024-01-02 2024-01-03 * "n"2024-01-02 open Assets:B \r5/"a"/Assets:A2024-01-02 open\rAssets:B/"a"/Assets:Aoption \r;c/-Model (
recovery::model_stray_cr_lines).recovery::stray_cr_analog):\rbecomes a space, of the same length, so every other byte keeps its offset;\rhas noINDENTin beancount (^[ \t]+/[^ \t\r\n]). Its content moves to column 0 and the blanks go after it. Error spans are mapped back.*,:, a flag, a#that starts no tag), a BOM that would land at byte 0, and a lone capital before a\r([A-Z]/[ \t\n]).BcLexer, so a\rinside a multi-line string is content.\ron, each line takes that parse's errors, except a line where rledger reads a stray\ras anERROR_TOKENof its own. That line keeps its own errors, so the deliberate error stays.\radds no push.\r. It is never nested: guarded byPHANTOM_DEPTHand a thread-local.Four more line shapes (found while closing the above)
convert::report_invalid_tokens_of_error_line). A line'sP0026now stands for the line's first invalid token when that token holds no BOM, so a run with a BOM inside it later on the line is one moreInvalid token. Example:2024-01-02 $ o<BOM>6is bean-check 2, main 1, now 2. A line where rledger reports a stray\rkeeps its old count, since that error is one beancount does not have. This retires most of the BOM matrix'sinner-bom-under-line-errorrows.1,50is reported on a line whose BOMs are each one token, or none, on both sides: a BOM-led invalid token (<BOM>x, which runs to the next blank in both lexers, compat(parser): an invalid run should swallow a following quote, #! or #+ mid-line, as beancount's lexer does #2928) or a BOM inside anACCOUNTbeancount's lexer reads (Assets:<BOM>A). It was left out on any line with a BOM. With the stray-\rmodel this closes 30 of the 48 inputs fix(parser): an invalid account starts bison's recovery, and three more recovery shapes count as bean-check does #3043 moved away.2000-01-01Z open 1,50 |). beancount warns about|from its grammar, so a header its grammar fails on first gives noPipe symbol is deprecated. That covers a second flag, a keyword or a tag before the strings, and a lone capital glued to what follows it. Example:2024-01-02 Z open |is now 1 error, as in bean-check, where it was 2. Too many strings is a builder error raised after the pipe is read, so it keeps the warning.Invalid booking methodis reported on theopen's own line (node_content_span, compat(parser): a pushtag, poptag or popmeta with an invalid date changes no state, and a pop error is on the pop's own line #2995's rule), not on a blank or comment line its node starts with after an earlier directive. Example:open/;c/open Assets:B "FOO"is bean-check line 3, main line 2, now line 3.Measurements (beancount 3.2.3)
Generated differential, main (
635bf818a4c) vs this branch: the #3035/#3036 generators' own 27 input files, 1,260,000 inputs. Per-line counts compared as the parity harness does.\rWhat moved away, 237 inputs, each classified:
\r. On every changed line, this branch counts exactly what main counts for the same input with each stray\rread as beancount reads it (the analog). beancount counts that analog as it counts the original. 131 of them are on lines with a BOM. Examples:$ 2024-01-02 * "y"/2024-02-30 5/"s"reports"s"(bean-check does not). That is a window that starts inside an entry bison builds mid-line, which the phantom parse ends at the body; it is item 2, in the follow-up PR.2013-05-18 ""/option "a" "b"/ postings /|.open, because the next line starts with an invalid token or bison is still recovering. rledger keeps it and its error ("entries beancount drops are kept"), now on theopen's line instead of a blank line before it.Other measurements:
9bc79f4f, matrix, tracked, compat): 107,647 → 108,454 matching, 0 regressions. 107,647 is fix(parser): an invalid account starts bison's recovery, and three more recovery shapes count as bean-check does #3043's 107,631 plus 16 format-compat test ledgers added since, which match on both sides. The manifest is rewritten with--update; 838 pins were stale.BOM_MATRIX_UPDATE=1 BOM_MATRIX_RELABEL=1. The relabel is for 44 matching rows whose reported token texts now include the inner-BOM run.inner-bom-under-line-errorcause tests moved to rows that still have that cause (x0<BOM>y x1<BOM>y; the recorded rowx0<BOM>y t<BOM>n, its nine columns regenerated with the matrix script's own functions).test_check_row_excepts_only_listed_exception_linesnow needs 10 single causes, not 11:extra-construct-errorlost its only row of its own to the pipe fix.Timing: linear. Seconds at 20k / 40k / 80k / 160k repetitions, release build:
\r$/ postingopen\rAssets:A/"a"/Assets:Apushtag #a\r$/ second-date entry / posting2024-01-02 $ o<BOM>6 x<BOM>ytest_quiet_bison_recovery_scans_linear_bytesgains three stray-\rshapes, which count both parses.test_tokenize_long_bom_runs_are_linear's 1 MB line. That test caught it, and it passes now.Robustness: no panics, and green and red agree, on the 1,260,000 generated inputs and the 44,598 fuzz-corpus files plus
fuzz/regressions. Every error span stays inside the source.Caches:
CACHE_VERSION141 → 142: parse errors move.Deliberate deviations
None changed. The stray-
\rerror stays where rledger reports it, and the booking-method change keeps "entries beancount drops are kept".How to test
Run locally:
cargo clippy --workspace --all-features --all-targets -- -D warnings(exit 0);STRICT_BASELINE=1corpus and CST baselines, no drift;--self-test;RUSTDOCFLAGS=-Dwarnings cargo doc -p rustledger-parser.🤖 Generated with Claude Code