Skip to content

Commit d11b428

Browse files
asgerfCopilot
andcommitted
yeast-macros: desugar 'field: @cap' to 'field: _ @cap'
When a field pattern has a bare capture with no preceding pattern atom (i.e. `foo: @bar`), implicitly use a true wildcard (`_`, match_unnamed: true) as the node pattern, making it equivalent to `foo: _ @bar`. This is a convenience shorthand: in practice every `field: _ @cap` in the Swift rules can now be written more concisely as `field: @cap`. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ddc9516 commit d11b428

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

shared/yeast-macros/src/parse.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,12 @@ fn parse_query_fields(tokens: &mut Tokens) -> Result<Vec<TokenStream>> {
141141
// Parse the field's pattern. To support repetition like
142142
// `field: (kind)* @cap`, parse the atom first, then check for
143143
// a quantifier, and lastly handle a trailing `@capture`.
144-
let atom = parse_query_atom(tokens)?;
144+
// `field: @cap` is sugar for `field: _ @cap`.
145+
let atom = if peek_is_at(tokens) {
146+
quote! { yeast::query::QueryNode::Any { match_unnamed: true } }
147+
} else {
148+
parse_query_atom(tokens)?
149+
};
145150
if peek_is_repetition(tokens) {
146151
let rep = expect_repetition(tokens)?;
147152
let elem = quote! {

0 commit comments

Comments
 (0)