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 SetReturnType {
42 type_annotation: TypeAnnotation,
43 span: Span,
44 },
45 SetReturnExpr { expression: Expr, span: Span },
48 ReplaceBody { body: Vec<Statement>, span: Span },
50 ReplaceBodyExpr { expression: Expr, span: Span },
53 ReplaceModuleExpr { expression: Expr, span: Span },
56}
57
58#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
59pub struct ForLoop {
60 pub init: ForInit,
62 pub body: Vec<Statement>,
64 pub is_async: bool,
66}
67
68#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
69pub enum ForInit {
70 ForIn {
72 pattern: super::patterns::DestructurePattern,
73 iter: Expr,
74 },
75 ForC {
77 init: Box<Statement>,
78 condition: Expr,
79 update: Expr,
80 },
81}
82
83#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
84pub struct WhileLoop {
85 pub condition: Expr,
86 pub body: Vec<Statement>,
87}
88
89#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
90pub struct IfStatement {
91 pub condition: Expr,
92 pub then_body: Vec<Statement>,
93 pub else_body: Option<Vec<Statement>>,
94}
95
96#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
98pub struct Block {
99 pub statements: Vec<Statement>,
100}