More work

This commit is contained in:
Greg Shuflin 2021-11-19 23:04:00 -08:00
parent eeec85c2b1
commit a41d808da3
2 changed files with 19 additions and 10 deletions

View File

@ -503,11 +503,14 @@ fn extended_expr_part(input: Span) -> ParseResult<ExtendedPart> {
fn call_part(input: Span) -> ParseResult<Vec<InvocationArgument>> { fn call_part(input: Span) -> ParseResult<Vec<InvocationArgument>> {
context( context(
"call-part", "call-part",
//TODO generalize this `not` verify(
delimited( //TODO generalize this `not`
tok(char('(')), delimited(
separated_list0(tok(char(',')), preceded(not(tok(char(')'))), invocation_argument)), tok(char('(')),
tok(char(')')), separated_list0(tok(char(',')), preceded(not(tok(char(')'))), invocation_argument)),
tok(char(')')),
),
|output: &Vec<_>| output.len() <= 255,
), ),
)(input) )(input)
} }

View File

@ -113,6 +113,7 @@ macro_rules! assert_ast {
}; };
} }
/*
macro_rules! assert_fail { macro_rules! assert_fail {
($input:expr, $failure:expr) => { ($input:expr, $failure:expr) => {
let mut parser = Parser::new(); let mut parser = Parser::new();
@ -120,8 +121,13 @@ macro_rules! assert_fail {
assert_eq!(err.msg, $failure); assert_eq!(err.msg, $failure);
}; };
} }
*/
macro_rules! assert_fail_comb { macro_rules! assert_fail {
($input:expr) => {
let mut parser = Parser::new();
let err = parser.parse_comb($input).unwrap_err();
};
($input:expr, $failure:expr) => { ($input:expr, $failure:expr) => {
let mut parser = Parser::new(); let mut parser = Parser::new();
let err = parser.parse_comb($input).unwrap_err(); let err = parser.parse_comb($input).unwrap_err();
@ -557,7 +563,7 @@ fn complex_lambdas() {
#[test] #[test]
fn reserved_words() { fn reserved_words() {
let err = "0: at line 1, in Verify:\nmodule::item::call()\n^\n\n1: at line 1, in tok:\nmodule::item::call()\n^\n\n2: at line 1, in tok:\nmodule::item::call()\n^\n\n3: at line 1, in primary-expr-no-struct:\nmodule::item::call()\n^\n\n4: at line 1, in primary-expr:\nmodule::item::call()\n^\n\n5: at line 1, in extended-expr:\nmodule::item::call()\n^\n\n6: at line 1, in prefix-expr:\nmodule::item::call()\n^\n\n7: at line 1, in expression-kind:\nmodule::item::call()\n^\n\n8: at line 1, in Parsing-statement:\nmodule::item::call()\n^\n\n9: at line 1, in AST:\nmodule::item::call()\n^\n\n"; let err = "0: at line 1, in Verify:\nmodule::item::call()\n^\n\n1: at line 1, in tok:\nmodule::item::call()\n^\n\n2: at line 1, in tok:\nmodule::item::call()\n^\n\n3: at line 1, in primary-expr-no-struct:\nmodule::item::call()\n^\n\n4: at line 1, in primary-expr:\nmodule::item::call()\n^\n\n5: at line 1, in extended-expr:\nmodule::item::call()\n^\n\n6: at line 1, in prefix-expr:\nmodule::item::call()\n^\n\n7: at line 1, in expression-kind:\nmodule::item::call()\n^\n\n8: at line 1, in Parsing-statement:\nmodule::item::call()\n^\n\n9: at line 1, in AST:\nmodule::item::call()\n^\n\n";
assert_fail_comb!("module::item::call()", err); assert_fail!("module::item::call()", err);
assert_expr!("modulek::item", expr(ExpressionKind::Value(qn!(modulek, item)))); assert_expr!("modulek::item", expr(ExpressionKind::Value(qn!(modulek, item))));
} }
@ -824,7 +830,7 @@ fn functions() {
}) })
); );
let err_msg = "0: at line 1, in Alpha:\na(b,,c)\n ^\n\n1: at line 1, in Alt:\na(b,,c)\n ^\n\n2: at line 1, in tok:\na(b,,c)\n ^\n\n3: at line 1, in identifier-expr:\na(b,,c)\n ^\n\n4: at line 1, in Alt:\na(b,,c)\n ^\n\n5: at line 1, in primary-expr:\na(b,,c)\n ^\n\n6: at line 1, in extended-expr:\na(b,,c)\n ^\n\n7: at line 1, in prefix-expr:\na(b,,c)\n ^\n\n8: at line 1, in expression-kind:\na(b,,c)\n ^\n\n9: at line 1, in Alt:\na(b,,c)\n ^\n\n10: at line 1, in invocation-argument:\na(b,,c)\n ^\n\n11: at line 1, in call-part:\na(b,,c)\n ^\n\n12: at line 1, in extended-expr:\na(b,,c)\n^\n\n13: at line 1, in prefix-expr:\na(b,,c)\n^\n\n14: at line 1, in expression-kind:\na(b,,c)\n^\n\n15: at line 1, in Parsing-statement:\na(b,,c)\n^\n\n16: at line 1, in AST:\na(b,,c)\n^\n\n"; let err_msg = "0: at line 1, in Alpha:\na(b,,c)\n ^\n\n1: at line 1, in Alt:\na(b,,c)\n ^\n\n2: at line 1, in tok:\na(b,,c)\n ^\n\n3: at line 1, in identifier-expr:\na(b,,c)\n ^\n\n4: at line 1, in Alt:\na(b,,c)\n ^\n\n5: at line 1, in primary-expr:\na(b,,c)\n ^\n\n6: at line 1, in extended-expr:\na(b,,c)\n ^\n\n7: at line 1, in prefix-expr:\na(b,,c)\n ^\n\n8: at line 1, in expression-kind:\na(b,,c)\n ^\n\n9: at line 1, in Alt:\na(b,,c)\n ^\n\n10: at line 1, in invocation-argument:\na(b,,c)\n ^\n\n11: at line 1, in call-part:\na(b,,c)\n ^\n\n12: at line 1, in extended-expr:\na(b,,c)\n^\n\n13: at line 1, in prefix-expr:\na(b,,c)\n^\n\n14: at line 1, in expression-kind:\na(b,,c)\n^\n\n15: at line 1, in Parsing-statement:\na(b,,c)\n^\n\n16: at line 1, in AST:\na(b,,c)\n^\n\n";
assert_fail_comb!("a(b,,c)", err_msg); assert_fail!("a(b,,c)", err_msg);
assert_ast!( assert_ast!(
"fn a(b, c: Int): Int", "fn a(b, c: Int): Int",
@ -868,8 +874,8 @@ fn max_function_params() {
} }
write!(buf, ") {{ return 20 }}").unwrap(); write!(buf, ") {{ return 20 }}").unwrap();
//assert_fail!(&buf, "A function cannot have more than 255 arguments"); //assert_fail!(&buf, "A function cannot have more than 255 arguments");
//TODO better errors again //TODO need to create a good, custom error message for this case
assert_fail!(&buf, "error at 1:1439: expected ['a' ..= 'z' | 'A' ..= 'Z' | '_']"); assert_fail!(&buf);
} }
#[test] #[test]