@@ -5,8 +5,8 @@ use crate::parse::expr_or_stmt::parse_expr_or_stmt;
55use crate :: parse:: iterator:: LexIterator ;
66use crate :: parse:: lex:: token:: Token ;
77use crate :: parse:: operation:: parse_expression;
8+ use crate :: parse:: result:: custom;
89use crate :: parse:: result:: ParseResult ;
9- use crate :: parse:: result:: { custom, ParseErr } ;
1010use crate :: parse:: ty:: parse_expression_type;
1111use crate :: parse:: ty:: parse_id;
1212use crate :: parse:: ty:: parse_type;
@@ -177,7 +177,12 @@ pub fn parse_fun_args(it: &mut LexIterator) -> ParseResult<Vec<AST>> {
177177 let mut args = vec ! [ ] ;
178178 it. peek_while_not_token ( & Token :: RRBrack , & mut |it, _| {
179179 args. push ( * it. parse ( & parse_fun_arg, "function arguments" , start) ?) ;
180- it. eat_if ( & Token :: Comma ) ;
180+
181+ if let Some ( next) = it. peek_next ( ) {
182+ if next. token != Token :: RRBrack {
183+ it. eat ( & Token :: Comma , "function arguments must be comma separated" ) ?;
184+ }
185+ }
181186 Ok ( ( ) )
182187 } ) ?;
183188
@@ -187,7 +192,6 @@ pub fn parse_fun_args(it: &mut LexIterator) -> ParseResult<Vec<AST>> {
187192
188193pub fn parse_fun_arg ( it : & mut LexIterator ) -> ParseResult {
189194 let start = it. start_pos ( "function argument" ) ?;
190- let vararg = it. eat_if ( & Token :: Vararg ) . is_some ( ) ;
191195
192196 let expression_type = it. parse ( & parse_expression_type, "function argument" , start) ?;
193197 let ( mutable, var, ty) = match & expression_type. node {
@@ -208,7 +212,7 @@ pub fn parse_fun_arg(it: &mut LexIterator) -> ParseResult {
208212
209213 let end = default. clone ( ) . map_or ( expression_type. pos , |def| def. pos ) ;
210214 let node = Node :: FunArg {
211- vararg,
215+ vararg : false ,
212216 mutable,
213217 var,
214218 ty,
@@ -217,10 +221,9 @@ pub fn parse_fun_arg(it: &mut LexIterator) -> ParseResult {
217221 Ok ( Box :: from ( AST :: new ( start. union ( end) , node) ) )
218222}
219223
220- /// Lambda args cannot be assigned a default
224+ /// Lambda args cannot be assigned a default, though whether we should even allow default arguments is debatable.
221225pub fn parse_lambda_arg ( it : & mut LexIterator ) -> ParseResult {
222226 let start = it. start_pos ( "function argument" ) ?;
223- let vararg = it. eat_if ( & Token :: Vararg ) . is_some ( ) ;
224227
225228 let expression_type = it. parse ( & parse_expression_type, "function argument" , start) ?;
226229 let ( mutable, var, ty) = match & expression_type. node {
@@ -233,17 +236,8 @@ pub fn parse_lambda_arg(it: &mut LexIterator) -> ParseResult {
233236 }
234237 } ;
235238
236- if let Some ( lex) = it. peek_next ( ) {
237- if lex. token == Token :: Assign {
238- return Err ( Box :: new ( custom (
239- "lambda function arguments cannot have defaults" ,
240- lex. pos ,
241- ) ) ) ;
242- }
243- }
244-
245239 let node = Node :: FunArg {
246- vararg,
240+ vararg : false ,
247241 mutable,
248242 var,
249243 ty,
@@ -545,7 +539,7 @@ mod test {
545539
546540 #[ test]
547541 fn function_definition_verify ( ) {
548- let source = String :: from ( "def f(fin b: Something, vararg c) := d" ) ;
542+ let source = String :: from ( "def f(fin b: Something, c) := d" ) ;
549543 let ast = parse_direct ( & source) . unwrap ( ) ;
550544 let ( pure, id, fun_args, ret, raises, body) = unwrap_func_definition ! ( ast) ;
551545
@@ -587,8 +581,8 @@ mod test {
587581 default : d2,
588582 } ,
589583 ) => {
590- assert_eq ! ( v1. clone( ) , false ) ;
591- assert_eq ! ( v2. clone( ) , true ) ;
584+ assert ! ( ! v1. clone( ) ) ;
585+ assert ! ( ! v2. clone( ) ) ;
592586
593587 assert_eq ! (
594588 id1. node,
@@ -681,9 +675,15 @@ mod test {
681675 }
682676 }
683677
678+ #[ test]
679+ fn function_no_separator_args ( ) {
680+ let source = String :: from ( "def f(x b: Something) := d" ) ;
681+ parse_direct ( & source) . unwrap_err ( ) ;
682+ }
683+
684684 #[ test]
685685 fn function_definition_with_literal_verify ( ) {
686- let source = String :: from ( "def f(x, vararg b: Something) := d" ) ;
686+ let source = String :: from ( "def f(x, b: Something) := d" ) ;
687687 let ast = parse_direct ( & source) . unwrap ( ) ;
688688 let ( pure, id, fun_args, ret, _, body) = unwrap_func_definition ! ( ast) ;
689689
@@ -725,7 +725,7 @@ mod test {
725725 } ,
726726 ) => {
727727 assert ! ( !v1. clone( ) ) ;
728- assert ! ( v2. clone( ) ) ;
728+ assert ! ( ! v2. clone( ) ) ;
729729
730730 assert ! ( mut1. clone( ) ) ;
731731 assert ! ( mut2. clone( ) ) ;
0 commit comments