Skip to main content

Module structural

Module structural 

Source
Expand description

Structural (AST) search.

Two input dialects are accepted:

  • A native tree-sitter query S-expression (anything starting with (), with captures (@name) and #eq? / #match? predicates. This is the full power of the tree-sitter query language.
  • A friendlier code pattern with $NAME meta-variables, e.g. fn $NAME($PARAMS) -> Result<$T>, which is compiled into a tree-sitter query: concrete tokens become structure + #eq? constraints, and each meta-variable becomes a wildcard capture. A variadic $$$ (optionally $$$NAME) matches any sequence of sibling nodes, so function $NAME($$$) { $$$ } matches a function with any parameters and any body. Variadic meta-variables only relax structure; they do not bind a capture.

Matching runs the compiled query over candidate documents. Literal tokens in the pattern double as trigram anchors so the index prunes candidates before parsing.

Structs§

Compiled
A compiled structural pattern ready to run against documents.
StructCapture
A capture bound by a structural match.
StructMatch
A single structural match within one document.

Functions§

compile
Compile a pattern (S-expression or meta-variable form) for lang.
run
Run a compiled pattern over one source buffer.