- current docs
- query consists of one or more patterns
- each pattern is an s-expression that matches nodes in a tree
- expression consists of pair of parens containing:
- node's type
- optionally series of other s-expressions matching node's children
- prefix a child pattern with a field name followed by a colon
- match anonymous nodes by expressing name between double quotes
- captures enable association of names with specific nodes in a pattern
- capture names are written after the nodes they refer to
- capture names start with the @ character
- quantification operators can be used to match a repeating sequence of sibling nodes
- postfix
+
-> one or more repetitions - postfix
*
-> zero or more repetitions - postifx
?
-> zero or one repetition
- postfix
- grouping sibling nodes
- sequence of sibling nodes can be grouped via parentheses
- any of the quantification operators (
+
,*
,?
) can be applied to groups
- alternations expressed by listing patterns between
[]
- wildcard node matches any node and expressed by
_
- anchor operator
.
is used to constrain ways in which child patterns are matched- before first child in a pattern, child only matches if it's the first named node
- after first child in pattern, child only matches if it's the last named node
- between child patterns, child only matches that are immediate siblings
- predicate s-expressions (e.g. #match?, #eq?, etc.)
- 2020-02-20
- anchor operator
- 2020-05-12
- wildcards with _
- repetition with *
- grouping with ()
- predicates with #
- 2020-05-30
- alternations
- 2020-09-22
- match on supertypes
- 2020-10
- consecutive siblings
- 2020-10
- metadata block with subsequent curly braces
Last active
November 10, 2020 11:31
-
-
Save sogaiu/bf7c550409eedca2970d191a6310ff4f to your computer and use it in GitHub Desktop.
tree-sitter query api notes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment