diff --git a/schala-lang/language/src/parsing/new.rs b/schala-lang/language/src/parsing/new.rs index 135fe89..7521ae0 100644 --- a/schala-lang/language/src/parsing/new.rs +++ b/schala-lang/language/src/parsing/new.rs @@ -1,7 +1,6 @@ use crate::ast::*; use std::rc::Rc; - peg::parser! { pub grammar schala_parser() for str { @@ -22,7 +21,14 @@ peg::parser! { primary() rule primary() -> ExpressionKind = - float_literal() / nat_literal() / bool_literal() / string_literal() / paren_expr() + float_literal() / nat_literal() / bool_literal() / string_literal() / paren_expr() / + list_expr() + + rule list_expr() -> ExpressionKind = + "[" exprs:(expression() ** ",") "]" { + let mut exprs = exprs; + ExpressionKind::ListLiteral(exprs) + } rule paren_expr() -> ExpressionKind = "(" exprs:(expression() ** ",") ")" { diff --git a/schala-lang/language/src/parsing/test.rs b/schala-lang/language/src/parsing/test.rs index 9d6ec99..f0f2bc3 100644 --- a/schala-lang/language/src/parsing/test.rs +++ b/schala-lang/language/src/parsing/test.rs @@ -127,6 +127,13 @@ macro_rules! assert_expr2 { assert_eq!(schala_parser::expression($input).unwrap(), $correct); }; } +macro_rules! assert_fail_expr2 { + ($input:expr, $failure:expr) => { + let _err = schala_parser::expression($input).unwrap_err(); + //TODO make real tests for failures + //assert_eq!(err.to_string(), $failure); + } +} macro_rules! assert_fail_expr { ($input:expr, $failure:expr) => { @@ -155,8 +162,9 @@ fn basic_literals() { fn list_literals() { use ExpressionKind::*; - assert_expr!("[]", expr(ListLiteral(vec![]))); - assert_expr!("[1,2]", expr(ListLiteral(vec![expr(NatLiteral(1)), expr(NatLiteral(2)),]))); + assert_expr2!("[]", expr(ListLiteral(vec![]))); + assert_expr2!("[1,2]", expr(ListLiteral(vec![expr(NatLiteral(1)), expr(NatLiteral(2)),]))); + assert_fail_expr2!("[1,,2]", "some failure"); } #[test]