#[derive(Debug, Clone)]
pub struct Program {
pub items: Vec<Item>,
}
#[derive(Debug, Clone)]
pub enum Item {
Bind(String, Expr),
Fn(FnDef),
Mod(String, Vec<Item>),
TypeAlias(String, String), }
#[derive(Debug, Clone)]
pub struct FnDef {
pub name: String,
pub is_async: bool,
pub params: Vec<String>, pub body: Vec<Stmt>,
}
#[derive(Debug, Clone)]
pub enum Expr {
Str(String),
Number(f64),
Bool(bool),
Unit,
Ident(String),
Do(Vec<Stmt>),
If {
cond: Box<Expr>,
then: Vec<Stmt>,
elseifs: Vec<(Expr, Vec<Stmt>)>,
else_body: Option<Vec<Stmt>>,
},
For {
var: String,
iter: Box<Expr>,
body: Vec<Stmt>,
},
Match(Box<Expr>, Vec<MatchArm>),
Call(Box<Expr>, Vec<Expr>),
MethodCall {
receiver: Box<Expr>,
method: String,
args: Vec<Expr>,
},
Path(Vec<String>),
Range(Box<Expr>, Box<Expr>),
Ref(Box<Expr>),
Await(Box<Expr>),
BinOp(BinOp, Box<Expr>, Box<Expr>),
Array(Vec<Expr>),
Index(Box<Expr>, Box<Expr>),
Closure(Vec<String>, Box<Expr>),
}
#[derive(Debug, Clone, PartialEq)]
pub enum BinOp {
Add, Sub, Mul, Div, Rem,
Eq, Ne, Lt, Gt, Le, Ge,
And, Or,
}
#[derive(Debug, Clone)]
pub enum Stmt {
Bind(String, Expr),
Expr(Expr),
Return(Expr),
}
#[derive(Debug, Clone)]
pub struct MatchArm {
pub pattern: Pattern,
pub body: Expr,
}
#[derive(Debug, Clone)]
pub enum Pattern {
Wildcard,
Str(String),
Number(f64),
Bool(bool),
Ident(String),
Constructor(String, Option<Box<Pattern>>),
}