Repository navigation
fix(parser): a link is not a valid metadata value - #1957
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aligns rustledger-parser’s CST conversion with beancount’s grammar by rejecting ^link tokens when they appear as metadata values inside META_ENTRY nodes (while still accepting #tag values and still allowing transaction-level links). It also bumps loader/wasm cache versions and updates the parser corpus baseline to reflect the new diagnostic.
Changes:
- Add a guarded CST tree scan that emits a syntax error when a
LINKtoken appears inside aMETA_ENTRY(link-valued metadata). - Add integration tests covering the intended tag/link asymmetry and green/red parity.
- Update corpus baselines and bump loader/wasm cache versions to avoid stale “previously clean” parses.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/baselines/parser-corpus.manifest | Updates baseline hash for examples_data_full.beancount due to the new parser diagnostic. |
| crates/rustledger-wasm/src/cache.rs | Bumps WASM cache version to v8 to invalidate cached parses affected by the new syntax error. |
| crates/rustledger-parser/tests/parser_integration_test.rs | Adds regression tests asserting link-valued metadata is rejected while tag-valued metadata remains accepted, plus green/red parity checks. |
| crates/rustledger-parser/src/cst/convert.rs | Implements the META_ENTRY scan that flags LINK tokens as invalid metadata values (guarded by contains('^')). |
| crates/rustledger-loader/src/cache.rs | Bumps loader cache version to v22 and updates fixture version assertions accordingly. |
Suppressed comments (1)
crates/rustledger-parser/src/cst/convert.rs:2493
- After inserting
extract_link_metadata_value_errorsabove this helper,extract_unclosed_cost_brace_errorsno longer has its own rustdoc. Re-add theCOST_SPECdocumentation directly above this function so it remains discoverable and attached to the correct item.
}
out
}
fn extract_unclosed_cost_brace_errors(
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
`ref: ^inv-1` parsed here and is a syntax error in beancount - its grammar has no production for a link in value position at all. A `#tag` in the same place IS valid there, and we already agreed on that. THE ASYMMETRY IS THE WHOLE POINT Tags and links lex as sibling kinds and are handled as a pair almost everywhere in this file, so rejecting both is the natural reach and the wrong answer - it would break input beancount accepts. Same mistake #1953 avoided in the mirror-image case, where `note` and `document` legitimately take both. SCOPE `META_ENTRY` nodes only. A link on a TRANSACTION is a direct child of the transaction, not of a metadata entry, so it is untouched - that being the one place links belong. NOT extended to `custom` / `pushmeta`, which run through `value_tokens_to_meta` rather than this path. beancount rejects BOTH a tag and a link there, so it is a different rule needing its own evidence. Measured but deliberately left: filing separately rather than folding a second rule into this change. The scan lives in `parse_via_cst_inner`, which both the green and red paths share, so there is no dual-path divergence to mirror. Guarded by `stripped.contains('^')`, the same trick the adjacent unclosed-cost-brace scan uses: no caret in the source means no LINK token can exist. THE FIRST VERSION OF THE TEST WAS VACUOUS Sabotaging the scan to reject TAG as well still passed. The reason is that guard: the tag fixture contained no `^`, so the scan never ran, and the "a tag must still be accepted" assertion said nothing about the scan's contents. The accept case now uses a file that DOES contain a link elsewhere, so the scan runs and the tag has to survive it. Both sabotages are caught now - disabling the scan, and widening it to tags. CORPUS One baseline drifted: `parser-lima/examples_data_full.beancount`, which carries `key-for-link: ^mylink` at line 84. beancount reports exactly one "unexpected LINK" error on that file and so do we now. Updated surgically. Caches: loader 21 -> 22, wasm 7 -> 8. Closes #1954.
…s function Two fixes, both mine. The new scan was inserted directly above , which put it BETWEEN that function and its doc comment: the cost-spec rustdoc then documented the link scan, and the cost-spec helper had none. Anchoring an insertion on a line orphans whatever rustdoc sits above it, and nothing in the build or tests notices. And resolving the rebase conflict in the test file, I cut through the middle of the #1955 test and dropped its closing brace - the conflict boundary sat inside the function, not between the two. Caught by clippy reporting an unclosed delimiter, not by me reading the merge. Both tests are present and the file has 63 passing again.
8daa573 to
8f814c4
Compare
📊 Benchmark Results
vs main branch (2026-08-04)
What do these numbers mean?
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
Suppressed comments (2)
crates/rustledger-loader/src/cache.rs:407
- PR description says the cache bumps are loader 21→22 and wasm 7→8, but this diff bumps loader to v23 and wasm to v9. Please update the PR description so reviewers/users don’t take the wrong cache version numbers away from this change.
/// v23: a `^link` is no longer accepted as a metadata VALUE (#1954), so a
/// file using `ref: ^x` moves from clean to erroring. A stale cache would
/// serve the old clean parse.
const CACHE_VERSION: u32 = 23;
crates/rustledger-parser/src/cst/convert.rs:155
stripped.contains('^')will be true for any file that contains transaction links (a common shape), which means we now do an additional full-treesyntax().descendants()scan that allocates red nodes even when there are no metadata entries with link values. This could be a noticeable parse-time regression on large ledgers that use links heavily. Consider folding the check into an existing traversal (e.g., the fused descendant/top-level walks or metadata-entry conversion) so link-in-metadata is detected without a second full-tree walk.
// Same guard trick as above: no '^' in the source means no LINK token can
// exist, so the whole-tree scan is skipped on the common case.
if stripped.contains('^') {
errors.extend(extract_link_metadata_value_errors(&source_file, bom_offset));
}
|
| Metric | Result |
|---|---|
| Check Compatibility | 100% |
| BQL Compatibility | 95% (raw 89%, 162 masked) |
| Full AST Match | 100% |
| Total Files | 812 |
What's tested
- Check: Exit codes and error counts match
bean-check - BQL: Query results match
bean-query
The headline is the EFFECTIVE rate, after pairs where beanquery
itself is wrong are masked. raw is the same run with nothing
masked. A widening gap means the registry grew, not that rledger
changed. - Files: ~800 test files downloaded from 10+ beancount repositories
Full results available in workflow artifacts
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
ref: ^inv-1parsed here and is a syntax error in beancount — its grammar has no production for a link in value position at all. A#tagin the same place is valid there, and we already agreed on that.The asymmetry is the whole point
Tags and links lex as sibling kinds and are handled as a pair almost everywhere in this file, so rejecting both is the natural reach and the wrong answer — it would break input beancount accepts. Same mistake #1953 avoided in the mirror-image case, where
noteanddocumentlegitimately take both.Scope
META_ENTRYnodes only. A link on a transaction is a direct child of the transaction, not of a metadata entry, so it's untouched — that being the one place links belong.Not extended to
custom/pushmeta, which run throughvalue_tokens_to_metarather than this path. beancount rejects both a tag and a link there, so it's a different rule needing its own evidence. Measured but deliberately left for a separate change rather than folding a second rule in here.The scan lives in
parse_via_cst_inner, which the green and red paths share, so there's no dual-path divergence to mirror. Guarded bystripped.contains('^'), the same trick the adjacent unclosed-cost-brace scan uses.The first version of the test was vacuous
Sabotaging the scan to reject TAG as well still passed. The cause was that guard: the tag fixture contained no
^, so the scan never ran, and "a tag must still be accepted" said nothing about the scan's contents.The accept case now uses a file that does contain a link elsewhere, so the scan runs and the tag has to survive it. Both sabotages are caught now:
Corpus
One baseline drifted:
parser-lima/examples_data_full.beancount, which carrieskey-for-link: ^mylinkat line 84. beancount reports exactly one "unexpected LINK" error on that file, and so do we now. Updated surgically.Caches: loader 21 → 22, wasm 7 → 8.
Verification
cargo fmt --checkcleanCloses #1954.