From cbd9dc298634a587702d1c827ee43af7f5d496c1 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Sun, 24 Jan 2021 07:37:17 -0600 Subject: [PATCH] get rid of old peg code --- src/parser.rs | 47 ----------------------------------------------- 1 file changed, 47 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index 2bb11ce..672cd6f 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -5,53 +5,6 @@ use crate::ast::Program; lalrpop_mod!(parser); -// peg::parser! { -// grammar parser() for str { -// pub rule program() -> Program -// = decls:decls() _? ![_] { Program { decls } } -// -// rule decls() -> Vec -// = hd:decl() _? tl:decls() { let mut tl = tl; tl.insert(0, hd); tl } -// / { vec![] } -// -// rule decl() -> Decl -// = d:func() { Decl::Func(d) } -// -// rule func() -> Func -// = "fn" _ name:ident() _? "{" _? body:expr() _? "}" { Func { name, body } } -// / "fn" _ name:ident() _? body:blockexpr() { Func { name, body } } -// -// rule stmts() -> Vec -// = hd:stmt() _? tl:stmts() { let mut tl = tl; tl.insert(0, hd); tl } -// / { vec![] } -// -// rule stmt() -> Stmt -// = "return" _ v:expr() _? ";" { Stmt::Return(v) } -// / v:expr() _? ";" { Stmt::Expr(v) } -// -// rule blockexpr() -> Expr -// = "{" _? s:stmts() _? e:expr() "}" { Expr::Seq(s, Box::new(e)) } -// -// rule expr() -> Expr -// = blockexpr() -// / func:ident() _? "(" _? ")" { Expr::FuncCall(func) } -// / v:lit() { Expr::Lit(v) } -// -// rule lit() -> Lit -// = v:int() { Lit::Int(v) } -// -// rule int() -> i64 -// = s:$(['0'..='9']+) { s.parse::().unwrap() } -// -// rule ident() -> Ident -// = s:$([ 'a'..='z' | 'A'..='Z'] ['a'..='z' | 'A'..='Z' | '0'..='9' ]*) { Ident(s.to_string()) } -// / s:$("_" ['a'..='z' | 'A'..='Z' | '0'..='9' ]+) { Ident(s.to_string()) } -// / expected!("identifier") -// -// rule _() = [' ' | '\n' | '\t']+ -// } -// } - pub fn parse(s: impl AsRef) -> Result { let s = s.as_ref().to_owned(); let parser = parser::ProgramParser::new();