ts::Parser class

Parser for a Tree-Sitter language.

The default constructor uses LUA_LANGUAGE.

Features not included (because we currently don't use them):

  • Partial document parsing:
    • ts_parser_set_included_ranges
    • ts_parser_included_ranges
  • alternative parse sources (other than utf8 string)
    • generalized ts_parser_parse (with TSInput)
    • ts_parser_parse_string_encoding
  • parsing timeout/cancellation
    • ts_parser_reset
    • ts_parser_set_timeout_micros
    • ts_parser_timeout_micros
    • ts_parser_set_cancellation_flag
    • ts_parser_cancellation_flag
  • Grammar debug features:
    • ts_parser_set_logger
    • ts_parser_logger
    • ts_parser_print_dot_graphs

Constructors, destructors, conversion operators

Parser(const Language&)
Create a parser using the given language.

Public functions

auto raw() const -> TSParser*
Returns the raw Tree-Sitter parser.
auto language() const -> Language
The Language the parser was created from.
auto parse_string(std::string) const -> Tree
Parse a string and return its syntax tree.
auto parse_string(const TSTree* old_tree, std::string source) const -> Tree
Parse a string and return its syntax tree.

Function documentation

TSParser* ts::Parser::raw() const

Returns the raw Tree-Sitter parser.

Tree ts::Parser::parse_string(std::string) const

Parse a string and return its syntax tree.

This takes the source code by copy (or move) and stores it in the tree.

Tree ts::Parser::parse_string(const TSTree* old_tree, std::string source) const

Parse a string and return its syntax tree.

This takes the source code by copy (or move) and a previously parsed tree.