use std::str::FromStr; grammar; match { "<", ">", "|", ":", ",", ";", ":=", "::=", "puts", "case", "let", "in", r"[a-z][A-Za-z0-9_-]*", r"[A-Z][A-Za-z0-9_-]*", r"[0-9]+", } use crate::ast::*; pub Stmts: Vec = { ";")*> => match stmt { None => stmts, Some(stmt) => { stmts.push(stmt); stmts } }, }; pub Stmt: Stmt = { "puts" => Stmt::Puts(<>), ":=" => Stmt::Assn(<>), }; pub Name: String = { r"[a-z][A-Za-z0-9_-]*" => <>.to_owned(), }; pub Expr: Expr = { => Expr::Lit(<>), => Expr::Var(<>), "<" ",")*> ">" => { es.push(e); Expr::Tup(es) }, "let" ":=" "in" => Expr::Let(name, Box::new(e1), Box::new(e2)), }; pub Num: i64 = { r"[0-9]+" => i64::from_str(<>).unwrap(), }; pub Literal: Literal = { => Literal::Num(<>), r"[A-Z][A-Za-z0-9_-]*" => Literal::Atom(<>.to_owned()), };