Repository navigation
Conversation
Pass the generated or caller-spanned `ctx` identifier through every template lowering path instead of falling back to an implicitly constructed identifier. This is needed primarily due to macro hygiene. Eventually we will be introducing macros that define macros, and here it's problematic that we rely on an implicit `ctx` variable to be present. So instead, we pass a suitable `ctx` identifier through the entire lowering, and interpolate that (using `#ctx`) instead.
Add hidden `tree!` and `trees!` variants that inject a schema dependency and preserve access to the caller's `ctx` binding. Essentially, these inner variants (`tree_with_schema!` etc.) will be used internally with an interpolated reference to the output schema. Thus, when we write `tree!(...)` this turns into `tree_with_schema(SCHEMA, ...)`, which enables that local macro call to (eventually) check the tree template against that schema.
Adds a new macro, `tree_schema!` which takes two arguments: an identifier and the name of an output schema. When the macro is executed, it then creates a local module with the same name as the specified identifier, which exports `tree` and `trees` macros and also the schema. These can then be imported in order to get access to these macros.
Declare the shared AST schema once and import its `tree!` wrapper for Swift lowering helpers and rule bodies.
I think in general we'll be happier if all uses of `tree!`/`trees!` have an (implicitly) associated schema. Thus, we don't need the generic schema-less versions anymore.
Provide `tree_with_context!` and `trees_with_context!` for macro-generated templates whose forwarded tokens cannot reliably identify the local `ctx` binding. This is essentially only needed if you're doing really peculiar stuff with macros, but Copilot insisted, and it seemed harmless to add this.
tausbn
force-pushed
the
tausbn/yeast-tree-schema
branch
from
November 12, 2026 16:56
c5e1a5c to
a9329b0
Compare
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Both builders skip interpolation isolation when the explicit context is not named ctx, allowing mutations to leak into subsequent interpolations.
1 open issue
What changed in this PR
This PR associates YEAST tree builders with output schemas through generated namespaces, preparing for future template validation without repeating schema paths at each call.
Changes:
- Adds
tree_schema!namespaces exposing schema contents and tree-building macros. - Adds explicit-context builders and threads the selected context through template lowering.
- Migrates Swift and test usage, with documentation and namespace/forwarding tests. Schema validation remains deferred.
| File | Description |
|---|---|
unified/extractor/src/languages/swift/swift.rs |
Uses a schema-bound Swift tree builder. |
shared/yeast/tests/test.rs |
Migrates builders and tests namespaces and forwarded templates. |
shared/yeast/src/lib.rs |
Exports the namespace macro and hidden builder entry points. |
shared/yeast/doc/yeast.md |
Documents schema namespaces and explicit-context usage. |
shared/yeast-macros/src/parse.rs |
Generates namespaces and parses schema paths and contexts. |
shared/yeast-macros/src/lower.rs |
Threads context identifiers through template lowering. |
shared/yeast-macros/src/lib.rs |
Defines schema-aware procedural macro entry points. |
Review effort: Balanced (auto)
This branch has not been deployed
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.

We want to be able to check
tree!templates against the given output schema, but having to specify the schema path directly in each call would get old fast.So, instead we add a macro,
tree_schema!that creates a local module (with a user-specified name) that exposes thetree!macro in such a way that the schema is baked into uses of that macro automatically.Essentially, the outer
tree!(...)expands intowhich means each invocations now knows exactly what schema applies to the tree template. Note that we do not currently perform any checks -- that will come in a future PR.
Can be reviewed commit-by-commit.