Allow a bare expression that will be evaluated and echo'd to stdin
This commit is contained in:
parent
15055b9ece
commit
688b48ef42
@ -10,7 +10,7 @@ fn repl() {
|
|||||||
let mut line = String::new();
|
let mut line = String::new();
|
||||||
io::stdin().read_line(&mut line).unwrap();
|
io::stdin().read_line(&mut line).unwrap();
|
||||||
let tree = parser::parse_stmt(&line);
|
let tree = parser::parse_stmt(&line);
|
||||||
println!("{:?}", tree);
|
println!("{:#?}", tree);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ pub enum Stmt {
|
|||||||
Assignment(String, Expr),
|
Assignment(String, Expr),
|
||||||
Funcall(Expr),
|
Funcall(Expr),
|
||||||
Conditional(Vec<Expr>, Option<Expr>),
|
Conditional(Vec<Expr>, Option<Expr>),
|
||||||
|
ReplPrint(Expr),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug,PartialEq,Clone)]
|
#[derive(Debug,PartialEq,Clone)]
|
||||||
@ -34,7 +35,8 @@ peg::parser! {
|
|||||||
pub rule stmt() -> Stmt
|
pub rule stmt() -> Stmt
|
||||||
= a:assignment() { a } /
|
= a:assignment() { a } /
|
||||||
f:funcall() stop() { Stmt::Funcall(f) } /
|
f:funcall() stop() { Stmt::Funcall(f) } /
|
||||||
c:conditional() { c }
|
c:conditional() { c } /
|
||||||
|
e:expr() stop() { Stmt::ReplPrint(e) }
|
||||||
rule expr() -> Expr = precedence! {
|
rule expr() -> Expr = precedence! {
|
||||||
e1:(@) "+" _ e2:@ { Expr::Plus(Box::new(e1), Box::new(e2)) }
|
e1:(@) "+" _ e2:@ { Expr::Plus(Box::new(e1), Box::new(e2)) }
|
||||||
e1:(@) "-" _ e2:@ { Expr::Minus(Box::new(e1), Box::new(e2)) }
|
e1:(@) "-" _ e2:@ { Expr::Minus(Box::new(e1), Box::new(e2)) }
|
||||||
|
Loading…
Reference in New Issue
Block a user