pub struct Syntax { /* private fields */ }Implementations§
Source§impl Syntax
impl Syntax
pub fn parse(language: Language, code: &Rope) -> Self
pub fn reparse(&mut self, code: &Rope)
pub fn language(&self) -> Language
pub fn tree(&self) -> &Tree
Sourcepub fn node_path(&self, byte_range: Range<usize>) -> Vec<Node<'_>>
pub fn node_path(&self, byte_range: Range<usize>) -> Vec<Node<'_>>
Nodes from the root down to the smallest node that covers byte_range.
Sourcepub fn inner_node(&self, byte_range: Range<usize>) -> Option<Node<'_>>
pub fn inner_node(&self, byte_range: Range<usize>) -> Option<Node<'_>>
First named node, in document order, whose byte range lies strictly inside byte_range.
Sourcepub fn outer_node(&self, byte_range: Range<usize>) -> Option<Node<'_>>
pub fn outer_node(&self, byte_range: Range<usize>) -> Option<Node<'_>>
Smallest node whose byte range strictly contains byte_range.
The root node starts after any leading whitespace, so a range that begins in that whitespace has no outer node.
Methods from Deref<Target = Tree>§
pub fn root_node(&self) -> Node<'_>
pub fn root_node(&self) -> Node<'_>
Get the root node of the syntax tree.
pub fn root_node_with_offset(
&self,
offset_bytes: usize,
offset_extent: Point,
) -> Node<'_>
pub fn root_node_with_offset( &self, offset_bytes: usize, offset_extent: Point, ) -> Node<'_>
Get the root node of the syntax tree, but with its position shifted forward by the given offset.
pub fn language(&self) -> LanguageRef<'_>
pub fn language(&self) -> LanguageRef<'_>
Get the language that was used to parse the syntax tree.
When Tree-sitter is compiled to WebAssembly, this returns the original language if the tree is being accessed from the same WebAssembly instance that created it. Otherwise, this returns a copy of the language that can be used to inspect the tree but cannot be assigned to a parser.
pub fn walk(&self) -> TreeCursor<'_>
pub fn walk(&self) -> TreeCursor<'_>
Create a new [TreeCursor] starting from the root of the tree.
pub fn changed_ranges(&self, other: &Tree) -> impl ExactSizeIterator
pub fn changed_ranges(&self, other: &Tree) -> impl ExactSizeIterator
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.
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 one of the [Parser::parse]
functions. Call it on the old tree that was passed to parse, and
pass the new tree that was returned from parse.
pub fn included_ranges(&self) -> Vec<Range>
pub fn included_ranges(&self) -> Vec<Range>
Get the included ranges that were used to parse the syntax tree.
pub fn print_dot_graph(&self, file: &impl AsRawFd)
pub fn print_dot_graph(&self, file: &impl AsRawFd)
Print a graph of the tree to the given file descriptor.
The graph is formatted in the DOT language. You may want to pipe this
graph directly to a dot(1) process in order to generate SVG
output.