Add docs for negated field patterns
This commit is contained in:
parent
ba9c44e715
commit
a7ae7767b4
2 changed files with 10 additions and 3 deletions
|
|
@ -462,6 +462,16 @@ In general, it's a good idea to make patterns more specific by specifying [field
|
|||
object: (call_expression)))
|
||||
```
|
||||
|
||||
#### Negated Fields
|
||||
|
||||
You can also constrain a pattern so that it only mathces nodes that *lack* a certain field. To do this, add a field name prefixed by a `!` within the parent pattern. For example, this pattern would match a class declaration with no type parameters:
|
||||
|
||||
```
|
||||
(class_declaration
|
||||
name: (identifier) @class_name
|
||||
!type_parameters)
|
||||
```
|
||||
|
||||
#### Anonymous Nodes
|
||||
|
||||
The parenthesized syntax for writing nodes only applies to [named nodes](#named-vs-anonymous-nodes). To match specific anonymous nodes, you write their name between double quotes. For example, this pattern would match any `binary_expression` where the operator is `!=` and the right side is `null`:
|
||||
|
|
@ -585,7 +595,6 @@ For example, this pattern would match any node inside a call:
|
|||
(call (_) @call.inner)
|
||||
```
|
||||
|
||||
|
||||
#### Anchors
|
||||
|
||||
The anchor operator, `.`, is used to constrain the ways in which child patterns are matched. It has different behaviors depending on where it's placed inside a query.
|
||||
|
|
|
|||
|
|
@ -66,8 +66,6 @@ typedef struct {
|
|||
* by other sibling nodes that weren't specified in the pattern.
|
||||
* - `is_last_child` - Indicates that the node matching this step cannot have any
|
||||
* subsequent named siblings.
|
||||
*
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
TSSymbol symbol;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue