Skip to main content

glint/
ast.rs

1#![allow(dead_code)]
2
3#[derive(Debug, Clone, Copy, PartialEq)]
4pub enum NodeId {
5    Element(u32),
6    Directive(u32),
7}
8
9#[derive(Debug, Clone, PartialEq)]
10pub enum Value {
11    String(String),
12    Int(i64),
13    Float(f64),
14    Bool(bool),
15    Color(String),
16    FsPath(String),
17    Variable(String),
18    Rhei(String),
19}
20
21#[derive(Debug, Clone)]
22pub enum Directive {
23    Version(i64),
24    Style(String),
25    Global {
26        name: String,
27        value: Value,
28    },
29    Singleton {
30        name: String,
31        prop_span: (u32, u32),
32    },
33    Component {
34        name: String,
35        params: Vec<(String, String)>,
36        child_span: (u32, u32),
37    },
38    Let {
39        name: String,
40        value: Value,
41    },
42    If {
43        condition: Value,
44        child_span: (u32, u32),
45        else_span: Option<(u32, u32)>,
46    },
47    Each {
48        item: String,
49        collection: Value,
50        child_span: (u32, u32),
51    },
52    On {
53        event: String,
54        args: Vec<(String, Value)>,
55        child_span: (u32, u32),
56    },
57    RheiBlock(String),
58}
59
60#[derive(Debug, Default)]
61pub struct ModuleSoA {
62    pub elem_types: Vec<String>,
63    pub elem_prop_spans: Vec<(u32, u32)>,
64    pub elem_child_spans: Vec<(u32, u32)>,
65    pub elem_content: Vec<Option<Value>>,
66
67    pub prop_keys: Vec<String>,
68    pub prop_values: Vec<Value>,
69
70    pub directives: Vec<Directive>,
71
72    pub hierarchy: Vec<NodeId>,
73}
74
75impl ModuleSoA {
76    pub fn new() -> Self {
77        Self::default()
78    }
79
80    pub fn push_element(&mut self, typ: String) -> u32 {
81        let id = self.elem_types.len() as u32;
82        self.elem_types.push(typ);
83        self.elem_prop_spans.push((0, 0));
84        self.elem_child_spans.push((0, 0));
85        self.elem_content.push(None);
86        id
87    }
88
89    pub fn push_directive(&mut self, dir: Directive) -> u32 {
90        let id = self.directives.len() as u32;
91        self.directives.push(dir);
92        id
93    }
94}