Repository navigation
Conversation
Getting these out of the way so they don't take up space in later commits.
Make query matching and capture storage generic over `TreeId` so the same runtime can match both input and output ASTs.
Capture bindings created with call-site hygiene are invisible through generated `macro_rules!` wrappers. Preserve each capture's pattern span and allow unused bindings now that they belong to user code. (If the above is unclear, don't worry about it. It's just something we need to do to get the macros to behave.)
We parse these in much the same way as top-level rules (and reuse some of the machinery), the only difference being that the right hand side of a match arm must be a Rust block -- it can't be a directly embedded tree.
Try arms in order against the AST selected by the node ID type. Guards and bodies receive independent raw captures, while bodies remain inline so `return` and `continue` affect their enclosing scope. Keep the selected `BuildCtx` separate from guard-local `ctx` and `ast` bindings so explicit context identifiers cannot redirect or shadow guard access.
This is an "internal" variant of `query_match!` that expects to receive (a path to) the relevant schema as an argument. This will almost never be used directly -- rather, the `query_match_schema!` macro we define later will take care of defining a local `query_match!` macro that bakes in this schema path. That way, each invocation of the macro knows what schema to (eventually -- not in this PR) check validity against.
This is the macro that was mentioned in the previous commit. Like `tree_schema!`, it creates a local module that exposes its own `query_match!` macro with the given schema path baked in.
Adds a bunch of tests covering required, optional, and repeated raw captures, ordered arm selection, catch-all handling, guard bindings, and guard fallthrough.
Verify that matcher bodies preserve enclosing `return` and `continue`, and that unmatched nodes report their kind and source location.
Having previously made the query matching mechanism agnostic in whether it's running on the input or output AST, the only thing we need to do to add support for output matching is to tell Rust where the AST lives (in the `output` field, as opposed to the `ast` field).
File this one under "things we'll almost certainly never need, but Copilot complained about it". Essentially, if we ever end up writing a macro that needs to mess with the context, then the previous macros won't do, due to `macro_rules!`'s enforcement of hygiene. So, we add `query_match_with_context!` that takes the context as an explicit argument, for the rare case where this is needed.
Document schema namespaces, ordered arms, raw captures, guards, output matching, and explicit contexts.
By using `query_match!` we avoid having to inspect the node structure directly (which is a bit awkward in plain Rust).
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Generated temporaries can shadow caller context bindings and capture storage, causing compilation failures and broken capture extraction.
1 open issue
What changed in this PR
Adds schema-scoped query_match! macros to YEAST for imperative matching against input and output ASTs, and adopts output matching in the Swift extractor.
Changes:
- Adds ordered query arms, optional guards, raw captures, and explicit-context matching.
- Generalizes query matching and capture storage to support output node IDs.
- Documents the API and adds tests for matching behavior, context handling, and output borrowing.
| File | Description |
|---|---|
unified/extractor/src/languages/swift/swift.rs |
Uses output queries to detect explicit constructors. |
shared/yeast/tests/test.rs |
Adds matcher behavior and context-handling tests. |
shared/yeast/src/query.rs |
Supports querying input and output ASTs. |
shared/yeast/src/lib.rs |
Exports the new matcher macros. |
shared/yeast/src/captures.rs |
Generalizes capture storage over node ID types. |
shared/yeast/doc/yeast.md |
Documents matcher namespaces, guards, and contexts. |
shared/yeast-macros/src/rule_parse.rs |
Makes guard parsing reusable. |
shared/yeast-macros/src/parse.rs |
Parses matcher arms and generates schema namespaces. |
shared/yeast-macros/src/lower.rs |
Generates matching, capture bindings, and fallback behavior. |
shared/yeast-macros/src/lib.rs |
Adds procedural macro entry points. |
shared/yeast-macros/src/ast.rs |
Defines matcher and arm representations. |
Review effort: Balanced (adaptive)
tausbn
marked this pull request as ready for review
November 24, 2026 15:35
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.

This macro can be thought of as a "local" variation of the
rules!macro. It uses essentially the same syntax, and allows picking a match arm based on whether a query matches or not. Queries can use all of the existing machinery, with a few crucial differences:@@. This is because aquery_match!may be done outside of a translation context, so there's not necessarily a sensible notion of "eager translation".tree!macro instead.)If no query matches, the entire match panics. Use a wildcard match like
_ => { None }or similar if this behaviour is undesirable.We also introduce a
query_match_schema!macro for setting up thequery_match!macro in a local module, just as we did previously withtree_schema!. Eventually, this will allow us to check the queries against the schema. Another benefit of this is that we can instantiate the schema separately for the input and output ASTs, and thus run queries against the output AST.Should be reviewed commit-by-commit.