diff --git a/parser/src/lib.rs b/parser/src/lib.rs index be08694..830d33b 100644 --- a/parser/src/lib.rs +++ b/parser/src/lib.rs @@ -653,7 +653,16 @@ impl<'a> Parser<'a> { args.push( parser.fold_rhs(lex, lhs, start, 0, |t| Redirection::parse(t).is_some())?, ); - self.parse_command_args(lex, &mut args)?; + // `print (1) + 1, 2`: the rest of the list follows a comma + if lex.consume(&Token::Comma) { + if !lex.peek_with(Token::is_expr_start) { + return Err(ParsingError::InvalidExpression( + lex.span(), + String::from("Expected next argument!"), + )); + } + self.parse_command_args(lex, &mut args)?; + } } args } else { diff --git a/parser/src/tests.rs b/parser/src/tests.rs index 36f2c42..fb740a1 100644 --- a/parser/src/tests.rs +++ b/parser/src/tests.rs @@ -628,6 +628,22 @@ fn test_parser_printf() { }); } +#[test] +fn test_parser_print_list_after_parenthesized_first_expression() { + let source = r#" + { print ($1) "-", $2 } + { print (1) + 1, 2, 3 } + { print (1) ? "a" : "b", 2 } + "#; + test_parser!(source => { + rules: [ + (None, Some("(body (Print (Concat (Record 1) \"-\") (Record 2)))")), + (None, Some("(body (Print (Add 1 1) 2 3))")), + (None, Some("(body (Print (?: 1 \"a\" \"b\") 2))")), + ], + }); +} + #[test] fn test_parser_control_flow() { let source = r"