Repository navigation
feat(parser): #1262 phase 2.2a META_ENTRY sub-node wraps indented metadata sub-lines - #1275
Merged
Merged
Conversation
…adata sub-lines Phase 2.2 of #1262 is split into smaller PRs by sub-structure type (following the PR 2.1a/2.1b precedent for reviewable scope). This is PR 2.2a — META_ENTRY wrapping; PR 2.2b will add POSTING; PR 2.2c will add AMOUNT / COST_SPEC / PRICE_ANNOTATION. ## What this PR ships - `META_ENTRY` SyntaxKind variant added. - New `emit_body_sub_line` helper called from both `emit_directive_body` and `emit_transaction_body`. When an indented sub-line is `WS META_KEY ...`, it gets wrapped in a META_ENTRY node; otherwise (indented `;`-comments and any future POSTING line) it flows through as flat children of the parent directive — consistent with both the trivia.rs spec's "metadata block" terminology and PR 2.2b's planned POSTING wrapping. - `is_indented_meta_sub_line` predicate centralizes the `WS + META_KEY` recognition. - Parser module rustdoc updated: phase 2.2a now lands META_ENTRY; phase 2.2b/c are flagged for POSTING / AMOUNT / COST_SPEC. - 5 new source-driven tests: - `meta_entry_wraps_metadata_sub_line_inside_open_directive` - `meta_entry_wraps_each_of_multiple_metadata_sub_lines` - `meta_entry_does_not_wrap_indented_comments` - `meta_entry_inside_transaction_body` - `meta_entry_with_value_kinds_other_than_string` - `commodity_with_metadata_wraps_full_multi_line_directive` updated to assert the new META_ENTRY shape (the structural diff this PR introduces). - Closed-form partition test + `nodes_are_not_tokens` test include META_ENTRY. ## What this PR does NOT add - POSTING wrapping (PR 2.2b) - AMOUNT / COST_SPEC / PRICE_ANNOTATION wrapping (PR 2.2c) - Typed-AST `Posting`/`MetaEntry` accessors (phase 3) - The "structural trailing-comment slot" pattern flagged in phase 2.0's rustdoc (polarmutex prior art) — still a phase 2.1 grammar option that hasn't been picked up; PR 2.2a is purely the wrapper around the existing flat metadata content. ## Why a separate META_ENTRY PR - Mechanically uniform across every directive kind that takes metadata; the change is concentrated to one new helper + predicate. - Drives node_shape baseline churn in a controlled way: every corpus file containing indented metadata sees its node_shape hash change, but token_seq stays byte-identical (no token classification change). - PR 2.2b (POSTING) and PR 2.2c (AMOUNT/COST_SPEC) build on top — POSTING's body parser will reuse `emit_body_sub_line`'s per-line dispatch shape. ## Verified - 56 structured-directive tests (was 51) + 171 unit + 4+1+1+55+2 doctest pass. - cargo check workspace, clippy -D warnings, fmt check, deny check bans, RUSTDOCFLAGS=-Dwarnings cargo doc — all clean. - STRICT_BASELINE=1 cargo test ... cst_baseline passes against the regenerated 804-file manifest. token_seq column unchanged vs main wherever source unchanged (phase-2 contract held); node_shape column churns on every corpus file that contains indented metadata. Refs #1262. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR advances the CST “structured parse” migration (tracking #1262) by introducing a dedicated META_ENTRY node that wraps indented metadata sub-lines (WS META_KEY ...) inside both dated directives and transaction bodies, while keeping other indented sub-lines (e.g., indented comments, future postings) as flat children of the parent node.
Changes:
- Added
SyntaxKind::META_ENTRYand updated SyntaxKind node-kind tests accordingly. - Introduced
emit_body_sub_line+is_indented_meta_sub_linein the CST parser and used it from both directive-body and transaction-body emission paths to wrap metadata lines. - Added/updated structured-parser tests to pin the new
META_ENTRYnode shape and ensure indented comments are not wrapped.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| crates/rustledger-parser/src/cst/parser.rs | Adds helper + predicate to wrap indented metadata sub-lines into META_ENTRY during structured CST emission. |
| crates/rustledger-parser/src/cst/syntax_kind.rs | Introduces the META_ENTRY node kind and updates node/token classification tests. |
| crates/rustledger-parser/tests/structured_directives.rs | Adds tests asserting META_ENTRY wrapping behavior across directives and transactions; updates an existing commodity+metadata shape test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
📊 Benchmark Results
vs main branch (2026-06-06)
What do these numbers mean?
|
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
…b-line predicate Round-1 review surfaced 2 low-severity findings: 1. Predicate-pair drift hazard: is_indented_meta_sub_line and the META_KEY arm of is_indented_directive_continuation independently encoded the same WS+META_KEY shape. A future PR widening one without the other could leave the directive body consuming sub-lines that arent wrapped, or wrapping sub-lines the body loop doesnt reach — no compile-time signal. Renamed is_indented_meta_sub_line to starts_meta_sub_line and routed is_indented_directive_continuations META_KEY arm through it. Single source of truth for the WS+META_KEY pattern. 2. PR 2.2b will need to relocate posting-attached metadata from TRANSACTIONs direct children to POSTINGs children. Added a forward-looking rustdoc note on emit_transaction_body explicitly calling this out so the future PR author knows that 2.2as meta_entry_inside_transaction_body assertion (counting direct children of TRANSACTION) is intentional for 2.2a but will need updating when 2.2b lands. No behavior change. 56 structured-directive tests + 171 unit + 4+1+1+55+2 doctest pass. Clippy, fmt, doc, deny check, strict baseline all clean. Refs #1262. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…rminated EOF case Copilot inline review flagged 3 places where the rustdoc claims META_ENTRY contains a terminator NEWLINE, but per rule 5 of cst::trivia (and emit_through_terminators NEWLINE-or-EOF stop condition), an unterminated final metadata sub-line at EOF still gets wrapped — its META_ENTRY just has no NEWLINE child. All three docs updated: - cst/parser.rs module rustdoc: WS META_KEY ... (NEWLINE OR EOF) - emit_body_sub_line rustdoc: explicit note about the unterminated final sub-line case - META_ENTRY SyntaxKind variant comment: same explicit note Added meta_entry_at_eof_without_trailing_newline test that asserts the META_ENTRY's exact element sequence is WHITESPACE META_KEY WHITESPACE STRING with no NEWLINE for the source `2024-01-01 open Assets:Cash\n key: "v"` — pinning the rustdoc claim with a concrete shape assertion. 57 tests (was 56) + 171 unit + 4+1+1+55+2 doctest pass. Clippy, fmt, doc all clean. Refs #1262. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…2.2b relocates Round-2 deep-review finding: the forward-looking rustdoc on `emit_transaction_body` miscited `meta_entry_inside_transaction_body` as a test that PR 2.2b will need to update. That test's metadata is 2-space-indented BEFORE postings (transaction-level), which stays at TRANSACTION level even after PR 2.2b. Only deeper-indented metadata FOLLOWING a posting gets relocated to the posting. Rewrote the rustdoc to explicitly distinguish: - TRANSACTION-level metadata (standard indent, before or between postings at that same depth) stays a direct child of TRANSACTION - POSTING-attached metadata (deeper indent following a posting) must be relocated by PR 2.2b No existing PR 2.2a test pins the posting-attached shape; PR 2.2b should add such tests alongside the relocation logic. Refs #1262. Co-Authored-By: Claude Opus 4.7 (1M context) <[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.
Summary
Phase 2.2 of #1262 split into smaller PRs by sub-structure type (following the PR 2.1a/2.1b precedent):
META_ENTRYwrapping for indentedWS META_KEY ... NEWLINEsub-linesPOSTINGwrapping forWS ACCOUNT ...lines inside transactionsAMOUNT/COST_SPEC/PRICE_ANNOTATIONinsidePOSTINGWhat this PR ships
META_ENTRYSyntaxKind variant added.emit_body_sub_linehelper called from bothemit_directive_bodyandemit_transaction_body. When an indented sub-line isWS META_KEY ..., it gets wrapped in aMETA_ENTRYnode; otherwise (indented;-comments, and any future POSTING line) it flows through as flat children of the parent directive.is_indented_meta_sub_linepredicate centralizes theWS + META_KEYrecognition (mirrors the existingis_indented_directive_continuation/is_indented_transaction_body_linepredicates).META_ENTRY; phase 2.2b/c flagged forPOSTING/AMOUNT/COST_SPEC.Tests
5 new tests pinning the
META_ENTRYshape + 1 updated test:meta_entry_wraps_metadata_sub_line_inside_open_directiveMETA_ENTRYshape onOPEN_DIRECTIVEmeta_entry_wraps_each_of_multiple_metadata_sub_linesMETA_ENTRYperMETA_KEYline; exact internal token sequencemeta_entry_does_not_wrap_indented_comments;-comments stay flat betweenMETA_ENTRYsiblings, not absorbedmeta_entry_inside_transaction_bodyMETA_ENTRYworks the same insideTRANSACTIONas inside dated directivesmeta_entry_with_value_kinds_other_than_stringMETA_ENTRYwraps regardless of value kind (NUMBER, DATE, ACCOUNT, ...)commodity_with_metadata_wraps_full_multi_line_directive(updated)What this PR does NOT add
POSTINGwrapping — PR 2.2bAMOUNT/COST_SPEC/PRICE_ANNOTATIONwrapping — PR 2.2cPosting/MetaEntryaccessors — phase 3Why a separate
META_ENTRYPRnode_shapebaseline churn in a controlled, single-purpose waytoken_seqstays byte-identical (no token classification change) — phase-2 contract heldPOSTING) and PR 2.2c (AMOUNT/COST_SPEC) build on top: POSTING's per-line dispatch reusesemit_body_sub_line's shapeVerified
cargo check --workspace --all-features --all-targetsclean.cargo clippy -p rustledger-parser --all-features --examples --tests -- -D warningsclean.cargo fmt --all --checkclean.cargo deny check bansclean.RUSTDOCFLAGS=-Dwarnings cargo doc -p rustledger-parser --no-depsclean.STRICT_BASELINE=1 cargo test -p rustledger-parser --test cst_baselinepasses against the regenerated 804-file manifest.Refs #1262.
🤖 Generated with Claude Code