@@ -13552,8 +13552,8 @@ parse_targets_validate(pm_parser_t *parser, pm_node_t *first_target, pm_binding_
13552
13552
*/
13553
13553
static pm_statements_node_t *
13554
13554
parse_statements(pm_parser_t *parser, pm_context_t context) {
13555
- // First, skip past any optional terminators that might be at the beginning of
13556
- // the statements.
13555
+ // First, skip past any optional terminators that might be at the beginning
13556
+ // of the statements.
13557
13557
while (accept2(parser, PM_TOKEN_SEMICOLON, PM_TOKEN_NEWLINE));
13558
13558
13559
13559
// If we have a terminator, then we can just return NULL.
@@ -13569,48 +13569,49 @@ parse_statements(pm_parser_t *parser, pm_context_t context) {
13569
13569
pm_node_t *node = parse_expression(parser, PM_BINDING_POWER_STATEMENT, true, PM_ERR_CANNOT_PARSE_EXPRESSION);
13570
13570
pm_statements_node_body_append(parser, statements, node);
13571
13571
13572
- // If we're recovering from a syntax error, then we need to stop parsing the
13573
- // statements now.
13572
+ // If we're recovering from a syntax error, then we need to stop parsing
13573
+ // the statements now.
13574
13574
if (parser->recovering) {
13575
- // If this is the level of context where the recovery has happened, then
13576
- // we can mark the parser as done recovering.
13575
+ // If this is the level of context where the recovery has happened,
13576
+ // then we can mark the parser as done recovering.
13577
13577
if (context_terminator(context, &parser->current)) parser->recovering = false;
13578
13578
break;
13579
13579
}
13580
13580
13581
- // If we have a terminator, then we will parse all consecutive terminators
13582
- // and then continue parsing the statements list.
13581
+ // If we have a terminator, then we will parse all consecutive
13582
+ // terminators and then continue parsing the statements list.
13583
13583
if (accept2(parser, PM_TOKEN_NEWLINE, PM_TOKEN_SEMICOLON)) {
13584
- // If we have a terminator, then we will continue parsing the statements
13585
- // list.
13584
+ // If we have a terminator, then we will continue parsing the
13585
+ // statements list.
13586
13586
while (accept2(parser, PM_TOKEN_NEWLINE, PM_TOKEN_SEMICOLON));
13587
13587
if (context_terminator(context, &parser->current)) break;
13588
13588
13589
13589
// Now we can continue parsing the list of statements.
13590
13590
continue;
13591
13591
}
13592
13592
13593
- // At this point we have a list of statements that are not terminated by a
13594
- // newline or semicolon. At this point we need to check if we're at the end
13595
- // of the statements list. If we are, then we should break out of the loop.
13593
+ // At this point we have a list of statements that are not terminated by
13594
+ // a newline or semicolon. At this point we need to check if we're at
13595
+ // the end of the statements list. If we are, then we should break out
13596
+ // of the loop.
13596
13597
if (context_terminator(context, &parser->current)) break;
13597
13598
13598
13599
// At this point, we have a syntax error, because the statement was not
13599
13600
// terminated by a newline or semicolon, and we're not at the end of the
13600
- // statements list. Ideally we should scan forward to determine if we should
13601
- // insert a missing terminator or break out of parsing the statements list
13602
- // at this point.
13601
+ // statements list. Ideally we should scan forward to determine if we
13602
+ // should insert a missing terminator or break out of parsing the
13603
+ // statements list at this point.
13603
13604
//
13604
- // We don't have that yet, so instead we'll do a more naive approach. If we
13605
- // were unable to parse an expression, then we will skip past this token and
13606
- // continue parsing the statements list. Otherwise we'll add an error and
13607
- // continue parsing the statements list.
13605
+ // We don't have that yet, so instead we'll do a more naive approach. If
13606
+ // we were unable to parse an expression, then we will skip past this
13607
+ // token and continue parsing the statements list. Otherwise we'll add
13608
+ // an error and continue parsing the statements list.
13608
13609
if (PM_NODE_TYPE_P(node, PM_MISSING_NODE)) {
13609
13610
parser_lex(parser);
13610
13611
13611
13612
while (accept2(parser, PM_TOKEN_NEWLINE, PM_TOKEN_SEMICOLON));
13612
13613
if (context_terminator(context, &parser->current)) break;
13613
- } else if (!accept1 (parser, PM_TOKEN_NEWLINE)) {
13614
+ } else if (!accept2 (parser, PM_TOKEN_NEWLINE, PM_TOKEN_EOF )) {
13614
13615
// This is an inlined version of accept1 because the error that we
13615
13616
// want to add has varargs. If this happens again, we should
13616
13617
// probably extract a helper function.
@@ -17428,7 +17429,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
17428
17429
17429
17430
// If we didn't find a terminator and we didn't find a right
17430
17431
// parenthesis, then this is a syntax error.
17431
- if (!terminator_found) {
17432
+ if (!terminator_found && !match1(parser, PM_TOKEN_EOF) ) {
17432
17433
PM_PARSER_ERR_TOKEN_FORMAT(parser, parser->current, PM_ERR_EXPECT_EOL_AFTER_STATEMENT, pm_token_type_human(parser->current.type));
17433
17434
}
17434
17435
@@ -17457,7 +17458,9 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
17457
17458
if (match1(parser, PM_TOKEN_PARENTHESIS_RIGHT)) break;
17458
17459
} else if (match1(parser, PM_TOKEN_PARENTHESIS_RIGHT)) {
17459
17460
break;
17460
- } else {
17461
+ } else if (!match1(parser, PM_TOKEN_EOF)) {
17462
+ // If we're at the end of the file, then we're going to add
17463
+ // an error after this for the ) anyway.
17461
17464
PM_PARSER_ERR_TOKEN_FORMAT(parser, parser->current, PM_ERR_EXPECT_EOL_AFTER_STATEMENT, pm_token_type_human(parser->current.type));
17462
17465
}
17463
17466
}
0 commit comments