Compare commits

...

2 Commits

Author SHA1 Message Date
Greg Shuflin
fc463d3807 Apply 256 arg limit to lambdas too 2021-11-22 00:14:21 -08:00
Greg Shuflin
7221d2cb11 Remove obsolete comments 2021-11-21 12:27:07 -08:00
3 changed files with 29 additions and 23 deletions

View File

@ -293,8 +293,7 @@ fn func_signature(input: Span) -> ParseResult<Signature> {
"func-signature",
preceded(
kw("fn"),
cut(verify(
alt((
cut(alt((
map(normal_fn, |(name, params, type_anno)| Signature {
name: rc_string(name.fragment()),
operator: false,
@ -307,18 +306,21 @@ fn func_signature(input: Span) -> ParseResult<Signature> {
params,
type_anno,
}),
)),
|sig| sig.params.len() < 256,
)),
))),
),
)(input)
}
fn formal_params(input: Span) -> ParseResult<Vec<FormalParam>> {
delimited(tok(char('(')), separated_list0(tok(char(',')), formal_param), tok(char(')')))(input)
context(
"formal-params",
verify(
delimited(tok(char('(')), separated_list0(tok(char(',')), formal_param), tok(char(')'))),
|params: &Vec<_>| params.len() < 256,
),
)(input)
}
//TODO support 256-limit
fn formal_param(input: Span) -> ParseResult<FormalParam> {
map(
tuple((identifier, opt(type_anno), opt(preceded(tok(char('=')), expression)))),
@ -578,7 +580,6 @@ fn extended_expr_part(input: Span) -> ParseResult<ExtendedPart> {
))(input)
}
//TODO this shouldn't be an expression b/c type annotations disallowed here
fn invocation_argument(input: Span) -> ParseResult<InvocationArgument> {
context(
"invocation-argument",

View File

@ -1,8 +1,6 @@
use std::rc::Rc;
use super::Parser;
//TODO make use of the format_parse_error function
//use crate::error::{SchalaError, format_parse_error};
use crate::ast::*;
fn rc_string(s: &str) -> Rc<String> {
@ -264,7 +262,6 @@ peg::parser! {
rule call_part(parser: &mut Parser) -> Vec<InvocationArgument> =
"(" arguments:(invocation_argument(parser) ** ",") ")" { arguments }
//TODO this shouldn't be an expression b/c type annotations disallowed here
rule invocation_argument(parser: &mut Parser) -> InvocationArgument =
_ "_" _ { InvocationArgument::Ignored } /
_ ident:identifier() _ "=" _ expr:expression(parser) { InvocationArgument::Keyword {

View File

@ -886,6 +886,14 @@ fn max_function_params() {
//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);
let mut buf = r#"\("#.to_string();
for n in 0..255 {
write!(buf, "a{}, ", n).unwrap();
}
write!(buf, " a256").unwrap();
write!(buf, ") {{ return 10 }}").unwrap();
assert_fail!(&buf);
}
#[test]