shape_ast/ast/
statements.rs1use serde::{Deserialize, Serialize};
4
5use super::expressions::Expr;
6use super::program::{Assignment, VariableDecl};
7use super::span::Span;
8use super::types::{ExtendStatement, TypeAnnotation};
9
10#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11pub enum Statement {
12 Return(Option<Expr>, Span),
14 Break(Span),
16 Continue(Span),
18 VariableDecl(VariableDecl, Span),
20 Assignment(Assignment, Span),
22 Expression(Expr, Span),
24 For(ForLoop, Span),
26 While(WhileLoop, Span),
28 If(IfStatement, Span),
30 Extend(ExtendStatement, Span),
32 RemoveTarget(Span),
34 SetParamType {
36 param_name: String,
37 type_annotation: TypeAnnotation,
38 span: Span,
39 },
40 SetParamValue {
42 param_name: String,
43 expression: Expr,
44 span: Span,
45 },
46 SetReturnType {
48 type_annotation: TypeAnnotation,
49 span: Span,
50 },
51 SetReturnExpr { expression: Expr, span: Span },
54 ReplaceBody { body: Vec<Statement>, span: Span },
56 ReplaceBodyExpr { expression: Expr, span: Span },
59 ReplaceModuleExpr { expression: Expr, span: Span },
62}
63
64#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
65pub struct ForLoop {
66 pub init: ForInit,
68 pub body: Vec<Statement>,
70 pub is_async: bool,
72}
73
74#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
75pub enum ForInit {
76 ForIn {
78 pattern: super::patterns::DestructurePattern,
79 iter: Expr,
80 },
81 ForC {
83 init: Box<Statement>,
84 condition: Expr,
85 update: Expr,
86 },
87}
88
89#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
90pub struct WhileLoop {
91 pub condition: Expr,
92 pub body: Vec<Statement>,
93}
94
95#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
96pub struct IfStatement {
97 pub condition: Expr,
98 pub then_body: Vec<Statement>,
99 pub else_body: Option<Vec<Statement>>,
100}
101
102#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
104pub struct Block {
105 pub statements: Vec<Statement>,
106}