Skip to main content

factorio_ir/
expression.rs

1use crate::{literal::Literal, operator::Operator};
2
3#[derive(Debug, PartialEq, Clone)]
4pub enum Expression {
5    Literal(Literal),
6    Identifier(String),
7    QualifiedPath {
8        segments: Vec<String>,
9    },
10    FieldAccess {
11        base: Box<Self>,
12        field: String,
13    },
14    Call {
15        func: Box<Self>,
16        args: Vec<Self>,
17    },
18    MethodCall {
19        receiver: Box<Self>,
20        method: String,
21        args: Vec<Self>,
22    },
23    StructLiteral {
24        /// The Rust struct name that produced this literal, used by codegen to inject
25        /// fixed Factorio prototype fields (e.g. `type = "bool-setting"`).
26        struct_name: Option<String>,
27        fields: Vec<(String, Self)>,
28    },
29    /// An operation between a `lhs` and a `rhs` with an [`Operator`]
30    BinaryOp {
31        lhs: Box<Self>,
32        op: Operator,
33        rhs: Box<Self>,
34    },
35    /// String interpolation parts joined with `..` in Lua.
36    FormatConcat {
37        parts: Vec<Self>,
38    },
39    /// Lua array literal `{ a, b, c }`.
40    Array {
41        elements: Vec<Self>,
42    },
43    /// Lua table index expression `base[key]`.
44    Index {
45        base: Box<Self>,
46        key: Box<Self>,
47    },
48    /// Logical `not EXPR` in Lua.
49    Not(Box<Self>),
50    /// Length operator `#EXPR` in Lua.
51    Len(Box<Self>),
52}