Updated AST.
This commit is contained in:
+47
-47
@@ -1,65 +1,65 @@
|
|||||||
pub enum Script {
|
pub struct Script {
|
||||||
|
pub items: Vec<Stmt>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum Stmt {
|
||||||
|
Let(Let),
|
||||||
|
Assign(Assign),
|
||||||
Expr(Expr),
|
Expr(Expr),
|
||||||
Fn(Fn),
|
Fn(FnDef),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Let {
|
||||||
|
pub name: Ident,
|
||||||
|
pub ty: Option<Type>,
|
||||||
|
pub value: Expr,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Assign {
|
||||||
|
pub name: Ident,
|
||||||
|
pub value: Expr,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct FnDef {
|
||||||
|
pub name: Ident,
|
||||||
|
pub params: Vec<FnParam>,
|
||||||
|
pub body: Vec<Stmt>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct FnParam {
|
||||||
|
pub name: Ident,
|
||||||
|
pub ty: Type,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum Expr {
|
||||||
|
Literal(Literal),
|
||||||
|
Variable(Ident),
|
||||||
FnCall(FnCall),
|
FnCall(FnCall),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Expr {
|
pub enum Literal {
|
||||||
pub ident: ExprIdent,
|
Number(LitNumber),
|
||||||
pub value: ExprValue,
|
String(LitString),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ExprIdent(pub Ident);
|
pub struct LitNumber {
|
||||||
|
|
||||||
pub enum ExprValue {
|
|
||||||
Number(ExprNumber),
|
|
||||||
String(ExprString),
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct ExprNumber {
|
|
||||||
pub raw: String,
|
|
||||||
pub value: f64,
|
pub value: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ExprString {
|
pub struct LitString {
|
||||||
pub value: String,
|
pub value: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Fn {
|
|
||||||
pub ident: FnIdent,
|
|
||||||
pub params: Vec<FnParam>,
|
|
||||||
pub elements: Vec<FnElement>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct FnIdent(pub Ident);
|
|
||||||
|
|
||||||
pub struct FnParam {
|
|
||||||
pub ident: FnParamIdent,
|
|
||||||
pub ty: FnParamType,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct FnParamIdent(pub Ident);
|
|
||||||
|
|
||||||
pub enum FnParamType {
|
|
||||||
Number,
|
|
||||||
String,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum FnElement {
|
|
||||||
Expr(Expr),
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct FnCall {
|
pub struct FnCall {
|
||||||
pub ident: FnIdent,
|
pub name: Ident,
|
||||||
pub args: Vec<FnCallArg>,
|
pub args: Vec<Expr>,
|
||||||
}
|
|
||||||
|
|
||||||
pub enum FnCallArg {
|
|
||||||
Expr(ExprIdent),
|
|
||||||
Number(ExprNumber),
|
|
||||||
String(ExprString),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Ident {
|
pub struct Ident {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum Type {
|
||||||
|
Number,
|
||||||
|
String,
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user