class
TreeA syntax tree.
Contents
This also contains a copy of the source code to allow the nodes to refer to the text they were created from.
Constructors, destructors, conversion operators
Public functions
- auto operator=(const Tree&) -> Tree&
- Copy assignment operator.
- auto operator=(Tree&& other) -> Tree& defaulted noexcept
- Move assignment operator.
- auto raw() const -> const TSTree*
- Returns the raw Tree-Sitter tree.
- auto source() const -> const std::string&
- The source code the tree was created from.
- auto parser() const -> const Parser&
- The used parser.
- auto root_node() const -> Node
- The root node of the tree.
- auto language() const -> Language
- The language that was used to parse the syntax tree.
- auto edit(std::vector<Edit>) -> EditResult
- Edit the syntax tree and source code and return the changed ranges.
- void print_dot_graph(std::string_view file) const
- Print a dot graph to the given file.
Friends
Function documentation
const TSTree* ts:: Tree:: raw() const
Returns the raw Tree-Sitter tree.
EditResult ts:: Tree:: edit(std::vector<Edit>)
Edit the syntax tree and source code and return the changed ranges.
You need to specify all edits you want to apply to the syntax tree in one call. Because this method changes both the syntax tree and source code string any other Edits will be invalid and trying to apply them is undefined behaviour.
The edits can't be duplicate or overlapping. Multiline edits are also currently not supported.
The returned result contains information about the raw string ranges that changed and it also contains the adjusted location of the edits that can e.g. be used for highlighting in an editor.
Any previously retrieved nodes will become (silently) invalid.
void ts:: Tree:: print_dot_graph(std::string_view file) const
Print a dot graph to the given file.
file
has to be a null-terminated string (e.g. from a std::string).