use crate::span::Span; #[derive(Debug, PartialEq)] pub enum Stmt { Let(Let), Assign(Assign), Expr(Expr), Block(Block), Fn(FnDef), } impl From for Stmt { fn from(let_stmt: Let) -> Self { Stmt::Let(let_stmt) } } impl From for Stmt { fn from(assign_stmt: Assign) -> Self { Stmt::Assign(assign_stmt) } } impl From for Stmt { fn from(expr_stmt: Expr) -> Self { Stmt::Expr(expr_stmt) } } impl From for Stmt { fn from(block: Block) -> Self { Stmt::Block(block) } } impl From for Stmt { fn from(fn_def: FnDef) -> Self { Stmt::Fn(fn_def) } } #[derive(Debug, PartialEq)] pub struct Let { pub name: Ident, pub ty: Option, pub value: Expr, pub span: Span, } #[derive(Debug, PartialEq)] pub struct Assign { pub name: Ident, pub value: Expr, pub span: Span, } #[derive(Debug, PartialEq)] pub struct FnDef { pub name: Ident, pub params: Vec, pub body: Vec, pub span: Span, } #[derive(Debug, PartialEq)] pub struct Block { pub stmts: Vec, pub span: Span, } #[derive(Debug, PartialEq)] pub struct FnParam { pub name: Ident, pub ty: Type, pub span: Span, } #[derive(Debug, PartialEq)] pub enum Expr { Literal(Literal), Variable(Ident), FnCall(FnCall), } #[derive(Debug, PartialEq)] pub enum Literal { Number(LitNumber), String(LitString), } impl From for Literal { fn from(lit: LitNumber) -> Self { Literal::Number(lit) } } impl From for Literal { fn from(lit: LitString) -> Self { Literal::String(lit) } } #[derive(Debug, PartialEq)] pub struct LitNumber { pub value: f64, pub span: Span, } #[derive(Debug, PartialEq)] pub struct LitString { pub value: String, pub span: Span, } #[derive(Debug, PartialEq)] pub struct FnCall { pub name: Ident, pub args: Vec, pub span: Span, } #[derive(Debug, PartialEq)] pub struct Ident { pub name: String, pub span: Span, } #[derive(Debug, PartialEq)] pub struct Type { pub name: String, pub span: Span, }