diff --git a/schala-lang/src/parsing/combinator.rs b/schala-lang/src/parsing/combinator.rs index 01c2ada..223b04d 100644 --- a/schala-lang/src/parsing/combinator.rs +++ b/schala-lang/src/parsing/combinator.rs @@ -154,13 +154,13 @@ fn block_template<'a, O, O2>( ) -> impl FnMut(Span<'a>) -> IResult, Vec, VerboseError>> { delimited( pair(tok(char('{')), many0(statement_delimiter)), - separated_list0(delimiter, input_parser), + cut(separated_list0(delimiter, input_parser)), pair(many0(statement_delimiter), tok(char('}'))), ) } pub fn block(input: Span) -> ParseResult { - map(block_template(many1(statement_delimiter), statement), |items| items.into())(input) + context("block", map(block_template(many1(statement_delimiter), statement), |items| items.into()))(input) } fn statement(input: Span) -> ParseResult { @@ -293,20 +293,23 @@ fn func_signature(input: Span) -> ParseResult { "func-signature", preceded( kw("fn"), - cut(alt(( - map(normal_fn, |(name, params, type_anno)| Signature { - name: rc_string(name.fragment()), - operator: false, - params, - type_anno, - }), - map(operator_fn, |(op, params, type_anno)| Signature { - name: rc_string(op.sigil()), - operator: true, - params, - type_anno, - }), - ))), + cut(verify( + alt(( + map(normal_fn, |(name, params, type_anno)| Signature { + name: rc_string(name.fragment()), + operator: false, + params, + type_anno, + }), + map(operator_fn, |(op, params, type_anno)| Signature { + name: rc_string(op.sigil()), + operator: true, + params, + type_anno, + }), + )), + |sig| sig.params.len() < 256, + )), ), )(input) } diff --git a/schala-lang/src/parsing/test.rs b/schala-lang/src/parsing/test.rs index 751934c..9d4e6cb 100644 --- a/schala-lang/src/parsing/test.rs +++ b/schala-lang/src/parsing/test.rs @@ -878,12 +878,13 @@ fn custom_operator() { #[test] fn max_function_params() { let mut buf = "fn longfunc(".to_string(); - for n in 0..256 { + for n in 0..255 { write!(buf, "a{}, ", n).unwrap(); } + write!(buf, " a256").unwrap(); write!(buf, ") {{ return 20 }}").unwrap(); - //assert_fail!(&buf, "A function cannot have more than 255 arguments"); //TODO need to create a good, custom error message for this case + //assert_fail!(&buf, "A function cannot have more than 255 arguments"); assert_fail!(&buf); }