From 6c9b5c16157ae7c9bb551e573e8fb60d2422eaf6 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Mon, 30 Sep 2024 10:51:01 -0400 Subject: [PATCH] Sync Prism with latest main branch --- prism/config.yml | 1 + prism/prism.c | 7 ++++--- prism/templates/src/diagnostic.c.erb | 1 + test/prism/errors/for_loop_delimiter.txt | 3 +++ test/prism/errors/for_loops_only_end.txt | 1 + test/prism/fixtures/patterns.txt | 10 ++-------- 6 files changed, 12 insertions(+), 11 deletions(-) create mode 100644 test/prism/errors/for_loop_delimiter.txt diff --git a/prism/config.yml b/prism/config.yml index 99a0e16cb1..b5de4d2b4a 100644 --- a/prism/config.yml +++ b/prism/config.yml @@ -99,6 +99,7 @@ errors: - EXPECT_EXPRESSION_AFTER_SPLAT - EXPECT_EXPRESSION_AFTER_SPLAT_HASH - EXPECT_EXPRESSION_AFTER_STAR + - EXPECT_FOR_DELIMITER - EXPECT_IDENT_REQ_PARAMETER - EXPECT_IN_DELIMITER - EXPECT_LPAREN_REQ_PARAMETER diff --git a/prism/prism.c b/prism/prism.c index 0b0a55e818..3c6863ab1b 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -17539,7 +17539,7 @@ parse_pattern(pm_parser_t *parser, pm_constant_id_list_t *captures, uint8_t flag // Gather up all of the patterns into the list. while (accept1(parser, PM_TOKEN_COMMA)) { // Break early here in case we have a trailing comma. - if (match6(parser, PM_TOKEN_KEYWORD_THEN, PM_TOKEN_BRACE_RIGHT, PM_TOKEN_BRACKET_RIGHT, PM_TOKEN_NEWLINE, PM_TOKEN_SEMICOLON, PM_TOKEN_EOF)) { + if (match4(parser, PM_TOKEN_KEYWORD_THEN, PM_TOKEN_BRACE_RIGHT, PM_TOKEN_BRACKET_RIGHT, PM_TOKEN_SEMICOLON)) { node = (pm_node_t *) pm_implicit_rest_node_create(parser, &parser->previous); pm_node_list_append(&nodes, node); break; @@ -19454,10 +19454,11 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b do_keyword = parser->previous; } else { do_keyword = not_provided(parser); + if (!match2(parser, PM_TOKEN_SEMICOLON, PM_TOKEN_NEWLINE)) { + PM_PARSER_ERR_TOKEN_FORMAT(parser, parser->current, PM_ERR_EXPECT_FOR_DELIMITER, pm_token_type_human(parser->current.type)); + } } - accept2(parser, PM_TOKEN_SEMICOLON, PM_TOKEN_NEWLINE); - pm_statements_node_t *statements = NULL; if (!match1(parser, PM_TOKEN_KEYWORD_END)) { statements = parse_statements(parser, PM_CONTEXT_FOR, (uint16_t) (depth + 1)); diff --git a/prism/templates/src/diagnostic.c.erb b/prism/templates/src/diagnostic.c.erb index 1f8217417e..b2381db57f 100644 --- a/prism/templates/src/diagnostic.c.erb +++ b/prism/templates/src/diagnostic.c.erb @@ -182,6 +182,7 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = { [PM_ERR_EXPECT_EXPRESSION_AFTER_SPLAT] = { "expected an expression after `*` splat in an argument", PM_ERROR_LEVEL_SYNTAX }, [PM_ERR_EXPECT_EXPRESSION_AFTER_SPLAT_HASH] = { "expected an expression after `**` in a hash", PM_ERROR_LEVEL_SYNTAX }, [PM_ERR_EXPECT_EXPRESSION_AFTER_STAR] = { "expected an expression after `*`", PM_ERROR_LEVEL_SYNTAX }, + [PM_ERR_EXPECT_FOR_DELIMITER] = { "unexpected %s; expected a 'do', newline, or ';' after the 'for' loop collection", PM_ERROR_LEVEL_SYNTAX }, [PM_ERR_EXPECT_IDENT_REQ_PARAMETER] = { "expected an identifier for the required parameter", PM_ERROR_LEVEL_SYNTAX }, [PM_ERR_EXPECT_IN_DELIMITER] = { "expected a delimiter after the patterns of an `in` clause", PM_ERROR_LEVEL_SYNTAX }, [PM_ERR_EXPECT_LPAREN_REQ_PARAMETER] = { "expected a `(` to start a required parameter", PM_ERROR_LEVEL_SYNTAX }, diff --git a/test/prism/errors/for_loop_delimiter.txt b/test/prism/errors/for_loop_delimiter.txt new file mode 100644 index 0000000000..07002d9d06 --- /dev/null +++ b/test/prism/errors/for_loop_delimiter.txt @@ -0,0 +1,3 @@ +for a in b end + ^~~ unexpected 'end'; expected a 'do', newline, or ';' after the 'for' loop collection + diff --git a/test/prism/errors/for_loops_only_end.txt b/test/prism/errors/for_loops_only_end.txt index 94cc5270b5..a8eaf0b8ab 100644 --- a/test/prism/errors/for_loops_only_end.txt +++ b/test/prism/errors/for_loops_only_end.txt @@ -2,4 +2,5 @@ for end ^~~ expected an index after `for` ^ expected an `in` after the index in a `for` statement ^ expected a collection after the `in` in a `for` statement + ^~~ unexpected 'end'; expected a 'do', newline, or ';' after the 'for' loop collection diff --git a/test/prism/fixtures/patterns.txt b/test/prism/fixtures/patterns.txt index 29f8b4cf80..5b3bc49652 100644 --- a/test/prism/fixtures/patterns.txt +++ b/test/prism/fixtures/patterns.txt @@ -87,10 +87,7 @@ foo => *bar, baz, qux foo => bar, *baz, qux foo => bar, baz, *qux foo => *bar, baz, *qux - -foo => bar, - -; # end the previous pattern for ParseTest#test_filepath_patterns.txt which parses the whole file at once +foo => bar,; foo => [] foo => [[[[[]]]]] @@ -127,10 +124,7 @@ foo in __FILE__ foo in __LINE__ foo in __ENCODING__ foo in -> { bar } - -foo in bar, - -; # end the previous pattern for ParseTest#test_filepath_patterns.txt which parses the whole file at once +foo in bar,; case foo; in bar then end case foo; in 1 then end