Text::Treesitter::Tree - holds the result of a tree-sitter parse operation
Text::Treesitter::Tree
Usually accessed indirectly, via Text::Treesitter.
Text::Treesitter
use Text::Treesitter; my $ts = Text::Treesitter->new( lang_name => "perl", ); my $tree = $ts->parse_string( $input ); my $root = $tree->root_node; ...
Instances of this class represent the result of a parse operation from an instance of Text::Treesitter::Parser. These objects are not created directly, but are returned by the parse_string method on a parser instance.
parse_string
$text = $tree->text;
Returns the original source text that was parsed to create the tree.
$charpos = $tree->byte_to_char( $bytepos );
Returns a position in characters (e.g. such that substr or length would count), corresponding to a position in the source text counted in bytes (such as returned by a Node's start_bytes or end_bytes accessor.
substr
length
start_bytes
end_bytes
$node = $tree->root_node;
Returns the root node of the parse tree, as an instance of Text::Treesitter::Node.
The following C library functions are currently unhandled:
ts_tree_copy ts_tree_root_node_with_offset ts_tree_language ts_tree_included_ranges ts_tree_edit ts_tree_get_changed_ranges
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.