class

TreeSitter::Query

Inherits Reference / Object

A query consists of one or more patterns, where each pattern is an S-expression that matches a certain set of nodes in a syntax tree. The expression to match a given node consists of a pair of parentheses containing two things: the node’s type, and optionally, a series of other S-expressions that match the node’s children.

Constructors

new(language : Language, source : String)

Create a new query from a string containing one or more S-expression patterns. The query is associated with a particular language, and can only be run on syntax nodes parsed with that language.

If all of the given patterns are valid, this returns a Query. If a pattern is invalid, this raises an Error exception that provides two pieces of information about the problem:

  1. The byte offset of the error.
  2. The type of error.
Source

Instance methods

capture_count
Source
pattern_count
Source
string_count
Source