More work
This commit is contained in:
parent
88b39b5561
commit
6cbe562241
@ -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() ** ",") ")" {
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user