CstNode

Struct CstNode 

Source
pub struct CstNode<K: TokenKind, R: RuleId, N: NodeId> {
    pub kind: CstKind<K, R>,
    pub span: Span,
    pub children: NodeChildren<N>,
}
Expand description

A single CST node stored in the arena.

Fields§

§kind: CstKind<K, R>

Type of node we are storing.

§span: Span

Span covered by the node.

§children: NodeChildren<N>

Children stored by identifier.

Implementations§

Source§

impl<K: TokenKind, R: RuleId, N: NodeId> CstNode<K, R, N>

Source

pub fn new<'fn_lifetime>() -> CstNodeBuilder<'fn_lifetime, K, R, N, (), (), (), (), ()>

Creating a builder.

§Required Fields
§kind
  • Type: CstKind < K, R >

Type of node we are storing.

§span
  • Type: Span

Span covered by the node.

§Optional Fields
§children
  • Type: NodeChildren < N >
  • Default: NodeChildren :: new()

Children stored by identifier.

Source§

impl<K: TokenKind, R: RuleId, N: NodeId> CstNode<K, R, N>

Source

pub fn create( kind: CstKind<K, R>, span: Span, children: NodeChildren<N>, ) -> Self

Create a new CST node.

For builder pattern usage, use CstNodeBuilder::new() instead.

Examples found in repository?
examples/cst_construction.rs (lines 43-47)
36fn main() {
37    println!("=== CST Construction Example ===\n");
38
39    // Create an arena to store nodes
40    let mut arena: NodeArena<Token, Rule, RawNodeId> = NodeArena::new();
41
42    // Create leaf nodes (tokens)
43    let ident_node = CstNode::create(
44        CstKind::Token(Token::Ident),
45        Span::new(0, 1),
46        NodeChildren::new(),
47    );
48    let ident_id = arena.alloc(ident_node);
49    println!("Created ident node: {:?}", ident_id);
50
51    let plus_node = CstNode::create(
52        CstKind::Token(Token::Plus),
53        Span::new(2, 3),
54        NodeChildren::new(),
55    );
56    let plus_id = arena.alloc(plus_node);
57    println!("Created plus node: {:?}", plus_id);
58
59    let number_node = CstNode::create(
60        CstKind::Token(Token::Number),
61        Span::new(4, 5),
62        NodeChildren::new(),
63    );
64    let number_id = arena.alloc(number_node);
65    println!("Created number node: {:?}", number_id);
66
67    // Create a rule node with children
68    let mut children = NodeChildren::new();
69    children.push(ident_id);
70    children.push(plus_id);
71    children.push(number_id);
72
73    let expr_node = CstNode::create(CstKind::Rule(Rule::Expr), Span::new(0, 5), children);
74    let root_id = arena.alloc(expr_node);
75    println!("Created expr node (root): {:?}", root_id);
76
77    println!("\nTotal nodes in arena: {}", arena.len());
78    println!("\n=== Example Complete ===");
79}

Trait Implementations§

Source§

impl<K: Clone + TokenKind, R: Clone + RuleId, N: Clone + NodeId> Clone for CstNode<K, R, N>

Source§

fn clone(&self) -> CstNode<K, R, N>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K: Debug + TokenKind, R: Debug + RuleId, N: Debug + NodeId> Debug for CstNode<K, R, N>

Source§

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

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

impl<K: TokenKind, R: RuleId, N: NodeId> From<&Token<K>> for CstNode<K, R, N>

Source§

fn from(token: &Token<K>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<K, R, N> Freeze for CstNode<K, R, N>
where K: Freeze, R: Freeze, N: Freeze,

§

impl<K, R, N> RefUnwindSafe for CstNode<K, R, N>

§

impl<K, R, N> Send for CstNode<K, R, N>

§

impl<K, R, N> Sync for CstNode<K, R, N>

§

impl<K, R, N> Unpin for CstNode<K, R, N>
where K: Unpin, R: Unpin, N: Unpin,

§

impl<K, R, N> UnwindSafe for CstNode<K, R, N>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.