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