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), Use { path: String, alias: Option<String> },
16}
17
18#[derive(Debug, Clone)]
19pub struct FnDef {
20 pub name: String,
21 pub is_async: bool,
22 pub params: Vec<String>, pub body: Vec<Stmt>,
24}
25
26#[derive(Debug, Clone)]
29pub enum Expr {
30 Str(String),
31 Number(f64),
32 Bool(bool),
33 Unit,
34 Ident(String),
35 Do(Vec<Stmt>),
37 If {
39 cond: Box<Expr>,
40 then: Vec<Stmt>,
41 elseifs: Vec<(Expr, Vec<Stmt>)>,
42 else_body: Option<Vec<Stmt>>,
43 },
44 For {
46 var: String,
47 iter: Box<Expr>,
48 body: Vec<Stmt>,
49 },
50 While {
52 cond: Box<Expr>,
53 body: Vec<Stmt>,
54 },
55 Match(Box<Expr>, Vec<MatchArm>),
57 Call(Box<Expr>, Vec<Expr>),
59 MethodCall {
61 receiver: Box<Expr>,
62 method: String,
63 args: Vec<Expr>,
64 },
65 Path(Vec<String>),
67 Range(Box<Expr>, Box<Expr>),
69 Ref(Box<Expr>),
71 Await(Box<Expr>),
73 BinOp(BinOp, Box<Expr>, Box<Expr>),
75 Array(Vec<Expr>),
77 Index(Box<Expr>, Box<Expr>),
79 Closure(Vec<String>, Box<Expr>),
81}
82
83#[derive(Debug, Clone, PartialEq)]
84pub enum BinOp {
85 Add, Sub, Mul, Div, Rem,
86 Eq, Ne, Lt, Gt, Le, Ge,
87 And, Or,
88}
89
90#[derive(Debug, Clone)]
93pub enum Stmt {
94 Bind(String, Expr),
95 Expr(Expr),
96 Return(Expr),
97}
98
99#[derive(Debug, Clone)]
102pub struct MatchArm {
103 pub pattern: Pattern,
104 pub body: Expr,
105}
106
107#[derive(Debug, Clone)]
108pub enum Pattern {
109 Wildcard,
110 Str(String),
111 Number(f64),
112 Bool(bool),
113 Ident(String),
114 Constructor(String, Option<Box<Pattern>>),
116}