pub struct Cst<'a> { /* private fields */ }Available on crate feature
parser only.Expand description
A concrete syntax tree (CST) type.
Nodes are laid out linearly in memory.
Spans for tokens are directly stored in the spans vector.
Spans for rule nodes are calculated based on their contained token nodes.
§Example
This syntax tree
foo
bar
A
B
Cwill have the following nodes vector.
[
Node::Rule(Rule::Foo, 4),
Node::Rule(Rule::Bar, 2),
Node::Token(Token::A, 0),
Node::Token(Token::B, 1),
Node::Token(Token::C, 2),
]Implementations§
Source§impl<'a> Cst<'a>
impl<'a> Cst<'a>
pub fn source(&self) -> &'a str
pub fn into_data(self) -> CstData
Sourcepub fn children(&self, node_ref: NodeRef) -> CstChildren<'_> ⓘ
pub fn children(&self, node_ref: NodeRef) -> CstChildren<'_> ⓘ
Returns an iterator over the children of the node referenced by node_ref.
Sourcepub fn span(&self, node_ref: NodeRef) -> Span
pub fn span(&self, node_ref: NodeRef) -> Span
Returns the span for the node referenced by node_ref.
For rules the span is calculated based on the first and last token.
If there are no tokens the function returns None.
Sourcepub fn match_token(
&self,
node_ref: NodeRef,
matched_token: Token,
) -> Option<(&'a str, Span)>
pub fn match_token( &self, node_ref: NodeRef, matched_token: Token, ) -> Option<(&'a str, Span)>
Returns the slice and span of the node referenced by node_ref if it matches matched_token.
Sourcepub fn match_rule(&self, node_ref: NodeRef, matched_rule: Rule) -> bool
pub fn match_rule(&self, node_ref: NodeRef, matched_rule: Rule) -> bool
Checks if the node referenced by node_ref matches matched_rule.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Forget for Cst<'a>
impl<'a> Freeze for Cst<'a>
impl<'a> RefUnwindSafe for Cst<'a>
impl<'a> Send for Cst<'a>
impl<'a> Sync for Cst<'a>
impl<'a> Unpin for Cst<'a>
impl<'a> UnsafeUnpin for Cst<'a>
impl<'a> UnwindSafe for Cst<'a>
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
Mutably borrows from an owned value. Read more
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> ⓘ
Converts
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> ⓘ
Converts
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