How to use or
logic in tree-sitter query?
I want to query out a class's properties and methods:
I tried to use |
:
(class_declaration
name: (type_identifier) @class-name
body: (class_body
((public_field_definition
name: (property_identifier) @property-name)
| (method_definition
name: (property_identifier) @method-name))))
and I checked all the query syntax document, didn't find how to implement it.
Use [
... ]
, and then no |
.
In the docs you referenced, it's called "Alternations".
body: (class_body
[(public_field_definition
name: (property_identifier) @property-name)
(method_definition
name: (property_identifier) @method-name)])