1#[derive(Debug, Clone)]
4pub struct Program {
5 pub items: Vec<Item>,
6}
7
8#[derive(Debug, Clone)]
9pub enum Item {
10 Bind(String, Expr),
11 Fn(FnDef),
12 Mod(String, Vec<Item>),
13 TypeAlias(String, String), Struct(String, Vec<String>),
17 Enum(String, Vec<EnumVariant>),
20 Use {
22 path: String,
23 alias: Option<String>,
24 },
25}
26
27#[derive(Debug, Clone)]
28pub struct EnumVariant {
29 pub name: String,
30 pub arity: usize,
31}
32
33#[derive(Debug, Clone)]
34pub struct FnDef {
35 pub name: String,
36 pub is_async: bool,
37 pub params: Vec<String>, pub body: Vec<Stmt>,
39}
40
41#[derive(Debug, Clone)]
44pub enum Expr {
45 Str(String),
46 Number(f64),
47 Bool(bool),
48 Unit,
49 Ident(String),
50 Do(Vec<Stmt>),
52 If {
54 cond: Box<Expr>,
55 then: Vec<Stmt>,
56 elseifs: Vec<(Expr, Vec<Stmt>)>,
57 else_body: Option<Vec<Stmt>>,
58 },
59 For {
61 var: String,
62 iter: Box<Expr>,
63 body: Vec<Stmt>,
64 },
65 While {
67 cond: Box<Expr>,
68 body: Vec<Stmt>,
69 },
70 Match(Box<Expr>, Vec<MatchArm>),
72 Call(Box<Expr>, Vec<Expr>),
74 MethodCall {
76 receiver: Box<Expr>,
77 method: String,
78 args: Vec<Expr>,
79 },
80 Path(Vec<String>),
82 Range(Box<Expr>, Box<Expr>),
84 Ref(Box<Expr>),
86 Await(Box<Expr>),
88 BinOp(BinOp, Box<Expr>, Box<Expr>),
90 Array(Vec<Expr>),
92 Index(Box<Expr>, Box<Expr>),
94 Closure(Vec<String>, Box<Expr>),
96}
97
98#[derive(Debug, Clone, PartialEq)]
99pub enum BinOp {
100 Add,
101 Sub,
102 Mul,
103 Div,
104 Rem,
105 Eq,
106 Ne,
107 Lt,
108 Gt,
109 Le,
110 Ge,
111 And,
112 Or,
113}
114
115#[derive(Debug, Clone)]
118pub enum Stmt {
119 Bind(String, Expr),
120 Expr(Expr),
121 Return(Expr),
122}
123
124#[derive(Debug, Clone)]
127pub struct MatchArm {
128 pub pattern: Pattern,
129 pub body: Expr,
130}
131
132#[derive(Debug, Clone)]
133pub enum Pattern {
134 Wildcard,
135 Str(String),
136 Number(f64),
137 Bool(bool),
138 Ident(String),
139 Constructor(String, Option<Box<Pattern>>),
141 Variant(String, Vec<Pattern>),
143}