pub struct SyntaxNode(/* private fields */);
Expand description
A node in the untyped syntax tree.
Implementations§
source§impl SyntaxNode
impl SyntaxNode
sourcepub fn leaf(kind: SyntaxKind, text: impl Into<EcoString>) -> Self
pub fn leaf(kind: SyntaxKind, text: impl Into<EcoString>) -> Self
Create a new leaf node.
sourcepub fn inner(kind: SyntaxKind, children: Vec<SyntaxNode>) -> Self
pub fn inner(kind: SyntaxKind, children: Vec<SyntaxNode>) -> Self
Create a new inner node with children.
sourcepub fn error(error: SyntaxError, text: impl Into<EcoString>) -> Self
pub fn error(error: SyntaxError, text: impl Into<EcoString>) -> Self
Create a new error node.
sourcepub const fn placeholder(kind: SyntaxKind) -> Self
pub const fn placeholder(kind: SyntaxKind) -> Self
Create a dummy node of the given kind.
Panics if kind
is SyntaxKind::Error
.
sourcepub fn kind(&self) -> SyntaxKind
pub fn kind(&self) -> SyntaxKind
The type of the node.
sourcepub fn text(&self) -> &EcoString
pub fn text(&self) -> &EcoString
The text of the node if it is a leaf or error node.
Returns the empty string if this is an inner node.
sourcepub fn into_text(self) -> EcoString
pub fn into_text(self) -> EcoString
Extract the text from the node.
Builds the string if this is an inner node.
sourcepub fn children(&self) -> Iter<'_, SyntaxNode>
pub fn children(&self) -> Iter<'_, SyntaxNode>
The node’s children.
sourcepub fn is<'a, T: AstNode<'a>>(&'a self) -> bool
pub fn is<'a, T: AstNode<'a>>(&'a self) -> bool
Whether the node can be cast to the given AST node.
sourcepub fn cast<'a, T: AstNode<'a>>(&'a self) -> Option<T>
pub fn cast<'a, T: AstNode<'a>>(&'a self) -> Option<T>
Try to convert the node to a typed AST node.
sourcepub fn cast_first_match<'a, T: AstNode<'a>>(&'a self) -> Option<T>
pub fn cast_first_match<'a, T: AstNode<'a>>(&'a self) -> Option<T>
Cast the first child that can cast to the AST type T
.
sourcepub fn cast_last_match<'a, T: AstNode<'a>>(&'a self) -> Option<T>
pub fn cast_last_match<'a, T: AstNode<'a>>(&'a self) -> Option<T>
Cast the last child that can cast to the AST type T
.
sourcepub fn errors(&self) -> Vec<SyntaxError>
pub fn errors(&self) -> Vec<SyntaxError>
The error messages for this node and its descendants.
sourcepub fn hint(&mut self, hint: impl Into<EcoString>)
pub fn hint(&mut self, hint: impl Into<EcoString>)
Add a user-presentable hint if this is an error node.
sourcepub fn synthesize(&mut self, span: Span)
pub fn synthesize(&mut self, span: Span)
Set a synthetic span for the node and all its descendants.
sourcepub fn spanless_eq(&self, other: &Self) -> bool
pub fn spanless_eq(&self, other: &Self) -> bool
Whether the two syntax nodes are the same apart from spans.
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 moresource§impl Debug for SyntaxNode
impl Debug for SyntaxNode
source§impl Default for SyntaxNode
impl Default for SyntaxNode
source§impl Hash for SyntaxNode
impl Hash for SyntaxNode
source§impl PartialEq for SyntaxNode
impl PartialEq for SyntaxNode
impl Eq for SyntaxNode
impl StructuralPartialEq for SyntaxNode
Auto Trait Implementations§
impl Freeze for SyntaxNode
impl RefUnwindSafe for SyntaxNode
impl Send for SyntaxNode
impl Sync for SyntaxNode
impl Unpin for SyntaxNode
impl UnwindSafe for SyntaxNode
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more