pub struct AmberNode<'a> { /* private fields */ }Expand description
Node in the amber syntax tree.
It’s a lightweight version of SyntaxNode without access to parent and siblings.
It’s much cheaper than SyntaxNode to create and use.
This is preferred to use for better performance if you don’t need to visit parent and siblings.
Implementations§
Source§impl<'a> AmberNode<'a>
impl<'a> AmberNode<'a>
Sourcepub fn new(green: &'a GreenNode, start: TextSize) -> Self
pub fn new(green: &'a GreenNode, start: TextSize) -> Self
Create a new amber node with the given green node based on the offset.
Note that passing wrong offset can cause unexpectedly incorrect syntax tree. Be careful.
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 to_ptr(&self) -> SyntaxNodePtr
pub fn to_ptr(&self) -> SyntaxNodePtr
The corresponding SyntaxNodePtr of this amber node.
Sourcepub fn children(&self) -> impl DoubleEndedIterator<Item = AmberNode<'a>> + Clone
pub fn children(&self) -> impl DoubleEndedIterator<Item = AmberNode<'a>> + Clone
Iterator over the child nodes of this node.
If you want to iterate over both nodes and tokens, use children_with_tokens instead.
Sourcepub fn children_by_kind<M>(
&self,
matcher: M,
) -> impl DoubleEndedIterator<Item = AmberNode<'a>> + use<'_, 'a, M>where
M: SyntaxKindMatch,
pub fn children_by_kind<M>(
&self,
matcher: M,
) -> impl DoubleEndedIterator<Item = AmberNode<'a>> + use<'_, 'a, M>where
M: SyntaxKindMatch,
Iterator over specific kinds of child nodes of this node.
Sourcepub fn tokens_by_kind<M>(
&self,
matcher: M,
) -> impl DoubleEndedIterator<Item = AmberToken<'a>> + use<'_, 'a, M>where
M: SyntaxKindMatch,
pub fn tokens_by_kind<M>(
&self,
matcher: M,
) -> impl DoubleEndedIterator<Item = AmberToken<'a>> + use<'_, 'a, M>where
M: SyntaxKindMatch,
Iterator over specific kinds of child tokens of this node.
Sourcepub fn children_with_tokens(
&self,
) -> impl DoubleEndedIterator<Item = NodeOrToken<AmberNode<'a>, AmberToken<'a>>>
pub fn children_with_tokens( &self, ) -> impl DoubleEndedIterator<Item = NodeOrToken<AmberNode<'a>, AmberToken<'a>>>
Iterator over the child nodes and tokens of this node.
Sourcepub fn descendant_tokens(
&self,
) -> impl Iterator<Item = (AmberToken<'a>, AmberNode<'a>, Option<AmberNode<'a>>)> + 'a
pub fn descendant_tokens( &self, ) -> impl Iterator<Item = (AmberToken<'a>, AmberNode<'a>, Option<AmberNode<'a>>)> + 'a
Iterator over all tokens in the subtree.
The iterator yields a three-component tuple:
- current token
- the parent of current token
- the grandparent of current token