NAME

Text::Treesitter::Parser - parse some input text according to a tree-sitter grammar

SYNOPSIS

Usually accessed indirectly, via Text::Treesitter. Can also be used directly.

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 );

...

DESCRIPTION

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

CONSTRUCTOR

new

$parser = Text::Treesitter::Parser->new;

Returns a new parser instance. A language must be set (by calling "set_language") before parsing can be performed.

METHODS

set_language

$parser->set_language( $lang );

Sets the language specification, as specified by an instance of Text::Treesitter::Language.

parse_string

$tree = $parser->parse_string( $str );

Parses a given input string, returning a node tree as an instance of Text::Treesitter::Tree.

parse_file

$tree = $parser->parse_file( $path );

Since version 0.13.

Reads the file content as a string, then applies "parse_string" on it.

reset

$parser->reset;

Resets the internal state of the parser so it can be used again.

TODO

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

AUTHOR

Paul Evans <leonerd@leonerd.org.uk>