Parser#
- class tree_sitter.Parser(language, *, included_ranges=None, timeout_micros=None)#
A class that is used to produce a
Tree
based on some source code.Methods#
- parse(source, /, old_tree=None, encoding='utf8')#
Parse a slice of a bytestring or bytes provided in chunks by a callback.
The callback function takes a byte offset and position and returns a bytestring starting at that offset and position. The slices can be of any length. If the given position is at the end of the text, the callback should return an empty slice.
- Returns:
A
Tree
if parsing succeeded orNone
if the parser does not have an assigned language or the timeout expired.
- print_dot_graphs(file)#
Set the file descriptor to which the parser should write debugging graphs during parsing. The graphs are formatted in the DOT language. You can turn off this logging by passing
None
.Added in version 0.24.0.
- reset()#
Instruct the parser to start the next parse from the beginning.
Attributes#
- included_ranges#
The ranges of text that the parser will include when parsing.
- language#
The language that will be used for parsing.
- logger#
The logger that the parser should use during parsing.
Added in version 0.24.0.
- timeout_micros#
The duration in microseconds that parsing is allowed to take.