get rid of old peg code
This commit is contained in:
parent
fd032e092d
commit
cbd9dc2986
1 changed files with 0 additions and 47 deletions
|
@ -5,53 +5,6 @@ use crate::ast::Program;
|
||||||
|
|
||||||
lalrpop_mod!(parser);
|
lalrpop_mod!(parser);
|
||||||
|
|
||||||
// peg::parser! {
|
|
||||||
// grammar parser() for str {
|
|
||||||
// pub rule program() -> Program
|
|
||||||
// = decls:decls() _? ![_] { Program { decls } }
|
|
||||||
//
|
|
||||||
// rule decls() -> Vec<Decl>
|
|
||||||
// = 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<Stmt>
|
|
||||||
// = 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::<i64>().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<str>) -> Result<Program> {
|
pub fn parse(s: impl AsRef<str>) -> Result<Program> {
|
||||||
let s = s.as_ref().to_owned();
|
let s = s.as_ref().to_owned();
|
||||||
let parser = parser::ProgramParser::new();
|
let parser = parser::ProgramParser::new();
|
||||||
|
|
Loading…
Reference in a new issue