Text::Treesitter::Language - represents a tree-sitter language grammar
Text::Treesitter::Language
Usually accessed indirectly, via Text::Treesitter. Can also be used directly.
Text::Treesitter
use Text::Treesitter::Language; my $language_lib = "path/to/the/tree-sitter-perl.so"; my $lang = Text::Treesitter::Language::load( $language_lib, "perl" ); printf "This language defines %d symbols\n", $lang->symbol_count;
Instances of this class represent an entire language grammar specification. Typically an application will load just one of these for the lifetime of its operation; or at least, just one per type of language being parsed.
These utility functions are not exported, and must be called fully-qualified.
Text::Treesitter::Language::build( $output, @dirs );
Requests that a language grammar repository directory (or several) be compiled into an object file that can later be loaded.
$lang = Text::Treesitter::Language::load( $libfile, $name );
Attempts to actually load the grammar specification from the object file. The object file must have been previously built (either by calling "build", or obtained in some other way).
An instance of Text::Treesitter::Language is returned. This can be passed to the set_language method of a Text::Treesitter::Parser instance.
set_language
$count = $lang->symbol_count;
Returns the number of symbols defined in the language.
@symbols = $lang->symbols;
Returns a list of Symbol instances, in id order. Each will be an instance of a class having the following accessors::
$symbol->id $symbol->name $symbol->type_is_regular $symbol->type_is_anonymous $symbol->type_is_auxiliary
$count = $lang->field_count;
Returns the number of fields defined in the language.
@fields = $lang->fields;
Returns a list of Field instances, in id order. Each will be an instance of a class having the following accessors:
$field->id $field->name
The following C library functions are currently unhandled:
ts_language_symbol_for_name ts_language_field_id_for_name ts_language_version
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.