Skip to main content

factorio_ir/ast/
statement.rs

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