diff --git a/docs/section-2-using-parsers.md b/docs/section-2-using-parsers.md index 75c508f5..06aa0c00 100644 --- a/docs/section-2-using-parsers.md +++ b/docs/section-2-using-parsers.md @@ -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. diff --git a/lib/src/query.c b/lib/src/query.c index 710a17b8..e0793011 100644 --- a/lib/src/query.c +++ b/lib/src/query.c @@ -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;