Text::Treesitter::QueryMatch - stores the result of a tree-sitter query pattern match
Text::Treesitter::QueryMatch
Usually accessed indirectly, via Text::Treesitter::QueryCursor.
Text::Treesitter::QueryCursor
use Text::Treesitter; use Text::Treesitter::QueryCursor; 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 ); while( my $match = $qc->next_match ) { my @captures = $match->captures; next unless $query->test_predicates_for_match( $match, \@captures ); foreach my $capture ( @captures ) { my $node = $capture->node; my $capturename = $query->capture_name_for_id( $capture->capture_id ); printf "%s captures the text <%s>\n", $capturename, $node->text; } }
Instances of this class are returned from a Text::Treesitter::QueryCursor to iterate the matches of the most recent query operation.
$index = $match->pattern_index;
Returns the index within the query indicating which pattern was responsible for this match.
$count = $match->capture_count;
Returns the number of captures made by this pattern.
@captures = $match->captures;
Returns a list of Capture instances, in pattern order. Each will be an instance of a class having the following accessors:
$capture->node $capture->capture_id
Paul Evans <leonerd@leonerd.org.uk>
To install Text::Treesitter, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Text::Treesitter
CPAN shell
perl -MCPAN -e shell install Text::Treesitter
For more information on module installation, please visit the detailed CPAN module installation guide.