2023-04-01 22:34:35 -07:00
|
|
|
use crate::syn::Spanned;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub enum Stmt {
|
2023-04-02 01:55:51 -07:00
|
|
|
Assign(SpAssignLhs, SpExpr),
|
2023-04-01 22:34:35 -07:00
|
|
|
Expr(SpExpr),
|
|
|
|
|
If {
|
|
|
|
|
if_true: SpCondExpr,
|
|
|
|
|
elseif: Vec<SpCondExpr>,
|
|
|
|
|
else_expr: Option<SpExpr>,
|
|
|
|
|
},
|
|
|
|
|
Def {
|
|
|
|
|
name: String,
|
|
|
|
|
params: Vec<SpParam>,
|
|
|
|
|
body: Vec<SpStmt>,
|
|
|
|
|
},
|
|
|
|
|
Import {
|
|
|
|
|
target: String,
|
|
|
|
|
from: Option<String>,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-02 01:55:51 -07:00
|
|
|
pub type SpAssignLhs = Spanned<AssignLhs>;
|
|
|
|
|
|
2023-04-01 22:34:35 -07:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub enum AssignLhs {
|
|
|
|
|
/// A simple assignment.
|
|
|
|
|
///
|
|
|
|
|
/// `x = foo`
|
|
|
|
|
Name(String),
|
|
|
|
|
|
|
|
|
|
/// A more complex assignment.
|
|
|
|
|
///
|
|
|
|
|
/// `x().bar = foo`
|
|
|
|
|
Complex(SpExpr, String),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub type SpStmt = Spanned<Stmt>;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct CondExpr {
|
|
|
|
|
pub cond: SpExpr,
|
|
|
|
|
pub expr: SpExpr,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub type SpCondExpr = Spanned<CondExpr>;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct Param {
|
|
|
|
|
pub name: String,
|
|
|
|
|
pub ty: Option<SpExpr>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub type SpParam = Spanned<Param>;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub enum Expr {
|
|
|
|
|
Call(Box<SpExpr>, Vec<SpExpr>),
|
|
|
|
|
Get(Box<SpExpr>, String),
|
|
|
|
|
Atom(SpAtom),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub type SpExpr = Spanned<Expr>;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub enum Atom {
|
|
|
|
|
Int(i64),
|
|
|
|
|
Float(f64),
|
|
|
|
|
Str(String),
|
|
|
|
|
Sym(String),
|
|
|
|
|
Name(String),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub type SpAtom = Spanned<Atom>;
|