Struct typst_syntax::SyntaxNode
source · 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(message: impl Into<EcoString>, text: impl Into<EcoString>) -> Self
pub fn error(message: impl Into<EcoString>, text: impl Into<EcoString>) -> Self
Create a new error node.
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
source§fn eq(&self, other: &SyntaxNode) -> bool
fn eq(&self, other: &SyntaxNode) -> bool
self
and other
values to be equal, and is used
by ==
.