The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Text::Treesitter::Tree - holds the result of a tree-sitter parse operation

SYNOPSIS

Usually accessed indirectly, via Text::Treesitter.

   use Text::Treesitter;

   my $ts = Text::Treesitter->new(
      lang_name => "perl",
   );

   my $tree = $ts->parse_string( $input );

   my $root = $tree->root_node;

   ...

DESCRIPTION

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.

METHODS

text

   $text = $tree->text;

Returns the original source text that was parsed to create the tree.

byte_to_char

   $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.

root_node

   $node = $tree->root_node;

Returns the root node of the parse tree, as an instance of Text::Treesitter::Node.

TODO

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

AUTHOR

Paul Evans <leonerd@leonerd.org.uk>