Tree#
- class tree_sitter.Tree#
A tree that represents the syntactic structure of a source code file.
Methods#
- changed_ranges(new_tree)#
Compare this old edited syntax tree to a new syntax tree representing the same document, returning a sequence of ranges whose syntactic structure has changed.
- Returns:
Ranges where the hierarchical structure of syntax nodes (from root to leaf) has changed between the old and new trees. Characters outside these ranges have identical ancestor nodes in both trees.
Note
The returned ranges may be slightly larger than the exact changed areas, but Tree-sitter attempts to make them as small as possible.
Tip
For this to work correctly, this syntax tree must have been edited such that its ranges match up to the new tree.
Generally, you’ll want to call this method right after calling the
Parser.parse()
method. Call it on the old tree that was passed to the method, and pass the new tree that was returned from it.
- copy()#
Create a shallow copy of the tree.
- edit(start_byte, old_end_byte, new_end_byte, start_point, old_end_point, new_end_point)#
Edit the syntax tree to keep it in sync with source code that has been edited.
You must describe the edit both in terms of byte offsets and of row/column points.
- print_dot_graph(file)#
Write a DOT graph describing the syntax tree to the given file.
- root_node_with_offset(offset_bytes, offset_extent, /)#
Get the root node of the syntax tree, but with its position shifted forward by the given offset.
- walk()#
Create a new
TreeCursor
starting from the root of the tree.
Special Methods#
- __copy__()#
Use
copy.copy()
to create a copy of the tree.
Attributes#
- included_ranges#
The included ranges that were used to parse the syntax tree.
- language#
The language that was used to parse the syntax tree.
- root_node#
The root node of the syntax tree.