mist_parser/ast/
statement.rs1use serde::Serialize;
2
3use super::*;
4
5#[derive(Debug, Clone, Serialize, Default)]
6pub struct Block(pub Vec<Spanned<Statement>>);
7
8#[derive(Debug, Clone, Serialize)]
9pub enum Statement {
10 Expression(Expression),
11 Block(Block),
12
13 VarDecl(VarDeclStmt),
14 Assign {
15 target: Expression,
16 compound: String,
17 value: Expression,
18 },
19 If {
20 initial: StatementBranch,
21 else_if: Vec<StatementBranch>,
22 else_branch: Option<Box<Statement>>,
23 },
24 While(StatementBranch),
25 CStyleFor {
26 init: Box<Statement>,
27 condition: Expression,
28 update: Box<Statement>,
29 body: Box<Statement>,
30 },
31 For {
32 mutable: bool,
33 pattern: Pattern,
34 iterator: Expression,
35 body: Box<Statement>,
36 },
37 Match(Expression, Vec<(Pattern, Block)>),
38
39 Return(Option<Expression>),
40 Break,
41 Continue,
42
43 Increment(Expression),
44 Decrement(Expression),
45}
46
47#[derive(Debug, Clone, Serialize)]
48pub struct VarDecl {
49 pub mutable: bool,
50 pub name: Pattern,
51 pub type_: Option<TypeExpr>,
52}
53
54#[derive(Debug, Clone, Serialize)]
55pub struct VarDeclStmt {
56 pub decl: VarDecl,
57 pub init: Option<Expression>,
58}
59
60#[derive(Debug, Clone, Serialize)]
61pub struct StatementBranch {
62 pub condition: Expression,
63 pub body: Box<Statement>,
64}