ImmutableSyntaxTree

Struct ImmutableSyntaxTree 

Source
pub struct ImmutableSyntaxTree<N: Node> { /* private fields */ }
Expand description

A canonical implementation of the SyntaxTree trait.

Parses a syntax grammar only and does not provides any reparse capabilities.

Use this interface when you need to build a syntax tree from already existing stream of tokens or a part of it.

Implementations§

Source§

impl<N: Node> ImmutableSyntaxTree<N>

Source

pub fn parse<'code>( token_cursor: impl TokenCursor<'code, Token = <N as Node>::Token>, ) -> Self

An ImmutableSyntaxTree constructor.

The token_cursor parameter of type TokenCursor provides access to the token stream that needs to be parsed.

You can get this cursor from a TokenBuffer, TokenStream, or any compilation unit type (e.g., Document).

See SourceCode::cursor function for details.

Source

pub fn parse_with_observer<'code>( token_cursor: impl TokenCursor<'code, Token = <N as Node>::Token>, observer: &mut impl Observer<Node = N>, ) -> Self

An extended constructor, where the additional parameter observer specifies an Observer object into which the syntax parser will report parsing steps.

One use case of the observer is to debug your parser. In particular, the DebugObserver prints each parsing step performed by the syntax parser to the stdout.

Trait Implementations§

Source§

impl<N: Node> Debug for ImmutableSyntaxTree<N>

Source§

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

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

impl<N: Node> Identifiable for ImmutableSyntaxTree<N>

Source§

fn id(&self) -> Id

Returns the globally unique identifier of the compilation unit to which this object belongs.
Source§

impl<N: Node> PartialEq for ImmutableSyntaxTree<N>

Source§

fn eq(&self, other: &Self) -> 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<N: Node> SyntaxTree for ImmutableSyntaxTree<N>

Source§

type Node = N

Specifies the type of the tree node. Read more
Source§

type NodeIterator<'tree> = NodeIter

Specifies the type of the iterator that walks through all node NodeRef references currently managed by this SyntaxTree instance.
Source§

type ErrorIterator<'tree> = ErrorIter

Specifies the type of the iterator that walks through all syntax error ErrorRef references currently managed by this SyntaxTree instance.
Source§

fn root_node_ref(&self) -> NodeRef

Returns a NodeRef reference to the root node of this syntax tree.
Source§

fn node_refs(&self) -> Self::NodeIterator<'_>

Returns an iterator of the NodeRef references over all nodes currently managed by this syntax tree. Read more
Source§

fn error_refs(&self) -> Self::ErrorIterator<'_>

Returns an iterator of the ErrorRef references over all syntax errors currently managed by this syntax tree. Read more
Source§

fn has_node(&self, entry: &Entry) -> bool

Checks if the node referred to by the versioned index exists in this syntax tree.
Source§

fn get_node(&self, entry: &Entry) -> Option<&Self::Node>

Provides immutable access to the node referred to by the versioned index. Read more
Source§

fn get_node_mut(&mut self, entry: &Entry) -> Option<&mut Self::Node>

Provides mutable access to the node referred to by the versioned index. Read more
Source§

fn has_error(&self, entry: &Entry) -> bool

Checks if the syntax error referred to by the versioned index exists in this syntax tree.
Source§

fn get_error(&self, entry: &Entry) -> Option<&SyntaxError>

Provides access to the syntax error referred to by the versioned index. Read more
Source§

fn root(&self) -> &Self::Node
where Self: Sized,

Provides access to the root node of the syntax tree. Read more
Source§

fn nodes(&self) -> NodeIter<'_, Self>
where Self: Sized,

Returns an iterator over all nodes currently managed by this syntax tree. Read more
Source§

fn errors(&self) -> ErrorIter<'_, Self>
where Self: Sized,

Returns an iterator over all syntax errors currently managed by this syntax tree. Read more
Source§

fn traverse_tree(&self, visitor: &mut impl Visitor)
where Self: Sized,

Performs a depth-first traverse of the syntax tree starting from the root node. Read more
Source§

fn traverse_subtree(&self, top: &NodeRef, visitor: &mut impl Visitor)
where Self: Sized,

Performs a depth-first traverse of a branch of the syntax tree. Read more
Source§

impl<N: Node> Eq for ImmutableSyntaxTree<N>

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> 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, 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.