Skip to content

yeast: Support optional guards in rules - #22436

Merged
tausbn merged 1 commit into
mainfrom
tausbn/yeast-support-optional-guards-in-rules
Aug 27, 2026
Merged

yeast: Support optional guards in rules#22436
tausbn merged 1 commit into
mainfrom
tausbn/yeast-support-optional-guards-in-rules

Conversation

@tausbn

@tausbntausbn commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Permits the use of guards of the form where expr (with expr being 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:

(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...)

(NB: In a previous version, I used if instead of where but 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.)

CopilotAI 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.

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
FileDescription
shared/yeast/src/lib.rsAdds guard runtime support.
shared/yeast-macros/src/parse.rsParses and generates guarded rules.
shared/yeast-macros/src/lib.rsDocuments macro guard syntax.
shared/yeast/doc/yeast.mdDocuments guard behavior.
shared/yeast/tests/test.rsTests 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

Comment threadshared/yeast/src/lib.rs Outdated
Comment threadshared/yeast/src/lib.rs Outdated
@tausbn
tausbnforce-pushed the tausbn/yeast-support-optional-guards-in-rules branch from faae557 to edb349fCompareAugust 27, 2026 10:57
@tausbn
tausbn marked this pull request as ready for review August 27, 2026 11:02
@tausbn
tausbn requested a review from a team as a code ownerAugust 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
tausbnforce-pushed the tausbn/yeast-support-optional-guards-in-rules branch from edb349f to 3e88b36CompareAugust 27, 2026 11:20

@asgerfasgerf 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.

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.

@tausbn
tausbn merged commit a035968 into mainAug 27, 2026
85 checks passed
@tausbn
tausbn deleted the tausbn/yeast-support-optional-guards-in-rules branch August 27, 2026 14:08
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@tausbn@asgerf