-
-
Notifications
You must be signed in to change notification settings - Fork 276
Description
This may not be a bug, but I'm looking for clarification. There are ambiguous situations where a parent and child node overlap entirely and each contain the same sequence of characters. When we use a pattern in a situation like this, both the parent and child nodes are reasonable matches. Is there a rationale behind whether ast-grep matches the parent or the child?
Further, it feels like using all
to order the rules and starting with kind
and refining with pattern
should be able to match the expression_statement
even if the pattern wants to match the binary_expression
over the expression_statement
all:
- kind: expression_statement # doesn't match
- pattern: $A == $B

⏯ Playground Link
Playground link with relevant code
💻 Code
Code:
a == b
Pattern:
rule:
pattern: $A == $B
kind: expression_statement # doesn't match
🙁 Actual behavior
While the expression_statement
node does fit the pattern, it won't be matched. Instead the child binary_expression
is matched
🙂 Expected behavior
A matching expression_statement
is found
Discussion
This leads to confusing situations where follows
doesn't work as expected because the matched nodes are children and require us to use inside
, then follows
, and then has
as discussed here