diff options
Diffstat (limited to 'users/glittershark/achilles/src/parser/expr.rs')
-rw-r--r-- | users/glittershark/achilles/src/parser/expr.rs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/users/glittershark/achilles/src/parser/expr.rs b/users/glittershark/achilles/src/parser/expr.rs index 99c8018fd00c..8a28d00984c9 100644 --- a/users/glittershark/achilles/src/parser/expr.rs +++ b/users/glittershark/achilles/src/parser/expr.rs @@ -186,7 +186,9 @@ named!(string(&str) -> Literal, preceded!( ) )); -named!(literal(&str) -> Literal, alt!(int | bool_ | string)); +named!(unit(&str) -> Literal, map!(complete!(tag!("()")), |_| Literal::Unit)); + +named!(literal(&str) -> Literal, alt!(int | bool_ | string | unit)); named!(literal_expr(&str) -> Expr, map!(literal, Expr::Literal)); @@ -270,7 +272,6 @@ named!(funcref(&str) -> Expr, alt!( named!(no_arg_call(&str) -> Expr, do_parse!( fun: funcref - >> multispace0 >> complete!(tag!("()")) >> (Expr::Call { fun: Box::new(fun), @@ -432,6 +433,11 @@ pub(crate) mod tests { } #[test] + fn unit() { + assert_eq!(test_parse!(expr, "()"), Expr::Literal(Literal::Unit)); + } + + #[test] fn bools() { assert_eq!( test_parse!(expr, "true"), @@ -516,6 +522,18 @@ pub(crate) mod tests { } #[test] + fn unit_call() { + let res = test_parse!(expr, "f ()"); + assert_eq!( + res, + Expr::Call { + fun: ident_expr("f"), + args: vec![Expr::Literal(Literal::Unit)] + } + ) + } + + #[test] fn call_with_args() { let res = test_parse!(expr, "f x 1"); assert_eq!( |