Skip to content

yeast: Emit tokens for leaf nodes on AST - #22945

Open
tausbn wants to merge 8 commits into
mainfrom
tausbn/yeast-emit-tokens-for-leaf-nodes-on-ast
Open

tausbn wants to merge 8 commits into
mainfrom
tausbn/yeast-emit-tokens-for-leaf-nodes-on-ast

Conversation

@tausbn

@tausbn tausbn commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

For rules where we're matching some node, and mapping it to some leaf node in the output schema (e.g. mapping (superExpr) to (super_expr) in Swift), we would previously produce a content-less node by default.

With the changes in this PR, we now detect the case where the right hand side of a rule is a bare leaf node (no fields, no explicit content). In this case, we give it a new kind of content, Inherited, which results in it being assigned the source range of whatever was matched as its content.


Should be reviewed commit-by-commit. As an experiment, I tried making the commits very small this time around (though one of them still ended up with the bulk of the changes). Do let me know if this made it harder or easier to review.

This gives us access to the input/output schemas during macro expansion,
which we'll need in order to know whether an output node is a leaf node
or not.

We could in principle get rid of all of the inner `rule!` applications
now and just inline them directly, but to prevent churn I have opted not
to do so at this time.
@tausbn tausbn added the no-change-note-required This PR does not need a change note label Oct 29, 2026
@tausbn
tausbn requested a max review from Copilot October 29, 2026 22:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The missing yeast-schema Bazel dependency blocks builds, and changed Swift token text leaves existing test expectations and annotations out of sync.

5 open issues
What changed in this PR

This PR lets YEAST’s schema-aware rewrite rules give bare output leaf nodes the matched input’s content instead of defaulting to empty token values.

Changes:

  • Track schema leaf kinds, resolve inherited content, and reject ambiguous nested bare leaves.
  • Build inherited tokens from stored content or source text.
  • Adopt schema-aware rules in Swift and add schema and runtime regression tests.
File Description
unified/​extractor/​src/​languages/​swift/​swift.rs Adopt rules! and simplify the super_expr translation.
shared/​yeast/​tests/​test.rs Test inheritance from parsed, synthetic, and empty content.
shared/​yeast/​src/​lib.rs Expose the matched root to token construction.
shared/​yeast/​src/​build.rs Construct tokens with inherited content.
shared/​yeast-schema/​src/​schema.rs Track and expose leaf-kind metadata.
shared/​yeast-schema/​src/​node_types_yaml.rs Populate and test leaf-kind metadata from YAML.
shared/​yeast-macros/​src/​parse.rs Load output schemas and resolve schema-aware rule items.
shared/​yeast-macros/​src/​lower.rs Emit inherited-token builder calls.
shared/​yeast-macros/​src/​lib.rs Document bare-leaf inheritance and nesting restrictions.
shared/​yeast-macros/​src/​ast.rs Resolve bare leaf templates and test validation.
shared/​yeast-macros/​Cargo.toml Add the schema dependency.
Cargo.lock Record the new dependency relationship.

Review effort: Max

Comment thread shared/yeast-macros/Cargo.toml Resolved
Comment thread shared/yeast-macros/src/parse.rs Resolved
Comment thread shared/yeast-schema/src/schema.rs Resolved
Comment thread shared/yeast/tests/test.rs Resolved
The `rules!` macro needs this information to decide whether a bare
output node should inherit the value of the matched input node.
The `rules!` macro needs to inspect every rule before expansion so it
can apply schema-aware transformations consistently.

When we encounter an embedded `rule!` macro inside of `rules!`, we now
unwrap it and lower it as if it were an inline rule.
A bare leaf used as a rule result has an obvious value: the value of the
node matched by the rule. Using the output schema we can now distinguish
leaves from fieldless structural nodes and mark top-level bare leaves as
inherited content.

For nested bare leaves, there's no obvious input node from which to
inherit their value, so these still need to be handled explicitly.
The `rules!` macro now reads output schemas during expansion, so the
proc-macro target needs `yeast-schema` under Bazel as well as Cargo.
Bare leaf rule results now inherit the matched source text. Existing
unsupported Swift nodes previously had empty content, so this changed
the control-flow test output even though their AST structure was
unchanged.

To fix this, we now give `unsupported_node` results explicit empty
content, leaving `super_expr` as the intentional inherited leaf and
preserving existing extraction behaviour.
@tausbn
tausbn force-pushed the tausbn/yeast-emit-tokens-for-leaf-nodes-on-ast branch from 3c8be31 to 6f93249 Compare October 29, 2026 23:01
@tausbn
tausbn requested a max review from Copilot October 29, 2026 23:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved content-inheritance bugs leave childless structural nodes with empty values despite available source text and give Swift labeled function-reference unsupported nodes unintended nonempty values.

2 open issues
5 resolved since last review

Review effort: Max

Comment thread shared/yeast/src/build.rs Resolved
Comment thread shared/yeast-macros/src/lib.rs Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Macro lowering drops explicit rule attributes, making gated rules unconditional, while a missed Swift rule changes unsupported-node values from empty strings to source text.

1 open issue
2 resolved since last review

Review effort: Max

Comment thread shared/yeast-macros/src/parse.rs Resolved
@tausbn
tausbn marked this pull request as ready for review October 30, 2026 12:45
@tausbn
tausbn requested review from a team as code owners October 30, 2026 12:45

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-change-note-required This PR does not need a change note Unified

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants