Struct rowan::GreenNodeBuilder
source · pub struct GreenNodeBuilder<'cache> { /* private fields */ }
Expand description
A builder for a green tree.
Implementations§
source§impl GreenNodeBuilder<'_>
impl GreenNodeBuilder<'_>
sourcepub fn new() -> GreenNodeBuilder<'static>
pub fn new() -> GreenNodeBuilder<'static>
Creates new builder.
sourcepub fn with_cache(cache: &mut NodeCache) -> GreenNodeBuilder<'_>
pub fn with_cache(cache: &mut NodeCache) -> GreenNodeBuilder<'_>
Reusing NodeCache
between different GreenNodeBuilder
s saves memory.
It allows to structurally share underlying trees.
sourcepub fn token(&mut self, kind: SyntaxKind, text: &str)
pub fn token(&mut self, kind: SyntaxKind, text: &str)
Adds new token to the current branch.
sourcepub fn start_node(&mut self, kind: SyntaxKind)
pub fn start_node(&mut self, kind: SyntaxKind)
Start new node and make it current.
sourcepub fn finish_node(&mut self)
pub fn finish_node(&mut self)
Finish current branch and restore previous branch as current.
sourcepub fn checkpoint(&self) -> Checkpoint
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();
}
sourcepub fn start_node_at(&mut self, checkpoint: Checkpoint, kind: SyntaxKind)
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.
Trait Implementations§
source§impl<'cache> Debug for GreenNodeBuilder<'cache>
impl<'cache> Debug for GreenNodeBuilder<'cache>
source§impl<'cache> Default for GreenNodeBuilder<'cache>
impl<'cache> Default for GreenNodeBuilder<'cache>
source§fn default() -> GreenNodeBuilder<'cache>
fn default() -> GreenNodeBuilder<'cache>
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl<'cache> Freeze for GreenNodeBuilder<'cache>
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> 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