Selecting by node kind
(:kind) is an escape hatch for power users who need to match constructs that SYNG doesn't have dedicated selectors for. It selects nodes by their underlying TreeSitter node kind and has the following signature:
(:kind [pattern])When to use it
Most of the time, you should prefer SYNG's dedicated selectors like (call), (fun), or (id). These are designed to be portable across languages and express intent clearly.
However, there are cases where you need to match something SYNG doesn't cover yet, or you're debugging and want to understand what node kinds exist in a particular piece of code. That's where (:kind) comes in.
Matching specific node kinds
To find all identifier nodes in Python:
(:kind "identifier")x = foo()
# matches: x, fooOr to find all function definitions:
(:kind "function_definition")def greet():
pass
# matches the entire function definitionUsing patterns
Like other selectors, (:kind) accepts regex patterns. To find any statement node:
(:kind /.*_statement/)x = 1
if True:
pass
# matches: expression_statement, if_statement, pass_statementComposing with other selectors
(:kind) can be combined with other selectors using logical operators. For example, to find calls that are specifically call nodes (as opposed to other expression types):
(:and (call) (:kind "call"))Or to find identifiers that appear in assignment targets:
(:and (:kind "identifier") (:text /x/))Finding available node kinds
Node kinds are specific to each language's TreeSitter grammar. To discover what kinds exist for a given piece of code, you can use a broad pattern:
(:kind /.*/)This will match every node, allowing you to inspect their kinds.