diff --git a/rust/src/main.rs b/rust/src/main.rs index fc44eea..807d781 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -10,7 +10,7 @@ fn repl() { let mut line = String::new(); io::stdin().read_line(&mut line).unwrap(); let tree = parser::parse_stmt(&line); - println!("{:?}", tree); + println!("{:#?}", tree); } } diff --git a/rust/src/parser.rs b/rust/src/parser.rs index 838a839..e3414c3 100644 --- a/rust/src/parser.rs +++ b/rust/src/parser.rs @@ -3,6 +3,7 @@ pub enum Stmt { Assignment(String, Expr), Funcall(Expr), Conditional(Vec, Option), + ReplPrint(Expr), } #[derive(Debug,PartialEq,Clone)] @@ -34,7 +35,8 @@ peg::parser! { pub rule stmt() -> Stmt = a:assignment() { a } / f:funcall() stop() { Stmt::Funcall(f) } / - c:conditional() { c } + c:conditional() { c } / + e:expr() stop() { Stmt::ReplPrint(e) } rule expr() -> Expr = precedence! { e1:(@) "+" _ e2:@ { Expr::Plus(Box::new(e1), Box::new(e2)) } e1:(@) "-" _ e2:@ { Expr::Minus(Box::new(e1), Box::new(e2)) }