yeast: Support optional guards in rules - #22436
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds optional Rust-expression guards to Yeast rules, evaluated before capture translation.
Changes:
- Adds runtime guard evaluation and context handling.
- Extends macros with guard parsing and raw capture bindings.
- Adds documentation and tests for guarded rules.
Show a summary per file
| File | Description |
|---|---|
shared/yeast/src/lib.rs |
Adds guard runtime support. |
shared/yeast-macros/src/parse.rs |
Parses and generates guarded rules. |
shared/yeast-macros/src/lib.rs |
Documents macro guard syntax. |
shared/yeast/doc/yeast.md |
Documents guard behavior. |
shared/yeast/tests/test.rs |
Tests guards, captures, context, and macros. |
Review details
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 5/5 changed files
- Comments generated: 2
- Review effort level: Balanced
tausbn
force-pushed
the
tausbn/yeast-support-optional-guards-in-rules
branch
from
August 27, 2026 10:57
faae557 to
edb349f
Compare
tausbn
marked this pull request as ready for review
August 27, 2026 11:02
Permits the use of guards of the form `where expr` (with `expr` being any Rust expression that evaluates to a boolean) inside of rules. The guard should come after the query itself, and before the `=>` that separates the query from the body, like so: ``` (foo bar: _? @bar) where bar.is_some() => (baz bar: {bar}) ``` If the guard is absent, it behaves as if it were `where true`. Inside of the guard body, all captures are treated as if they are raw. Translation of non-raw captures only happens if the guard succeeds. The guard can also access the user-defined context. This context is shared with the body if the guard succeeds, and discarded if the guard fails (just as it is currently discarded after running a rule body). (I think it's unlikely that we'll ever want to mutate the context from inside the guard, but you never know...)
tausbn
force-pushed
the
tausbn/yeast-support-optional-guards-in-rules
branch
from
August 27, 2026 11:20
edb349f to
3e88b36
Compare
asgerf
approved these changes
Aug 27, 2026
asgerf
left a comment
Contributor
There was a problem hiding this comment.
LGTM.
The code was too dense for me to have much confidence in my own ability to notice any issues with it. But I've played around with it for a while today and so far it seems to work perfectly.
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.
Permits the use of guards of the form
where expr(withexprbeing any Rust expression that evaluates to a boolean value) inside of rules. The guard should come after the query itself, and before the=>that separates the query from the body, like so:If the guard is absent, it behaves as if it were
where true. Inside of the guard body, all captures are treated as if they are raw. Translation of non-raw captures only happens if the guard succeeds.The guard can also access the user-defined context. This context is shared with the body if the guard succeeds, and discarded if the guard fails (just as it is currently discarded after running a rule body). (I think it's unlikely that we'll ever want to mutate the context from inside the guard, but you never know...)
(NB: In a previous version, I used
ifinstead ofwherebut I think I like the latter better. It's a bit more prominent, and it's less likely to overlap with actual language keywords. I'll happily change it again, though.)