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.

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.

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.

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.

Attributes#

included_ranges#

The included ranges that were used to parse the syntax tree.

root_node#

The root node of the syntax tree.

text#

The source text of this tree, if unedited.

Deprecated since version 0.22.0: Use root_node.text instead.