cairo_lang_syntax/node/
green.rs

1use cairo_lang_filesystem::span::TextWidth;
2use smol_str::SmolStr;
3
4use super::ids::GreenId;
5use super::kind::SyntaxKind;
6
7#[derive(Clone, Debug, Hash, PartialEq, Eq)]
8pub enum GreenNodeDetails {
9    Token(SmolStr),
10    Node { children: Vec<GreenId>, width: TextWidth },
11}
12/// Green node. Underlying untyped representation of the syntax tree.
13#[derive(Clone, Debug, Hash, PartialEq, Eq)]
14pub struct GreenNode {
15    pub kind: SyntaxKind,
16    pub details: GreenNodeDetails,
17}
18impl GreenNode {
19    pub fn width(&self) -> TextWidth {
20        match &self.details {
21            GreenNodeDetails::Token(text) => TextWidth::from_str(text),
22            GreenNodeDetails::Node { width, .. } => *width,
23        }
24    }
25    pub fn children(&self) -> &[GreenId] {
26        match &self.details {
27            GreenNodeDetails::Token(_text) => &[],
28            GreenNodeDetails::Node { children, .. } => children,
29        }
30    }
31}