parser

struct Parser;
A stateful object that this is used to produce a Tree based on some source code
TSParser* tsparser;
internal TSParser
nothrow @nogc this(in Language language);
Create a new Parser for the given language.
NOTE: It assumes that the language is compatible (uses set_language_nothrow).
Parameters:
Language language the language you want to create a parser for
nothrow auto set_language_nothrow(in Language language);
Set the language that the parser should use for parsing.
NOTE it assumes that the language is compatible. Returns a boolean indicating whether or not the language was successfully assigned.
auto set_language(in Language language);
Set the language that the parser should use for parsing.
Returns a boolean indicating whether or not the language was successfully assigned. True means assignment succeeded. False means there was a version mismatch, the language was gen with an incompatible version of the Tree-sitter CLI. Check the language's version using ts_language_version and compare it to this library's TREE_SITTER_LANGUAGE_VERSION and TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION constants.
const void enforce_compatible_language(Language language);
Throws an error if the version of the given language is not compatible
const nothrow @nogc auto language();
Get the parser's current language.
const nothrow @nogc TSLogger* logger();
Get the parser's current logger.
auto print_dot_graphs(File file);
Set the destination to which the parser should write debugging graphs during parsing. The graphs are formatted in the DOT language. You may want to pipe these graphs directly to a dot(1) process in order to generate SVG output.
nothrow @nogc auto stop_printing_dot_graphs();
Stop the parser from printing debugging graphs while parsing.
nothrow @nogc auto parse(TSInput input, const TSTree* old_tree = Tree.create_empty());
Use the parser to parse some source code and create a syntax tree.
If you are parsing this document for the first time, pass NULL for the old_tree parameter. Otherwise, if you have already parsed an earlier version of this document and the document has since been edited, pass the previous syntax tree so that the unchanged parts of it can be reused. This will save time and memory. For this to work correctly, you must have already edited the old syntax tree using the ts_tree_edit function in a way that exactly matches the source code changes.
The TSInput parameter lets you specify how to read the text. It has the following three fields:
  1. read: A function to retrieve a chunk of text at a given byte offset and (row, column) position. The function should return a pointer to the text and write its length to the bytes_read pointer. The parser does not take ownership of this buffer; it just borrows it until it has finished reading it. The function should write a zero value to the bytes_read pointer to indicate the end of the document.
  2. payload: An arbitrary pointer that will be passed to each invocation of the read function.
  3. encoding: An indication of how the text is encoded. Either TSInputEncodingUTF8 or TSInputEncodingUTF16.
This function returns a syntax tree on success, and NULL on failure. There are three possible reasons for failure:
  1. The parser does not have a language assigned. Check for this using the
ts_parser_language function. 2. Parsing was cancelled due to a timeout that was set by an earlier call to the ts_parser_set_timeout_micros function. You can resume parsing from where the parser left out by calling ts_parser_parse again with the same arguments. Or you can start parsing from scratch by first calling ts_parser_reset. 3. Parsing was cancelled using a cancellation flag that was set by an earlier call to ts_parser_set_cancellation_flag. You can resume parsing from where the parser left out by calling ts_parser_parse again with the same arguments.
nothrow auto parse(const string source_code, const TSTree* old_tree = Tree.create_empty());
Use the parser to parse some source code stored in one contiguous buffer. The first two parameters are the same as in the ts_parser_parse function above. The second two parameters indicate the location of the buffer and its length in bytes.
nothrow auto parse(const string source_code, const TSInputEncoding encoding, const TSTree* old_tree = Tree.create_empty());
Use the parser to parse some source code stored in one contiguous buffer with a given encoding. The first four parameters work the same as in the ts_parser_parse_string method above. The final parameter indicates whether the text is encoded as UTF8 or UTF16.
nothrow auto parse_utf8(const string source_code, const TSTree* old_tree = Tree.create_empty());
Parse the given source_code that is in utf8 encoding
nothrow @nogc auto parse_utf16(const wstring source_code, const TSTree* old_tree = Tree.create_empty());
Parse the given source_code that is in utf16 encoding
nothrow Tree parse_to_tree(const string source);
Parse the given source_code into a Tree
nothrow auto s_expression(const string source_code);
Get the S-expression of the given source code
Parameters:
string source_code the given source code as a string
Returns: the parsed S-expression
void traverse(const string source_code, TreeVisitor visitor);
@trusted string traverse_print(const string source_code);
Traverse the Tree starting from its root Node and print information about each