1#[derive(Debug, Clone, PartialEq)]
8pub enum Type {
9 I8,
11 I16,
12 I32,
13 I64,
14 I128,
15 U8,
16 U16,
17 U32,
18 U64,
19 U128,
20 F32,
22 F64,
23 Bool,
25 Char,
26 String,
27 Usize,
28 Isize,
29 Array(Box<Type>, Option<usize>),
31 Vec(Box<Type>),
32 Tuple(Vec<Type>),
33 Option(Box<Type>),
34 Custom(String),
35 Unit,
36 Inferred,
37 Reference(Box<Type>, bool),
39}
40
41#[derive(Debug, Clone)]
46pub enum Expr {
47 IntLiteral(i64),
49 FloatLiteral(f64),
50 StringLiteral(String),
51 CharLiteral(char),
52 BoolLiteral(bool),
53
54 Ident(String),
56
57 BinaryOp {
59 left: Box<Expr>,
60 op: BinOp,
61 right: Box<Expr>,
62 },
63
64 UnaryOp {
66 op: UnaryOp,
67 expr: Box<Expr>,
68 },
69
70 Assign {
73 target: Box<Expr>,
74 value: Box<Expr>,
75 },
76
77 CompoundAssign {
79 target: Box<Expr>,
80 op: BinOp,
81 value: Box<Expr>,
82 },
83
84 Let {
86 name: String,
87 mutable: bool,
88 type_ann: Option<Type>,
89 value: Option<Box<Expr>>,
90 },
91
92 Block(Vec<Expr>),
95
96 If {
98 condition: Box<Expr>,
99 then_block: Box<Expr>,
100 else_block: Option<Box<Expr>>,
101 },
102
103 While {
105 condition: Box<Expr>,
106 body: Box<Expr>,
107 },
108
109 Loop {
111 body: Box<Expr>,
112 },
113
114 For {
116 var: String,
117 iterator: Box<Expr>,
118 body: Box<Expr>,
119 },
120
121 Range {
123 start: Option<Box<Expr>>,
124 end: Option<Box<Expr>>,
125 inclusive: bool,
126 },
127
128 Break(Option<Box<Expr>>),
130 Continue,
131
132 Return(Option<Box<Expr>>),
134
135 FnDef {
138 name: String,
139 params: Vec<(String, Type)>,
140 return_type: Option<Type>,
141 body: Box<Expr>,
142 },
143
144 FnCall {
146 name: String,
147 args: Vec<Expr>,
148 },
149
150 MethodCall {
152 object: Box<Expr>,
153 method: String,
154 args: Vec<Expr>,
155 },
156
157 MacroCall {
159 name: String,
160 args: Vec<Expr>,
161 },
162
163 ArrayLiteral(Vec<Expr>),
166
167 ArrayRepeat {
169 value: Box<Expr>,
170 count: Box<Expr>,
171 },
172
173 TupleLiteral(Vec<Expr>),
175
176 Index {
178 object: Box<Expr>,
179 index: Box<Expr>,
180 },
181
182 FieldAccess {
184 object: Box<Expr>,
185 field: String,
186 },
187
188 StructDef {
191 name: String,
192 fields: Vec<(String, Type)>,
193 },
194
195 StructInit {
197 name: String,
198 fields: Vec<(String, Expr)>,
199 },
200
201 Match {
204 expr: Box<Expr>,
205 arms: Vec<MatchArm>,
206 },
207
208 TypeCast {
211 expr: Box<Expr>,
212 target_type: Type,
213 },
214
215 Closure {
218 params: Vec<(String, Option<Type>)>,
219 body: Box<Expr>,
220 },
221
222 Ref {
224 expr: Box<Expr>,
225 mutable: bool,
226 },
227
228 Deref(Box<Expr>),
230
231 VecMacro(Vec<Expr>),
233
234 Unit,
236}
237
238#[derive(Debug, Clone, PartialEq)]
240pub enum BinOp {
241 Add,
242 Sub,
243 Mul,
244 Div,
245 Mod,
246 Eq,
247 NotEq,
248 Lt,
249 LtEq,
250 Gt,
251 GtEq,
252 And,
253 Or,
254 BitAnd,
255 BitOr,
256 BitXor,
257 Shl,
258 Shr,
259}
260
261#[derive(Debug, Clone, PartialEq)]
263pub enum UnaryOp {
264 Neg,
265 Not,
266}
267
268#[derive(Debug, Clone)]
270pub struct MatchArm {
271 pub pattern: Pattern,
272 pub body: Expr,
273}
274
275#[derive(Debug, Clone)]
277pub enum Pattern {
278 Literal(Expr),
279 Ident(String),
280 Wildcard,
281 Range {
282 start: Box<Expr>,
283 end: Box<Expr>,
284 inclusive: bool,
285 },
286 Or(Vec<Pattern>),
287}