Struct rowan::SyntaxNode
source · pub struct SyntaxNode<T: Types> { /* private fields */ }
Expand description
Akn immutable lazy constructed syntax tree with offsets and parent pointers.
The design is close to https://github.com/apple/swift/tree/bc3189a2d265bf7728ea0cfeb55f032bfe5beaf1/lib/Syntax
All nodes constituting a tree share the ownership by a tree. Internally, and
Arc
is used, but outside world observes nodes as &SyntaxNode
or
TreeArc<SyntaxNode>
, where a TreeArc
is an Arc-like smart pointer.
Implementations
sourceimpl<T: Types> SyntaxNode<T>
impl<T: Types> SyntaxNode<T>
sourcepub fn new(green: GreenNode<T>, data: T::RootData) -> TreeArc<T, SyntaxNode<T>>
pub fn new(green: GreenNode<T>, data: T::RootData) -> TreeArc<T, SyntaxNode<T>>
Creates a new SyntaxNode
, whihc becomes the root of the tree.
sourcepub fn to_owned(&self) -> TreeArc<T, SyntaxNode<T>>
pub fn to_owned(&self) -> TreeArc<T, SyntaxNode<T>>
Switch this node to owned flavor.
sourcepub fn replace_children(&self, children: Box<[GreenNode<T>]>) -> GreenNode<T>
pub fn replace_children(&self, children: Box<[GreenNode<T>]>) -> GreenNode<T>
Get the root node but with the children replaced. See replace_with
.
sourcepub fn replace_self(&self, green: GreenNode<T>) -> GreenNode<T>
pub fn replace_self(&self, green: GreenNode<T>) -> GreenNode<T>
Returns a green tree, equal to the green tree this node belongs two, except with this node substitute. The complexity of operation is proportional to the depth of the tree TODO: naming is unfortunate, the return value is not current node, it is the new root node.
sourcepub fn parent(&self) -> Option<&SyntaxNode<T>>
pub fn parent(&self) -> Option<&SyntaxNode<T>>
Get the parent node.
sourcepub fn first_child(&self) -> Option<&SyntaxNode<T>>
pub fn first_child(&self) -> Option<&SyntaxNode<T>>
Get first child.
sourcepub fn last_child(&self) -> Option<&SyntaxNode<T>>
pub fn last_child(&self) -> Option<&SyntaxNode<T>>
Get last child.
sourcepub fn next_sibling(&self) -> Option<&SyntaxNode<T>>
pub fn next_sibling(&self) -> Option<&SyntaxNode<T>>
Get next sibling.
sourcepub fn prev_sibling(&self) -> Option<&SyntaxNode<T>>
pub fn prev_sibling(&self) -> Option<&SyntaxNode<T>>
Get previous sibling.
sourcepub fn children(&self) -> SyntaxNodeChildren<'_, T> ⓘ
pub fn children(&self) -> SyntaxNodeChildren<'_, T> ⓘ
Get iterator over children.
sourcepub fn ancestors(&self) -> impl Iterator<Item = &SyntaxNode<T>>
pub fn ancestors(&self) -> impl Iterator<Item = &SyntaxNode<T>>
All ancestors of the current node, including itself
sourcepub fn preorder(&self) -> impl Iterator<Item = WalkEvent<&SyntaxNode<T>>>
pub fn preorder(&self) -> impl Iterator<Item = WalkEvent<&SyntaxNode<T>>>
Traverse the subtree rooted at the current node (including the current node) in preorder.
sourcepub fn common_ancestor<'a>(
&'a self,
other: &'a SyntaxNode<T>
) -> &'a SyntaxNode<T>
pub fn common_ancestor<'a>(
&'a self,
other: &'a SyntaxNode<T>
) -> &'a SyntaxNode<T>
Returns common ancestor of the two nodes. Precondition: nodes must be from the same tree.
sourcepub fn leaf_at_offset(&self, offset: TextUnit) -> LeafAtOffset<&SyntaxNode<T>> ⓘ
pub fn leaf_at_offset(&self, offset: TextUnit) -> LeafAtOffset<&SyntaxNode<T>> ⓘ
Find a leaf in the subtree corresponding to this node, which covers the offset. Precondition: offset must be withing node’s range.
sourcepub fn covering_node(&self, range: TextRange) -> &SyntaxNode<T>
pub fn covering_node(&self, range: TextRange) -> &SyntaxNode<T>
Return the deepest node in the current subtree that fully contains the range. If the range is empty and is contained in two leaf nodes, either one can be returned. Precondition: range must be contained withing the current node