Skip to main content

oak_racket/ast/
mod.rs

1/// Expression types in the Racket AST.
2#[derive(Debug, PartialEq, Eq, Clone)]
3pub enum Expression {
4    /// Identifier expression.
5    Identifier(String),
6    /// Number literal expression.
7    Number(String),
8    /// String literal expression.
9    String(String),
10    /// Boolean literal expression.
11    Boolean(bool),
12
13    /// Binary expression with left operand, operator, and right operand.
14    BinaryExpression(Box<BinaryExpression>),
15    /// Unary expression with operator and operand.
16    UnaryExpression(Box<UnaryExpression>),
17    /// Function call expression.
18    Call(Box<Call>),
19    /// Index access expression.
20    Index(Box<Index>),
21    /// Tuple expression.
22    Tuple(Vec<Expression>),
23    /// List expression.
24    List(Vec<Expression>),
25    /// Map/dictionary expression.
26    Map(Vec<(Expression, Expression)>),
27
28    /// For loop expression.
29    For(Box<For>),
30
31    /// List comprehension expression.
32    ListComprehension(Box<ListComprehension>),
33}
34
35/// Binary expression with left operand, operator, and right operand.
36#[derive(Debug, PartialEq, Eq, Clone)]
37pub struct BinaryExpression {
38    /// Left operand of the binary expression.
39    pub left: Expression,
40    /// Operator of the binary expression.
41    pub operator: String,
42    /// Right operand of the binary expression.
43    pub right: Expression,
44}
45
46/// Unary expression with operator and operand.
47#[derive(Debug, PartialEq, Eq, Clone)]
48pub struct UnaryExpression {
49    /// Operator of the unary expression.
50    pub operator: String,
51    /// Operand of the unary expression.
52    pub expression: Expression,
53}
54
55/// Function call expression.
56#[derive(Debug, PartialEq, Eq, Clone)]
57pub struct Call {
58    /// Function being called.
59    pub function: Expression,
60    /// Arguments passed to the function.
61    pub arguments: Vec<Expression>,
62}
63
64/// Index access expression.
65#[derive(Debug, PartialEq, Eq, Clone)]
66pub struct Index {
67    /// Expression being indexed.
68    pub expression: Expression,
69    /// Index value.
70    pub index: Expression,
71}
72
73/// For loop expression.
74#[derive(Debug, PartialEq, Eq, Clone)]
75pub struct For {
76    /// Loop variable name.
77    pub variable: String,
78    /// Iterable expression.
79    pub iterable: Expression,
80    /// Loop body expressions.
81    pub body: Vec<Expression>,
82}
83
84/// List comprehension expression.
85#[derive(Debug, PartialEq, Eq, Clone)]
86pub struct ListComprehension {
87    /// Output expression.
88    pub expression: Expression,
89    /// Loop variable name.
90    pub variable: String,
91    /// Iterable expression.
92    pub iterable: Expression,
93    /// Optional filter condition.
94    pub condition: Option<Expression>,
95}