Text::Treesitter::QueryCursor - stores the result of a tree-sitter node query
my $ts = Text::Treesitter->new(
lang_name => "perl",
my $query = $ts->load_query_string( "path/to/query.scm" );
my $tree = $ts->parse_string( $input );
my $qc = Text::Treesitter::_QueryCursor->new;
$qc->exec( $query, $tree->root_node );
Instances of this class store the result of performing a query pattern match operation against the node tree of a parse result. Once executed it will contain the matched patterns and captured nodes, which can then be queried.
$qc = Text::Treesitter::QueryCursor->new;
Returns a new blank instance.
$qc->exec( $query, $node );
Performs the query pattern-matching operation by attempting to match node subtrees from the given (root) node, against patterns defined by the query.
This method does not return a result; instead the matches are stored within the object itself and can be iterated using "next_match".
$match = $qc->next_match;
Returns the next stored match from the most recent "exec" operation, or undef if there are no more matches. The match is returned as an instance of Text::Treesitter::QueryMatch.
$captures = $qc->next_match_captures( %options );
Since version 0.10.
A convenience wrapper around "next_match" for applying predicate tests and extracting the nodes corresponding to each capture.
Matches that fail the test_predicates_for_match are skipped. The next match that passes then has its captures extracted into a hash; with keys of the hash being the capture names, and the values containing the nodes.
If the multi option is true then each value of the returned hash will be an array reference containing every node that was captured at that name. If the option is false then it will contain just the final capture (which is normally fine because most patterns do not capture multiple nodes).
The following C library functions are currently unhandled:
Paul Evans <firstname.lastname@example.org>
To install Text::Treesitter, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.