Parser#
- class tree_sitter.Parser(language, *, included_ranges=None, timeout_micros=None)#
A class that is used to produce a
Treebased 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
Treeif parsing succeeded orNoneif the parser does not have an assigned language or the timeout expired.
Changed in version 0.25.0: *
encodingcan be one of"utf8", "utf16", "utf16le", "utf16be". *progress_callbackparameter added.
- 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.
- 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.