use crate::ast::*; grammar; pub Program: Vec = Decl* => <>; Decl: Decl = { Func => Decl::Func(<>), }; Func: Func = { "fn" "(" ")" "->" "{" "}" => Func { name, return_ty, stmts }, }; Stmt: Stmt = { "let" ":" "=" ";" => Stmt::Let(name, ty, expr), "return" ";" => Stmt::Return(expr), }; Expr: Expr = { Expr1 => <>, }; Expr1: Expr = { r"[0-9]+" => Expr::Int(<>.parse::().unwrap()), Ident => Expr::Var(<>), "(" ")" => expr, }; Type: Type = { "int" => Type::Int, }; Ident: String = r"([A-Za-z][A-Za-z0-9_]*)|(_[A-Za-z0-9_]+)" => <>.to_string();