lust/ast/
stmt.rs

1use super::{Expr, Span, Type};
2#[derive(Debug, Clone, PartialEq)]
3pub struct Stmt {
4    pub kind: StmtKind,
5    pub span: Span,
6}
7
8impl Stmt {
9    pub fn new(kind: StmtKind, span: Span) -> Self {
10        Self { kind, span }
11    }
12}
13
14#[derive(Debug, Clone, PartialEq)]
15pub struct LocalBinding {
16    pub name: String,
17    pub type_annotation: Option<Type>,
18    pub span: Span,
19}
20
21#[derive(Debug, Clone, PartialEq)]
22pub enum StmtKind {
23    Local {
24        bindings: Vec<LocalBinding>,
25        mutable: bool,
26        initializer: Option<Vec<Expr>>,
27    },
28    Assign {
29        targets: Vec<Expr>,
30        values: Vec<Expr>,
31    },
32    CompoundAssign {
33        target: Expr,
34        op: super::expr::BinaryOp,
35        value: Expr,
36    },
37    Expr(Expr),
38    If {
39        condition: Expr,
40        then_block: Vec<Stmt>,
41        elseif_branches: Vec<(Expr, Vec<Stmt>)>,
42        else_block: Option<Vec<Stmt>>,
43    },
44    While {
45        condition: Expr,
46        body: Vec<Stmt>,
47    },
48    ForNumeric {
49        variable: String,
50        start: Expr,
51        end: Expr,
52        step: Option<Expr>,
53        body: Vec<Stmt>,
54    },
55    ForIn {
56        variables: Vec<String>,
57        iterator: Expr,
58        body: Vec<Stmt>,
59    },
60    Return(Vec<Expr>),
61    Break,
62    Continue,
63    Block(Vec<Stmt>),
64}