Text::Treesitter::Parser - parse some input text according to a tree-sitter grammar
Text::Treesitter::Parser
Usually accessed indirectly, via Text::Treesitter. Can also be used directly.
Text::Treesitter
use Text::Treesitter::Language; use Text::Treesitter::Parser; my $language_lib = "path/to/the/tree-sitter-perl.so"; my $lang = Text::Treesitter::Language::load( $language_lib, "perl" ); my $parser = Text::Treesitter::Parser->new; $parser->set_language( $lang ); my $tree = $parser->parse_string( $input ); ...
Instances of this class perform the actual parsing operation, taking a language specification (in the form of a Text::Treesitter::Language instance) and the input text string, yielding a result (in the form of a Text::Treesitter::Tree instance).
$parser = Text::Treesitter::Parser->new;
Returns a new parser instance. A language must be set (by calling "set_language") before parsing can be performed.
$parser->set_language( $lang );
Sets the language specification, as specified by an instance of Text::Treesitter::Language.
$tree = $parser->parse_string( $str );
Parses a given input string, returning a node tree as an instance of Text::Treesitter::Tree.
$parser->reset;
Resets the internal state of the parser so it can be used again.
The following C library functions are currently unhandled:
ts_parser_included_ranges ts_parser_parse ts_parser_set_timeout_micros ts_parser_timeout_micros ts_parser_set_cancellation_flag ts_parser_cancellation_flag ts_parser_set_logger ts_parser_logger
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.