Repository navigation
fix(parser): no error for a BOM-led account after a line's first error, and report a header defect before a tag (#2968) - #2983
Merged
Merged
Conversation
…r, and report a header defect before a tag A BOM that beancount reads into an account (`<BOM>Assets:A`) after an earlier error on its line got its own BomInDirectiveBody, one error more than bean-check 3.2.3, whose grammar is already recovering there. It is now dropped after an invalid token or a defect the grammar fails at first; an error that stands for the whole line does not count as one. A directive that does not take tags or links was reported only through its tag's error, so the header check never looked for an earlier defect (`close Assets:A TRUE $x #t`), and the tag's error is dropped after an invalid token. The header check now runs there too, and a defect before the tag is reported in its place. The BOM combination matrix takes in the moved counts: 618 more rows match bean-check, and the 9 that no longer do are a mid-line `T#!` that already counts one fewer here, which the dropped BOM error used to make up for; each is accepted with its reason. WASM cache v117 (v116 is held by #2981); the loader cache is unchanged. Closes #2968 Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 |
) Where the header defect now replaces a directive's tag and link errors, a line whose extra tag errors made up for a token rledger misses (`T#!`, `U?SD`, a second grammar error after `NULL`) counts one fewer than bean-check, and `{#t #u` one more, as `{#t` alone does. Each counts what main counts with its tags and links removed; pinned with those versions, and named in the CHANGELOG entry. 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
Two error counts after a line's grammar has already failed, both found in the #2931 reviews and both pre-existing on main (#2968's update section).
A BOM-led account after an earlier error on its line is no error. beancount 3.2.3 reads a BOM into an account (
<BOM>Assets:A,<BOM>xAssets:A), so it is no invalid token there; theACCOUNTis an error only when the grammar fails right at it. After an earlier error on the line (an invalid token,Assets:A $@ <BOM>Assets:A, or a defect the grammar fails at first,commodity HOOL TRUE <BOM>Assets:A), its grammar is recovering and reports nothing for it. rledger reported aBomInDirectiveBodythere.quiet_after_invalid_tokensnow drops thatP0026when a kept error before it on the same line counts as such a failure point: one past the line's content start, or an invalid token's own. A whole-line error (which starts at the indentation,<BOM>Assets:A 1 USD) does not count, so that pair stays as the BOM combination matrix's rules model it. Linear: each line's end and content start are found once.A header defect before a tag or link is reported in the tag's place.
reject_tags_and_linksreports a tag on a directive that does not take one, and the header check (directive_header_check) then never ran, because the converter had reported an error. With an invalid token between the two (close Assets:A TRUE $x #t), the tag's error is dropped after the token, so the line lost theunexpected BOOLbeancount reports first. The header check now also runs when the converter's only new errors are tag/link rejections (is_tag_or_link_rejection, matched by a shared message constant), and its defect replaces them when it comes before the first tag. A tag before the defect (close Assets:A #t TRUE) keeps its own message.Issue rows (bean-check 3.2.3 / main / this PR, the line shown)
After
2024-01-01 open Assets:Aand2024-01-01 open Assets:B:2024-01-02 */Assets:A $@ <BOM>xAssets:A.00/Assets:B2024-01-02 close Assets:A TRUE <BOM>x (k: #t Assets:A<BOM>~Assets:A $@ <BOM>Assets:A(in a transaction)Assets:A $@ <BOM>Assets:A.00close Assets:A TRUE $x #tclose Assets:A TRUE $x (k: #t Assets:A$~close Assets:A TRUE <BOM>xAlso fixed, from the differential:
Assets:A <BOM>Assets:B <BOM>Assets:A1/2/1;commodity HOOL TRUE <BOM>Assets:A1/2/1;Assets:A 1 USD ! <BOM>Assets:A1/2/1;close Assets:A TRUE #t ^l1/2/1;open Assets:C USD TRUE $x #t,event "a" "b" TRUE $x #t,pad Assets:A Assets:B 1 $x ^l,balance Assets:A 1 USD TRUE $x #t2/1/2.Differential
My own generator (
posting,metadataand 17 header shapes, each followed by 1 to 4 pieces from pools of invalid tokens, BOM-led accounts, tags/links and valid tokens, glued or after blanks or a tab; 15% after an erroring line; 15% CRLF, 10% no final newline; postings or a metadata line after), two seeds, run through bean-check 3.2.3 (the harness'srun_beancount), main (48ddb343451, with #2981) and this branch, per-line counts. Controls hold no invalid token, no BOM and no tag or link.No input changes on more than one line, and no directive is dropped or added (both changes only remove or replace errors on a line that already has one).
Documented family: the BOM error stood in for one rledger already misses (319 regressions, 3 further)
On every regressed line, rledger already reads the line with one error fewer than beancount, and main's
P0026for the BOM-led account made the count match by chance. 316 of the 319 count exactly what main counts with each BOM-led account written as a plain account (Assets:Z). The other 3 are lines where that rewrite itself changes how a neighbouring token lexes (a BOM glued to a link,^l<BOM>Assets:A,), so the whole-line analog cannot be built; the round-1 review's own generator found more such partial-rewrite and gluing cases, all the same mechanism. Each differs by one on one line. Examples (bean-check / main / PR, and main on the plain-account version):Assets:A ~$ <BOM><BOM>Assets:B -$Assets:A % $x <BOM>Assets:A, ^a-b2024-01-02 price HOOL 1 USD -1$x <BOM>Assets:A ~$(header)What rledger misses there:
~$, which beancount reads as~(a grammar error) and$;% $x, beancount'sFLAGerror and$x;-1$x, itsMINUSerror and$x; a mid-lineT#!(below).test_parse_bom_account_no_longer_stands_in_for_a_missed_errorpins the first two with their plain-account versions.Documented family: the tag errors stood in for one rledger already misses (change 2)
Where the header defect now replaces a directive's tag and link errors, a line whose extra tag errors made up for something rledger already misses counts what main counts for the same line with its tags and links removed (the tag-side counterpart of the family above). The round-1 review measured it at about 345 regressions per seed (348 of 1,901 on seed 7, 344 of 1,740 on seed 8), plus about 400 per seed moving further; on its generator change 2 overall gained about 28.7k and regressed about 490 per seed, and change 1 gained about 73k and regressed about 1.3k. Examples (bean-check / main / PR, and main with the tags and links removed), after the two
openlines:2024-01-02 event "a" "b" "s" T#! #t #u2024-01-02 balance Assets:A 1 USD { U?SD #t #u2024-01-02 price HOOL 1 USD USD U?SD #t^l2024-01-02 open Assets:C USD "FIFO" 2024-01-01 * ^l #t NULL2024-01-02 close Assets:A {#t #u2024-01-02 query "q" "select 1" {#t #uWhat rledger misses there: a mid-line
T#!andU?SD, each one invalid token in beancount; afterNULL, beancount's second grammar error (expecting ... TAG or LINK). The{#t #urows go the other way: rledger lexes{#and an invalid run where beancount reads{and a tag (the matrix'sbrace-hash-before-tag), so with the header check now running the line shows main's existing over-count for{#talone. Avoiding it means changing how{#lexes, which is left out of this PR.test_parse_tag_errors_no_longer_stand_in_for_a_missed_errorpins all six with their untagged versions (counts checked with bean-check).Parity corpus
79,549 of 111,323 matching on main (
48ddb343451) and on this branch: none gained, none lost. One fuzz input that mismatches on both moved one closer on one line.--checkpasses and the manifest is unchanged (the row-1 shapes the issue counted in the corpus mismatch for other reasons too).BOM combination matrix
tests/bom_combination_matrix.rs(13,438 rows) took the moved counts withBOM_MATRIX_UPDATE=1 BOM_MATRIX_RELABEL=1:T#!(causemid-line-hash-bang): the lone capital stays a token here, one error fewer than beancount, and main matched only by the BOM error. They, and 2 rows already in the known list that moved one further for the same reason, are in the known list with that reason (9 accepted lines).indented-line-after-errorand others, with the line's standalone count) instead oflike-main-without-bom; one new further-than-main line (2024-01-02 ! #t ^l open \tT#!\t(1 + 2) \t<BOM>Ü:A Assets:A, the sameT#!case) is accepted asmid-line-hash-bang.Heading<BOM>a-b:C~<BOM>1:A<BOM>a-b:C\t{counts 2 (bean-check 1, main 3): theP0026after the~error is dropped, and the unclosed-cost error is left; the construct rule needs main to count as rledger does, and main still counts the droppedP0026.Caches
CACHE_VERSION117 (v116 was taken by fix(parser): drop a sign check that ends at its line's first invalid token, as beancount does #2981): both payloads archive parse errors, which move.P0026is dropped only after another error on its line, a tag error is replaced only by another error), and directives do not change, so no load the loader caches (error-free ones) is affected.How to test
Each count in
bom_account_and_tag_recovery.rswas checked against bean-check 3.2.3; the tests also assert the green and red paths agree.Local runs: parser, loader, LSP and WASM cache tests pass, clippy
-D warnings,cargo fmt --checkandcargo docwith-Dwarningsare clean. Three tests fail locally on main too, from a stray/tmp/rec_before.beancountthe discovery walk finds above the temp dir: loaderdiscover::tests::a_non_utf8_file_is_not_a_candidateandskips_files_that_declare_no_include, and LSPmain_loop::tests::an_unrelated_root_is_probed_once_not_once_per_file.Not changed
close Assets:A #t #u: bean-check 1, main and this PR 2 (each tag gets its own error).close <BOM>Assets:Bon a line of its own: bean-check reads it as an account and reports nothing; rledger reports the BOM, as on main (compat(parser): an invalid run should swallow a following quote, #! or #+ mid-line, as beancount's lexer does #2928's design).Closes #2968
🤖 Generated with Claude Code