factorio_ir/ast/statement.rs
1use crate::ast::{
2 enumeration::Enum, expression::Expression, function::Function, structure::Struct, r#type::Type,
3};
4
5#[derive(Debug, Clone, PartialEq)]
6pub enum Statement {
7 FunctionDecl(Function),
8 StructDecl(Struct),
9 EnumDecl(Enum),
10 VariableDecl {
11 name: String,
12 ty: Type,
13 source_type: Option<String>,
14 value: Expression,
15 },
16 Assignment {
17 target: Expression,
18 value: Expression,
19 },
20 Conditional {
21 condition: Expression,
22 then_block: Vec<Self>,
23 else_block: Vec<Self>,
24 },
25 Return(Option<Expression>),
26 Expr(Expression),
27 /// `for _, VAR in pairs/ipairs(ITER) do BODY end` in Lua.
28 ForIn {
29 var: String,
30 iter: Expression,
31 body: Vec<Self>,
32 /// When true, emit `ipairs` (ordered); otherwise `pairs`.
33 ipairs: bool,
34 },
35 /// `for VAR = START, LIMIT do BODY end` in Lua (inclusive limit, step 1).
36 ForNumeric {
37 var: String,
38 start: Expression,
39 limit: Expression,
40 body: Vec<Self>,
41 },
42 /// `while CONDITION do BODY end` in Lua. Rust `loop { }` lowers with
43 /// `condition = true`.
44 While {
45 condition: Expression,
46 body: Vec<Self>,
47 },
48 /// `goto __continue_N` in Lua (the label `::__continue_N::` is emitted by
49 /// the enclosing `ForIn` / `ForNumeric` / `While`).
50 Continue,
51 /// Lua `break` (exits the innermost loop).
52 Break,
53 /// Verbatim Lua source emitted as-is (from `lua! { ... }` in unsafe context).
54 ///
55 /// Each line of `code` is emitted with the current generator indent prefix.
56 /// The optimizer and pruner treat this variant as fully opaque.
57 RawLua {
58 code: String,
59 },
60}