#[repr(C)]pub struct Node<'tree> { /* private fields */ }Implementations§
Source§impl<'tree> Node<'tree>
impl<'tree> Node<'tree>
pub fn id(&self) -> usize
Sourcepub fn grammar(&self) -> Grammar
pub fn grammar(&self) -> Grammar
Get the Grammar that was used to parse this node’s syntax tree.
Sourcepub fn is_named(&self) -> bool
pub fn is_named(&self) -> bool
Check if this node is named.
Named nodes correspond to named rules in the grammar, whereas anonymous nodes correspond to string literals in the grammar.
Sourcepub fn is_contained_within(&self, range: Range<u32>) -> bool
pub fn is_contained_within(&self, range: Range<u32>) -> bool
Returns true if and only if this node is contained “inside” the given input range, i.e. either start_new > start_old and end_new <= end_old OR start_new >= start_old and end_new < end_old
Sourcepub fn is_missing(&self) -> bool
pub fn is_missing(&self) -> bool
Check if this node is missing.
Missing nodes are inserted by the parser in order to recover from certain kinds of syntax errors.
Sourcepub fn is_extra(&self) -> bool
pub fn is_extra(&self) -> bool
Check if this node is extra.
Extra nodes represent things like comments, which are not required by the grammar, but can appear anywhere.
Sourcepub fn start_byte(&self) -> u32
pub fn start_byte(&self) -> u32
Get the byte offsets where this node starts.
Sourcepub fn byte_range(&self) -> Range<u32>
pub fn byte_range(&self) -> Range<u32>
Get the byte range of source code that this node represents.
Sourcepub fn child(&self, i: u32) -> Option<Node<'tree>>
pub fn child(&self, i: u32) -> Option<Node<'tree>>
Get the node’s child at the given index, where zero represents the first child.
This method is fairly fast, but its cost is technically log(i), so if
you might be iterating over a long list of children, you should use
Node::children instead.
Sourcepub fn child_count(&self) -> u32
pub fn child_count(&self) -> u32
Get this node’s number of children.
Sourcepub fn named_child(&self, i: u32) -> Option<Node<'tree>>
pub fn named_child(&self, i: u32) -> Option<Node<'tree>>
Get this node’s named child at the given index.
See also Node::is_named.
This method is fairly fast, but its cost is technically log(i), so if
you might be iterating over a long list of children, you should use
Node::named_children instead.
Sourcepub fn named_child_count(&self) -> u32
pub fn named_child_count(&self) -> u32
Get this node’s number of named children.
See also Node::is_named.
Sourcepub fn next_sibling(&self) -> Option<Self>
pub fn next_sibling(&self) -> Option<Self>
Get this node’s next sibling.
Sourcepub fn prev_sibling(&self) -> Option<Self>
pub fn prev_sibling(&self) -> Option<Self>
Get this node’s previous sibling.
Sourcepub fn next_named_sibling(&self) -> Option<Self>
pub fn next_named_sibling(&self) -> Option<Self>
Get this node’s next named sibling.
Sourcepub fn prev_named_sibling(&self) -> Option<Self>
pub fn prev_named_sibling(&self) -> Option<Self>
Get this node’s previous named sibling.
Sourcepub fn descendant_for_byte_range(&self, start: u32, end: u32) -> Option<Self>
pub fn descendant_for_byte_range(&self, start: u32, end: u32) -> Option<Self>
Get the smallest node within this node that spans the given range.
Sourcepub fn named_descendant_for_byte_range(
&self,
start: u32,
end: u32,
) -> Option<Self>
pub fn named_descendant_for_byte_range( &self, start: u32, end: u32, ) -> Option<Self>
Get the smallest named node within this node that spans the given range.
Sourcepub fn children(&self) -> impl ExactSizeIterator<Item = Node<'tree>>
pub fn children(&self) -> impl ExactSizeIterator<Item = Node<'tree>>
Iterate over this node’s children.
A TreeCursor is used to retrieve the children efficiently. Obtain
a TreeCursor by calling Tree::walk or Node::walk. To avoid
unnecessary allocations, you should reuse the same cursor for
subsequent calls to this method.
If you’re walking the tree recursively, you may want to use the
TreeCursor APIs directly instead.