Skip to main content

SyntaxNode

Struct SyntaxNode 

Source
pub struct SyntaxNode { /* private fields */ }
Expand description

Node in the red syntax tree.

Implementations§

Source§

impl SyntaxNode

Source

pub fn new_root(green: GreenNode) -> Self

Build a new syntax tree on top of a green tree.

Source

pub fn kind(&self) -> SyntaxKind

Kind of this node.

Source

pub fn text_range(&self) -> TextRange

The range that this node covers in the original text.

Source

pub fn green(&self) -> &GreenNode

The underlying green node of this red node.

Source

pub fn amber(&self) -> AmberNode<'_>

The corresponding amber node of this red node.

Source

pub fn parent(&self) -> Option<SyntaxNode>

Parent of this node. It returns None if this node is the root.

Source

pub fn ancestors(&self) -> impl Iterator<Item = SyntaxNode>

Iterator along the chain of parents of this node.

Source

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.

Source

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.

Source

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.

Source

pub fn children_with_tokens( &self, ) -> impl DoubleEndedIterator<Item = NodeOrToken<SyntaxNode, SyntaxToken>>

Iterator over the child nodes and tokens of this node.

Source

pub fn has_child_or_token_by_kind<M>(&self, matcher: M) -> bool
where 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.

Source

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.

Source

pub fn next_sibling_or_token( &self, ) -> Option<NodeOrToken<SyntaxNode, SyntaxToken>>

Node or token that comes immediately after this node.

Source

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.

Source

pub fn next_consecutive_tokens(&self) -> impl Iterator<Item = SyntaxToken>

Consecutive tokens sequence that come immediately after this node without any nodes in between.

Source

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.

Source

pub fn prev_sibling_or_token( &self, ) -> Option<NodeOrToken<SyntaxNode, SyntaxToken>>

Node or token that comes immediately before this node.

Source

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.

Source

pub fn prev_consecutive_tokens(&self) -> impl Iterator<Item = SyntaxToken>

Consecutive tokens sequence that come immediately before this node without any nodes in between.

Source

pub fn descendants(&self) -> impl Iterator<Item = SyntaxNode>

Iterator over all nodes in the subtree, including this node itself.

Source

pub fn token_at_offset(&self, offset: TextSize) -> TokenAtOffset

Find a token in the subtree corresponding to this node, which covers the offset.

Source

pub fn child_at_range(&self, range: TextRange) -> Option<SyntaxNode>

Find a child node that intersects with the given range.

Source

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

Source§

fn clone(&self) -> SyntaxNode

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SyntaxNode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for SyntaxNode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> From<&'a SyntaxNode> for AmberNode<'a>

Source§

fn from(node: &'a SyntaxNode) -> Self

Converts to this type from the input type.
Source§

impl From<SyntaxNode> for NodeOrToken<SyntaxNode, SyntaxToken>

Source§

fn from(node: SyntaxNode) -> Self

Converts to this type from the input type.
Source§

impl Hash for SyntaxNode

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for SyntaxNode

Source§

fn eq(&self, other: &SyntaxNode) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for SyntaxNode

Source§

impl StructuralPartialEq for SyntaxNode

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.