1use serde::{Deserialize, Serialize};
4
5use super::expressions::Expr;
6use super::functions::Annotation;
7use super::patterns::{DestructurePattern, Pattern};
8use super::program::VariableDecl;
9use super::span::Span;
10use super::types::TypeAnnotation;
11
12#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14pub struct BlockExpr {
15 pub items: Vec<BlockItem>,
17}
18
19#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
21pub enum BlockItem {
22 VariableDecl(VariableDecl),
24 Assignment(super::program::Assignment),
26 Statement(super::statements::Statement),
28 Expression(Expr),
30}
31
32#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
34pub struct IfExpr {
35 pub condition: Box<Expr>,
36 pub then_branch: Box<Expr>,
37 pub else_branch: Option<Box<Expr>>, }
39
40#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
42pub struct WhileExpr {
43 pub condition: Box<Expr>,
44 pub body: Box<Expr>,
45}
46
47#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
49pub struct ForExpr {
50 pub pattern: Pattern,
51 pub iterable: Box<Expr>,
52 pub body: Box<Expr>,
53 pub is_async: bool,
55}
56
57#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
59pub struct ListComprehension {
60 pub element: Box<Expr>,
62 pub clauses: Vec<ComprehensionClause>,
64}
65
66#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
68pub struct ComprehensionClause {
69 pub pattern: DestructurePattern,
71 pub iterable: Box<Expr>,
73 pub filter: Option<Box<Expr>>,
75}
76
77#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
79pub struct LoopExpr {
80 pub body: Box<Expr>,
81}
82
83#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
85pub struct LetExpr {
86 pub pattern: Pattern,
87 pub type_annotation: Option<TypeAnnotation>,
88 pub value: Option<Box<Expr>>,
89 pub body: Box<Expr>, }
91
92#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
94pub struct AssignExpr {
95 pub target: Box<Expr>, pub value: Box<Expr>,
97}
98
99#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
101pub struct MatchExpr {
102 pub scrutinee: Box<Expr>,
103 pub arms: Vec<MatchArm>,
104}
105
106#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
108pub struct MatchArm {
109 pub pattern: Pattern,
110 pub guard: Option<Box<Expr>>,
111 pub body: Box<Expr>,
112 pub pattern_span: Option<super::Span>,
114}
115
116#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
119pub struct FromQueryExpr {
120 pub variable: String,
122 pub source: Box<Expr>,
124 pub clauses: Vec<QueryClause>,
126 pub select: Box<Expr>,
128}
129
130#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
132pub enum QueryClause {
133 Where(Box<Expr>),
135
136 OrderBy(Vec<OrderBySpec>),
138
139 GroupBy {
141 element: Box<Expr>,
142 key: Box<Expr>,
143 into_var: Option<String>,
144 },
145
146 Join {
148 variable: String,
149 source: Box<Expr>,
150 left_key: Box<Expr>,
151 right_key: Box<Expr>,
152 into_var: Option<String>,
153 },
154
155 Let { variable: String, value: Box<Expr> },
157}
158
159#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
161pub struct OrderBySpec {
162 pub key: Box<Expr>,
163 pub descending: bool,
164}
165
166#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
168pub enum JoinKind {
169 All = 0,
171 Race = 1,
173 Any = 2,
175 Settle = 3,
177}
178
179#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
181pub struct JoinBranch {
182 pub label: Option<String>,
184 pub expr: Expr,
186 pub annotations: Vec<Annotation>,
188}
189
190#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
193pub struct AsyncLetExpr {
194 pub name: String,
196 pub expr: Box<Expr>,
198 pub span: Span,
200}
201
202#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
204pub struct JoinExpr {
205 pub kind: JoinKind,
207 pub branches: Vec<JoinBranch>,
209 pub span: Span,
211}
212
213#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
217pub struct ComptimeForExpr {
218 pub variable: String,
220 pub iterable: Box<Expr>,
222 pub body: Vec<super::statements::Statement>,
224}