pub struct GreenNode<'a, L: Language> {
pub kind: L::ElementType,
pub children: &'a [GreenTree<'a, L>],
pub byte_length: u32,
}Expand description
A green node that contains child elements.
Green nodes are allocated in a SyntaxArena and hold a slice reference
to their children. They are POD (Plain Old Data) and strictly immutable.
Unlike red nodes, green nodes do not know their absolute position in the source code, which makes them highly reusable for incremental parsing.
Fields§
§kind: L::ElementTypeThe element type (kind) of this node.
children: &'a [GreenTree<'a, L>]The children of this node, which can be other nodes or leaf tokens.
byte_length: u32The total text length of this node (sum of children’s lengths) in bytes.
Implementations§
Source§impl<'a, L: Language> GreenNode<'a, L>
impl<'a, L: Language> GreenNode<'a, L>
Sourcepub fn new(kind: L::ElementType, children: &'a [GreenTree<'a, L>]) -> Self
pub fn new(kind: L::ElementType, children: &'a [GreenTree<'a, L>]) -> Self
Creates a new green node from child elements.
This function assumes the children slice is already allocated in the arena.
It automatically calculates the total text_len by summing child lengths.
§Arguments
kind- The node type.children- The slice of child elements.
Sourcepub fn kind(&self) -> L::ElementType
pub fn kind(&self) -> L::ElementType
Returns the kind of this node.
Sourcepub fn child_at(&self, index: usize) -> Option<&'a GreenTree<'a, L>>
pub fn child_at(&self, index: usize) -> Option<&'a GreenTree<'a, L>>
Returns a specific child at index.
Returns None if the index is out of bounds.
Sourcepub fn has_children(&self) -> bool
pub fn has_children(&self) -> bool
Checks if this node has any children.
Sourcepub fn children_count(&self) -> usize
pub fn children_count(&self) -> usize
Returns the number of children in this node.