Struct rowan::GreenNodeBuilder

source ·
pub struct GreenNodeBuilder<'cache> { /* private fields */ }
Expand description

A builder for a green tree.

Implementations§

source§

impl GreenNodeBuilder<'_>

source

pub fn new() -> GreenNodeBuilder<'static>

Creates new builder.

source

pub fn with_cache(cache: &mut NodeCache) -> GreenNodeBuilder<'_>

Reusing NodeCache between different GreenNodeBuilders saves memory. It allows to structurally share underlying trees.

source

pub fn token(&mut self, kind: SyntaxKind, text: &str)

Adds new token to the current branch.

source

pub fn start_node(&mut self, kind: SyntaxKind)

Start new node and make it current.

source

pub fn finish_node(&mut self)

Finish current branch and restore previous branch as current.

source

pub fn checkpoint(&self) -> Checkpoint

Prepare for maybe wrapping the next node. The way wrapping works is that you first of all get a checkpoint, then you place all tokens you want to wrap, and then maybe call start_node_at. Example:

let checkpoint = builder.checkpoint();
parser.parse_expr();
if parser.peek() == Some(PLUS) {
  // 1 + 2 = Add(1, 2)
  builder.start_node_at(checkpoint, OPERATION);
  parser.parse_expr();
  builder.finish_node();
}
source

pub fn start_node_at(&mut self, checkpoint: Checkpoint, kind: SyntaxKind)

Wrap the previous branch marked by checkpoint in a new branch and make it current.

source

pub fn finish(self) -> GreenNode

Complete tree building. Make sure that start_node_at and finish_node calls are paired!

Trait Implementations§

source§

impl<'cache> Debug for GreenNodeBuilder<'cache>

source§

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

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

impl<'cache> Default for GreenNodeBuilder<'cache>

source§

fn default() -> GreenNodeBuilder<'cache>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'cache> RefUnwindSafe for GreenNodeBuilder<'cache>

§

impl<'cache> Send for GreenNodeBuilder<'cache>

§

impl<'cache> Sync for GreenNodeBuilder<'cache>

§

impl<'cache> Unpin for GreenNodeBuilder<'cache>

§

impl<'cache> !UnwindSafe for GreenNodeBuilder<'cache>

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

§

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

§

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.