pub struct SyntaxNode { /* private fields */ }Expand description
Node in the red syntax tree.
Implementations§
Source§impl SyntaxNode
impl SyntaxNode
Sourcepub fn kind(&self) -> SyntaxKind
pub fn kind(&self) -> SyntaxKind
Kind of this node.
Sourcepub fn text_range(&self) -> TextRange
pub fn text_range(&self) -> TextRange
The range that this node covers in the original text.
Sourcepub fn parent(&self) -> Option<SyntaxNode>
pub fn parent(&self) -> Option<SyntaxNode>
Parent of this node. It returns None if this node is the root.
Sourcepub fn ancestors(&self) -> impl Iterator<Item = SyntaxNode>
pub fn ancestors(&self) -> impl Iterator<Item = SyntaxNode>
Iterator along the chain of parents of this node.
Sourcepub fn children(&self) -> SyntaxNodeChildren ⓘ
pub fn children(&self) -> SyntaxNodeChildren ⓘ
Iterator over the child nodes of this node.
If you want to iterate over both nodes and tokens, use children_with_tokens instead.
Though you can filter specific kinds of children on this iterator manually,
it is more efficient to use children_by_kind instead.
Sourcepub fn children_by_kind<M>(
&self,
matcher: M,
) -> impl DoubleEndedIterator<Item = SyntaxNode> + use<'_, M>where
M: SyntaxKindMatch,
pub fn children_by_kind<M>(
&self,
matcher: M,
) -> impl DoubleEndedIterator<Item = SyntaxNode> + use<'_, M>where
M: SyntaxKindMatch,
Iterator over specific kinds of child nodes of this node.
This is more efficient than filtering with children manually.
Sourcepub fn tokens_by_kind<M>(
&self,
matcher: M,
) -> impl DoubleEndedIterator<Item = SyntaxToken> + use<'_, M>where
M: SyntaxKindMatch,
pub fn tokens_by_kind<M>(
&self,
matcher: M,
) -> impl DoubleEndedIterator<Item = SyntaxToken> + use<'_, M>where
M: SyntaxKindMatch,
Iterator over specific kinds of child tokens of this node.
Sourcepub fn children_with_tokens(
&self,
) -> impl DoubleEndedIterator<Item = NodeOrToken<SyntaxNode, SyntaxToken>>
pub fn children_with_tokens( &self, ) -> impl DoubleEndedIterator<Item = NodeOrToken<SyntaxNode, SyntaxToken>>
Iterator over the child nodes and tokens of this node.
Sourcepub fn has_child_or_token_by_kind<M>(&self, matcher: M) -> boolwhere
M: SyntaxKindMatch,
pub fn has_child_or_token_by_kind<M>(&self, matcher: M) -> boolwhere
M: SyntaxKindMatch,
Check if this node has specific kinds of child nodes or tokens.
This is an efficient alternative to node.children_with_tokens().any(...)
since it won’t create any nodes or tokens.
Sourcepub fn next_siblings(&self) -> impl Iterator<Item = SyntaxNode>
pub fn next_siblings(&self) -> impl Iterator<Item = SyntaxNode>
Nodes that come immediately after this node.
If you want to iterate over both nodes and tokens, use next_siblings_with_tokens instead.
Unlike rowan, the iterator doesn’t contain the current node itself.
Sourcepub fn next_sibling_or_token(
&self,
) -> Option<NodeOrToken<SyntaxNode, SyntaxToken>>
pub fn next_sibling_or_token( &self, ) -> Option<NodeOrToken<SyntaxNode, SyntaxToken>>
Node or token that comes immediately after this node.
Sourcepub fn next_siblings_with_tokens(
&self,
) -> impl Iterator<Item = NodeOrToken<SyntaxNode, SyntaxToken>>
pub fn next_siblings_with_tokens( &self, ) -> impl Iterator<Item = NodeOrToken<SyntaxNode, SyntaxToken>>
Nodes and tokens that come immediately after this node.
Unlike rowan, the iterator doesn’t contain the current node itself.
Sourcepub fn next_consecutive_tokens(&self) -> impl Iterator<Item = SyntaxToken>
pub fn next_consecutive_tokens(&self) -> impl Iterator<Item = SyntaxToken>
Consecutive tokens sequence that come immediately after this node without any nodes in between.
Sourcepub fn prev_siblings(&self) -> impl Iterator<Item = SyntaxNode>
pub fn prev_siblings(&self) -> impl Iterator<Item = SyntaxNode>
Nodes that come immediately before this node.
If you want to iterate over both nodes and tokens, use prev_siblings_with_tokens instead.
Unlike rowan, the iterator doesn’t contain the current node itself.
Sourcepub fn prev_sibling_or_token(
&self,
) -> Option<NodeOrToken<SyntaxNode, SyntaxToken>>
pub fn prev_sibling_or_token( &self, ) -> Option<NodeOrToken<SyntaxNode, SyntaxToken>>
Node or token that comes immediately before this node.
Sourcepub fn prev_siblings_with_tokens(
&self,
) -> impl Iterator<Item = NodeOrToken<SyntaxNode, SyntaxToken>>
pub fn prev_siblings_with_tokens( &self, ) -> impl Iterator<Item = NodeOrToken<SyntaxNode, SyntaxToken>>
Nodes and tokens that come immediately before this node.
Unlike rowan, the iterator doesn’t contain the current node itself.
Sourcepub fn prev_consecutive_tokens(&self) -> impl Iterator<Item = SyntaxToken>
pub fn prev_consecutive_tokens(&self) -> impl Iterator<Item = SyntaxToken>
Consecutive tokens sequence that come immediately before this node without any nodes in between.
Sourcepub fn descendants(&self) -> impl Iterator<Item = SyntaxNode>
pub fn descendants(&self) -> impl Iterator<Item = SyntaxNode>
Iterator over all nodes in the subtree, including this node itself.
Sourcepub fn token_at_offset(&self, offset: TextSize) -> TokenAtOffset
pub fn token_at_offset(&self, offset: TextSize) -> TokenAtOffset
Find a token in the subtree corresponding to this node, which covers the offset.
Sourcepub fn child_at_range(&self, range: TextRange) -> Option<SyntaxNode>
pub fn child_at_range(&self, range: TextRange) -> Option<SyntaxNode>
Find a child node that intersects with the given range.
Sourcepub fn replace_with(&self, replacement: GreenNode) -> GreenNode
pub fn replace_with(&self, replacement: GreenNode) -> GreenNode
Replace this node with new green node. It returns new root green node with replaced node.
Trait Implementations§
Source§impl Clone for SyntaxNode
impl Clone for SyntaxNode
Source§fn clone(&self) -> SyntaxNode
fn clone(&self) -> SyntaxNode
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more