pub struct SyntaxTree { /* private fields */ }parser only.Expand description
A lossless concrete syntax tree for a Source, as produced by the generated parser.
Nodes are referenced using NodeRefs, and are either Node::Rules (with children) or Node::Tokens (leaves). SyntaxTree::ROOT is always a Node::Rule.
Implementations§
Source§impl SyntaxTree
impl SyntaxTree
Sourcepub const ROOT: NodeRef = NodeRef::ROOT
pub const ROOT: NodeRef = NodeRef::ROOT
The root node of every SyntaxTree.
Sourcepub fn token(&self, node: NodeRef) -> Option<Token>
pub fn token(&self, node: NodeRef) -> Option<Token>
Get the Token type of a node if it’s a token node.
Sourcepub fn children(&self, node: NodeRef) -> CstChildren<'_> ⓘ
pub fn children(&self, node: NodeRef) -> CstChildren<'_> ⓘ
Get an iterator over the direct children of a node. Token nodes have no children.
Sourcepub fn span(&self, node: NodeRef) -> Range<usize> ⓘ
pub fn span(&self, node: NodeRef) -> Range<usize> ⓘ
Get the byte range in the source covered by a node.
For rule nodes, this is from the start of their first token to the end of their last. Rule nodes without any tokens (possible when the parser recovers from errors) have an empty range where they would be.
Sourcepub fn fragment(&self, node: NodeRef) -> Fragment
pub fn fragment(&self, node: NodeRef) -> Fragment
Get a Fragment of the source covered by a node (see SyntaxTree::span).
Sourcepub fn text(&self, node: NodeRef) -> &str
pub fn text(&self, node: NodeRef) -> &str
Get the source text covered by a node (see SyntaxTree::span).
Trait Implementations§
Source§impl Debug for SyntaxTree
impl Debug for SyntaxTree
Auto Trait Implementations§
impl Forget for SyntaxTree
impl Freeze for SyntaxTree
impl RefUnwindSafe for SyntaxTree
impl Send for SyntaxTree
impl Sync for SyntaxTree
impl Unpin for SyntaxTree
impl UnsafeUnpin for SyntaxTree
impl UnwindSafe for SyntaxTree
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> 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