query

struct QueryCapture;
A particular Node that has been captured with a particular name within a Query.
Node node;
The Node that was captured.
int index;
the index
string name;
The name of the capture.
struct QueryMatch;
A match of a Query to a particular set of Nodes.
uint id;
The id
uint pattern_index;
the pattern index
QueryCapture[] captures;
the captures array
struct QueryIterator;
A sequence of QueryMatches associated with a given QueryCursor.
this(Query* query, Node* node);
Create a new QueryIterator for the given Query and Node.
this(Query* query, Node* node, uint min, uint max);
Create a new QueryIterator for the given Query and Node and given byte range.
this(Query* query, Node* node, Point min, Point max);
Create a new QueryIterator for the given Query and Node and given point range.
void set_byte_range(uint min, uint max);
Adjusts the range in which the query will apply. min and max are byte offsets.
void set_point_range(Point min, Point max);
Adjusts the range in which the query will apply. min and max are Point offsets.
int opApply(scope int delegate(QueryMatch) dg);
Returns the next QueryMatch in the sequence.
class QueryException: object.Exception;
An error that occurred when trying to create a Query.
TSQueryError error;
the internal TSQueryError error
this(TSQueryError error);
Create a new QueryException with the given TSQueryError.
struct Query;
A query to retrieve information from the syntax tree.
TSQuery* tsquery;
The underlying TSQuery
this(Language language, string queryString);
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. References to Queries can be shared between multiple threads.
QueryIterator exec(Node node);
Execute a query over an entire node.
The caller may iterate over the result to receive a series of QueryMatch results.
QueryIterator exec(Node node, uint min, uint max);
Execute a query between given start and end byte offsets.
The caller may iterate over the result to receive a series of QueryMatch results.
QueryIterator exec(Node node, Point min, Point max);
Execute a query between given start and end Points.
The caller may iterate over the result to receive a series of QueryMatch results.
nothrow @nogc int pattern_count();
Get the number of patterns in the query.
nothrow @nogc int capture_count();
Get the number of captures in the query.
nothrow @nogc int string_count();
Get the number of string literals in the query.
nothrow @nogc int start_byte_for_pattern(uint patternId);
Get the byte offset where the given pattern starts in the query's source.
This can be useful when combining queries by concatenating their source code strings.
nothrow @nogc const(TSQueryPredicateStep)[] predicates_for_pattern(uint patternId);
Get all of the predicates for the given pattern in the query.
The predicates are represented as a single array of steps. There are three types of steps in this array, which correspond to the three legal values for the type field:
  • TSQueryPredicateStepTypeCapture - Steps with this type represent names of captures. Their value_id can be used with the ts_query_capture_name_for_id function to obtain the name of the capture.
  • TSQueryPredicateStepTypeString - Steps with this type represent literal strings. Their value_id can be used with the ts_query_string_value_for_id function to obtain their string value.
  • TSQueryPredicateStepTypeDone - Steps with this type are sentinels that represent the end of an individual predicate. If a pattern has two predicates, then there will be two steps with this type in the array.
nothrow @nogc bool is_pattern_guaranteed_at_step(uint byteOffset);
Check if a given step in a query is 'definite'.
A query step is 'definite' if its parent pattern will be guaranteed to match successfully once it reaches the step.
nothrow @nogc bool step_is_definite(uint byteOffset);
@deprecated. Use is_pattern_guaranteed_at_step instead.
nothrow string capture_name_for_id(uint captureId);
Get the name of one of the query's captures.
Each capture is associated with a numeric id based on the order that it appeared in the query's source.
nothrow string capture_name(TSQueryCapture capture);
Get the name of one of the query's captures, given a TSQueryCapture.
nothrow string query_string_value_for_id(uint id);
Get the name of one of the query's string literals.
Each string is associated with a numeric id based on the order that it appeared in the query's source.
void disable_capture(string captureName);
Disable a certain capture within a query.
This prevents the capture from being returned in matches, and also avoids any resource usage associated with recording the capture. Currently, there is no way to undo this.
nothrow @nogc void disable_pattern(uint patternId);
Disable a certain pattern within a query.
This prevents the pattern from matching and removes most of the overhead associated with the pattern. Currently, there is no way to undo this.