1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use crate::{Expression, Type};
#[derive(Debug, PartialEq)]
pub enum Statement {
Let {
identifier: String,
r#type: Option<Type>,
initial: Expression,
},
Function {
identifier: String,
parameters: Vec<Parameter>,
return_type: Option<Type>,
body: Vec<Statement>,
},
If {
condition: Expression,
then: Vec<Statement>,
otherwise: Vec<Statement>,
},
While {
condition: Expression,
then: Vec<Statement>,
},
Return {
expression: Expression,
},
Expression {
expression: Expression,
}
}
#[derive(Debug, PartialEq)]
pub struct Parameter {
name: String,
r#type: Option<Type>,
}
impl Parameter {
pub fn new(name: impl Into<String>, r#type: Option<Type>) -> Self {
Self { name: name.into(), r#type }
}
}