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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#[derive(Clone, Debug)]
pub enum Expr {
Number(isize),
Op(Box<Expr>, String, Box<Expr>),
Ref(Ident),
Do(Vec<DoItem>, Where),
Parens(Vec<Expr>),
Case(Box<Expr>, Vec<CaseCond>),
Generator(Vec<Expr>, Vec<()>),
Let(Vec<Assignment>, Box<Expr>),
Span(Vec<Expr>),
Vector(Vec<Expr>),
Operator(String),
Record(Box<Expr>, Vec<(Ident, Expr)>),
Lambda(Vec<Pat>, Box<Expr>),
Str(String),
Char(String),
If(Box<Expr>, Box<Expr>, Option<Box<Expr>>),
RecordArgs(Vec<(Ident, Expr)>),
Error,
}
#[derive(Clone, Debug)]
pub enum Assignment {
Assign {
pats: Vec<Pat>,
expr: Expr,
},
Case {
pats: Vec<Pat>,
sets: Vec<(Vec<(Expr, Option<Expr>)>, Expr)>,
}
}
#[derive(Clone, Debug)]
pub enum CaseCond {
Matching(Vec<Pat>, Vec<(Vec<Expr>, Expr)>),
Direct(Vec<Pat>, Vec<Expr>),
}
#[derive(Copy, Clone, Debug)]
pub enum Opcode {
Mul,
Div,
Add,
Sub,
}
#[derive(Clone, Debug)]
pub enum Item {
Import(Vec<Vec<Ident>>),
Data(Ident, Vec<Vec<Ty>>, Vec<Ident>, Vec<Ty>),
Newtype(Ident, Ty, Vec<Ident>, Vec<Ty>),
Type(Ident, Vec<Ty>, Vec<Ty>),
Class,
Instance,
Prototype(Vec<Ident>, Vec<Ty>),
Assign(Box<Assignment>, Where),
GuardAssign,
Infixr(isize, Ident),
Infixl(isize, Ident),
}
pub type Where = Vec<Item>;
#[derive(Clone, Debug)]
pub enum DoItem {
Let(Vec<Assignment>),
Bind(Vec<Pat>, Box<Expr>),
Expression(Box<Expr>),
}
#[derive(Clone, Debug)]
pub struct Module {
pub name: Ident,
pub items: Where,
}
#[derive(Clone, Debug)]
pub enum Ty {
Span(Vec<Ty>),
Pair(Box<Ty>, Box<Ty>),
Not(Box<Ty>),
Ref(Ident),
Tuple(Vec<Ty>),
Brackets(Box<Ty>),
Record(Vec<(Ident, Ty)>),
EmptyParen,
RangeOp,
Dummy,
}
#[derive(Clone, Debug)]
pub enum Pat {
Span(Vec<Pat>),
ViewPattern(Ident, Box<Pat>),
Not(Box<Pat>),
Ref(Ident),
Infix(Ident),
Tuple(Vec<Pat>),
Brackets(Vec<Pat>),
Record(Ident, Vec<(Ident, Pat)>),
Operator(String),
Str(String),
Char(String),
Num(isize),
Concat(Box<Pat>, Box<Pat>),
EmptyParen,
}
#[derive(Clone, Debug)]
pub struct Ident(pub String);