Skip to main content

oak_apl/ast/
mod.rs

1#![doc = include_str!("readme.md")]
2/// Root node of the APL syntax tree.
3#[derive(Debug, Clone, PartialEq, Eq)]
4pub struct AplRoot {
5    /// Items in this APL file.
6    pub items: Vec<AplItem>,
7}
8
9impl AplRoot {
10    /// Creates a new APL root node.
11    pub fn new(items: Vec<AplItem>) -> Self {
12        Self { items }
13    }
14
15    /// Gets all top-level items in this APL file.
16    pub fn items(&self) -> &[AplItem] {
17        &self.items
18    }
19}
20
21/// Item in an APL file.
22#[derive(Debug, Clone, PartialEq, Eq)]
23pub enum AplItem {
24    /// Assignment.
25    Assignment(AplAssignment),
26    /// Expression.
27    Expression(String),
28}
29
30/// APL assignment.
31#[derive(Debug, Clone, PartialEq, Eq)]
32pub struct AplAssignment {
33    /// Variable name.
34    pub name: String,
35    /// Expression.
36    pub expression: String,
37}
38
39impl AplAssignment {
40    /// Creates a new assignment.
41    pub fn new(name: String, expression: String) -> Self {
42        Self { name, expression }
43    }
44}