pub struct TreeBuilder { /* private fields */ }Expand description
Builds a SyntaxTree as the parser walks the token stream.
Children accumulate in one flat buffer; closing a node drains its slice out
of that buffer into the arena. This keeps TreeBuilder::checkpoint O(1),
which matters because the Pratt expression parser takes one per operand.
Implementations§
Source§impl TreeBuilder
impl TreeBuilder
pub fn new() -> Self
pub fn start_node(&mut self, kind: SyntaxKind)
pub fn checkpoint(&self) -> Checkpoint
Sourcepub fn start_node_at(&mut self, checkpoint: Checkpoint, kind: SyntaxKind)
pub fn start_node_at(&mut self, checkpoint: Checkpoint, kind: SyntaxKind)
Open a node that retroactively contains everything added since
checkpoint.
pub fn token(&mut self, token: Token)
pub fn finish_node(&mut self)
Sourcepub fn finish(self, source: String, errors: Vec<SyntaxError>) -> SyntaxTree
pub fn finish(self, source: String, errors: Vec<SyntaxError>) -> SyntaxTree
Close the builder, producing the finished tree.
§Panics
Panics if any node is still open, or if the builder produced anything other than exactly one root node.
Trait Implementations§
Source§impl Debug for TreeBuilder
impl Debug for TreeBuilder
Auto Trait Implementations§
impl Freeze for TreeBuilder
impl RefUnwindSafe for TreeBuilder
impl Send for TreeBuilder
impl Sync for TreeBuilder
impl Unpin for TreeBuilder
impl UnsafeUnpin for TreeBuilder
impl UnwindSafe for TreeBuilder
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