mirror of
https://github.com/github/codeql.git
synced 2026-06-25 14:47:04 +02:00
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>
This commit is contained in:
@@ -141,7 +141,12 @@ fn parse_query_fields(tokens: &mut Tokens) -> Result<Vec<TokenStream>> {
|
||||
// Parse the field's pattern. To support repetition like
|
||||
// `field: (kind)* @cap`, parse the atom first, then check for
|
||||
// a quantifier, and lastly handle a trailing `@capture`.
|
||||
let atom = parse_query_atom(tokens)?;
|
||||
// `field: @cap` is sugar for `field: _ @cap`.
|
||||
let atom = if peek_is_at(tokens) {
|
||||
quote! { yeast::query::QueryNode::Any { match_unnamed: true } }
|
||||
} else {
|
||||
parse_query_atom(tokens)?
|
||||
};
|
||||
if peek_is_repetition(tokens) {
|
||||
let rep = expect_repetition(tokens)?;
|
||||
let elem = quote! {
|
||||
|
||||
Reference in New Issue
Block a user