Repository navigation
fix(parser): report the metadata shapes beancount rejects - #2888
Merged
Merged
Conversation
Each row of #2813, checked against bean-check 3.2.3: - `True`, `true`, `False`, `false` were booleans. Beancount's lexer has only `TRUE` and `FALSE`; the others are `Invalid token`, now a parse error. - An account value with an invalid root (`kk: Foo:Bar`) was kept as an account. It is now E1005, checked with `validate_account_name` against the ledger's configured roots, on directive and posting metadata. - An indented line after `option`, `include`, `plugin`, `pushtag`, `poptag`, `pushmeta` or `popmeta` was absorbed and dropped. It is now an error at the first indented line of the block, as beancount's `unexpected INDENT` (an indented comment too). Not reported where the line or the directive's header already has a syntax error, which beancount's recovery swallows. One green-tree pass, with a counter test. - A posting's `filename:` / `lineno:` is an error at the transaction's line, as beancount's `Duplicate posting metadata field`. A directive's own are still accepted, as there. - `kk: 1 / 0` was already an error (beancount segfaults). - A division in an amount or value is `rustledger_core::py_div`, Python's: `10/4` is `2.5` (was `2.50`), an inexact quotient has 28 significant digits. Two parser-lima baseline rows (`(1 + 5) / 2.1` balances) move. The `render_commas: true` spelling in the format test is dropped: it is a parse error now, as in beancount. Loader CACHE_VERSION 60, WASM 77. Closes #2813 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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?
|
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
…low rule Review round 1 on #2813: - `true`, `false`, `True` and `False` in a value now read `invalid token 'true' (booleans are written TRUE or FALSE)` instead of a bare `unexpected input` (maintainer's decision: match beancount, with a kind error). CHANGELOG Breaking: `render_commas: true` (#1892) must now be written `TRUE`. - `previous_line_is_a_gap` and `report_no_metadata_continuations` share one keyword list (`NO_METADATA_DIRECTIVES`) and one predicate for a header error that swallows the next line (`swallows_the_next_line`): a syntax or lexer error does, a `poptag`/`popmeta` of nothing pushed does not. `poptag #zz` then ` 2024-02-30 open Assets:A` is three errors, as in bean-check (it was two); an invalid date on a `pushmeta` header now swallows the indented line, as there. A drift-guard test pins six shapes against bean-check 3.2.3. The indented-line report now runs after `report_invalid_dates`, so header date errors count. - CHANGELOG: the py_div change can flip balance tolerance in beancount's direction. - The unevaluable-expression messages name the underflow case; one parser-lima baseline row (ErrorInPosting) moves with the text. - `report_posting_filename_lineno` pushes the key directly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 7, 2026
Review round 2 on #2813: the boolean hint fired on account components and on words glued to punctuation or non-ASCII (`Assets:true`, `true.`, `True'`, `trueé`), where bean-check names the whole token. It now renames only a word bounded by a line start or whitespace before it and by whitespace, a line end, a comment's `;` or the end of the source after it, read over ASCII letters only. The letter cap is fixed so the word really spans at most one more than five letters. Negatives for each case are added to `test_parse_names_a_misspelled_boolean`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 7, 2026
#2888 took WASM cache v77 (loader v60). This branch's ParsedLedger payload change moves to v78, its note after #2888's; LOADER_CACHE_VERSION_PIN is 60, as main's loader cache is. 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
Each row of #2813 was checked against bean-check 3.2.3 before coding:
kk: True/true/False/falseInvalid token: 'True'TRUE/FALSEare booleans)kk: Foo:Bar(invalid root)Invalid account nameE1005kk: 1(or; c,#tag) afteroption,include,plugin,pushtag,poptag,pushmeta,popmetasyntax error, unexpected INDENTfilename:/lineno:Duplicate posting metadata field, at the transaction's linekk: 1 / 0kk: 10/42.502.52.5How each row is implemented:
True/true/False/falsetokens, so those spellings now lex like any other word, as an error. The spec grammar (spec/core/grammar.peg) already allowed onlyTRUE/FALSE.validators::helpers::push_invalid_meta_accountschecks every account-valued metadata entry with the canonicalvalidate_account_name, against the ledger's configuredaccount_types(sooption "name_assets"is honoured, and no root prefixes are string-matched). It runs on directive and posting metadata in the Late phase. The error is anchored at the directive, like the otherE1005s, so it is reported on the directive's line where bean-check names the metadata line.report_no_metadata_continuationsruns over the green tree only, so it costs no red nodes. It reports at most one error per indented block, because beancount's recovery swallows the rest of the block. Whitespace-only lines are skipped. It does not report when that line already has a syntax error of its own, or when the directive's header does, since beancount's recovery swallows the indented line in that case. Apoptagof an absent tag is not a syntax error, so the indented-line error is still reported after it, as in beancount.filename:/lineno::report_posting_filename_linenoruns only when the source containsfilename:orlineno:. A directive's ownfilename:/lineno:is still accepted, as in beancount.rustledger_core::py_div(Python's division) instead ofchecked_div. This applies to amounts as well as metadata values.10/4is2.5,10.00/4is2.50.6 / 2.1is2.857142857142857142857142857, one digit shorter than before.Decision notes
kk: 1 / 0needed no decision. It has been a parse error since fix(parser): report stray characters in metadata lines #2810 (the "invalid arithmetic expression ... division by zero" error), and beancount crashes on it.render_commas: true:format_render_commas_testaccepted a bare lowercasetrueon purpose (Is it intentional thatformatstrips thousands separators, even withoption "render_commas" "TRUE"? #1892, "all spellings a ledger author might write"). Beancount rejects that spelling, so it is now a parse error here and the spelling was dropped from the test.TRUEand"TRUE"still opt in.Why
Issue #2813. Each change matches beancount; no deviation is introduced.
How to test
Verification
poptagof an absent tag, a blank line, a tag line, and posting / transaction / directivefilename:andlineno:. The parse-error lines match for every probe, except thatE1005is placed on the directive's line.STRICT_BASELINE=1corpus and CST baselines pass.parser-lima/test-cases_Expressions.ExplicitPrecision{,2}.beancount. Their(1 + 5) / 2.1 USDbalance amounts now have Python's 28 significant digits. The source hashes are unchanged and the CST rows do not move. Only those rows were taken from a regenerated manifest.format_sourceand whole-file range formatting keepkk: True, the absorbedkk: 1, and the postingfilename:byte for byte.option(which bean-check rejects) is dedented to column 0, which makes that line valid. The CLI refuses to format a file with errors, so onlyformat_sourceand LSP range formatting do this.test_report_no_metadata_continuations_is_linear_in_the_inputcounts header tokens, checked line bytes and errors visited, over 20,000pushtag/poptagblocks among 20,000 other errors. It can fail: with a per-lineerrors.iter().any(..)restored, it counted 2,000,740,000 units on a 900,000-byte input and failed.cargo test --workspace --all-features --no-fail-fastpasses, apart from one failure ofplugin_conformance::python_plugins_back_to_back_after_a_timeout, a timing test that ran while the machine was loaded. It passed when run alone, twice.cargo clippy --all-features --all-targets -- -D warnings,RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-depsandcargo fmt --checkpass.CACHE_VERSION60 (withFIXTURE_VERSION), WASM 77 (withLOADER_CACHE_VERSION_PIN60).#2872 rows
This PR fixes one #2872 row: indented metadata (
mm: "x") afterpushmeta/pushtag, or an indented comment afteroption, is now an error, as bean-check'sunexpected INDENT.Follow-ups (not fixed here):
custom "a" Truegives 2 errors where bean-check gives 1. A capitalized word lexes as a one-letter currency plus an error token, asTruexalready did on main.Review round 1
true,false,TrueandFalsein a value now reportinvalid token 'true' (booleans are written TRUE or FALSE)instead of a bareunexpected input. This follows the maintainer's decision: match beancount, with a kind error.name_misspelled_booleansreads the word from the source around the error, at most five letters each way. The word matters becauseTruelexes as the currencyTplus an error tokenrue. Reading the whole word also keepsTruexfrom being taken for a boolean.render_commas: true(Is it intentional thatformatstrips thousands separators, even withoption "render_commas" "TRUE"? #1892) must now be writtenTRUE, as bean-check already requires.test_parse_names_a_misspelled_booleancovers each spelling in metadata, acustomvalue andpushmeta, plus theTruexnegative case.previous_line_is_a_gapandreport_no_metadata_continuationsnow share one keyword list (NO_METADATA_DIRECTIVES) and one predicate (swallows_the_next_line). The predicate decides whether a header error swallows the next line:poptag/popmetaof nothing pushed, or a push never popped, does not, because that is beancount's builder error and the parser carries on.poptag #zzthen2024-02-30 open Assets:Ais now 3 errors, as in bean-check (it was 2).pushmetaheader now swallows the indented line, as there. The indented-line report runs afterreport_invalid_dates, so header date errors count.test_parse_no_metadata_header_errors_swallow_the_next_line_as_beancountpins six shapes, each checked against bean-check 3.2.3.py_divchange can flip a balance check in beancount's direction:10/4 USDagainst-2.46 USDis now accepted, and10/3*3 USDagainst-10 USDnow reports its residual. Both cases were checked against bean-check and against main.an inexact quotient below 1e-28). The one parser-lima row whose error text moved,test-cases_SyntaxErrors.ErrorInPosting.beancount, is updated: same source hash, and its CST row does not move.report_posting_filename_linenopusheskeydirectly.keyword_nameis gone, replaced by the shared table.Verification for this round:
STRICT_BASELINE=1corpus and CST baselines pass.-D warnings, rustdoc-Dwarningsandcargo fmt --checkare clean.Review round 2
The boolean hint now fires only on a word that stands alone as a value. The word is read over ASCII letters. It needs a line start or whitespace before it, and whitespace, a line end, a comment's
;or the end of the source after it.Assets:true,true.,True',trueéand😀truekeep the generic message, because bean-check names the whole token there. The letter cap is fixed, so the word spans at most one letter more than the five offalse. The negatives (alsoxfalse,falsee, andopen Assets:true) and the positives (at the end of the source, before;) are intest_parse_names_a_misspelled_boolean. Parser tests,STRICT_BASELINE=1corpus and CST baselines, clippy andcargo fmt --checkpass.Closes #2813
🤖 Generated with Claude Code