Skip to content

Commit dd532de

Browse files
committed
Replace end of file with end-of-input
1 parent 48147a5 commit dd532de

File tree

4 files changed

+34
-33
lines changed

4 files changed

+34
-33
lines changed

rust/ruby-prism-sys/tests/parser_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn diagnostics_test() {
8585
let message = CStr::from_ptr((*error).message);
8686
assert_eq!(
8787
message.to_string_lossy(),
88-
"unexpected end of file, assuming it is closing the parent top level context"
88+
"unexpected end-of-input, assuming it is closing the parent top level context"
8989
);
9090

9191
let location = {

src/prism.c

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13552,8 +13552,8 @@ parse_targets_validate(pm_parser_t *parser, pm_node_t *first_target, pm_binding_
1355213552
*/
1355313553
static pm_statements_node_t *
1355413554
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.
1355713557
while (accept2(parser, PM_TOKEN_SEMICOLON, PM_TOKEN_NEWLINE));
1355813558

1355913559
// 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) {
1356913569
pm_node_t *node = parse_expression(parser, PM_BINDING_POWER_STATEMENT, true, PM_ERR_CANNOT_PARSE_EXPRESSION);
1357013570
pm_statements_node_body_append(parser, statements, node);
1357113571

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.
1357413574
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.
1357713577
if (context_terminator(context, &parser->current)) parser->recovering = false;
1357813578
break;
1357913579
}
1358013580

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.
1358313583
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.
1358613586
while (accept2(parser, PM_TOKEN_NEWLINE, PM_TOKEN_SEMICOLON));
1358713587
if (context_terminator(context, &parser->current)) break;
1358813588

1358913589
// Now we can continue parsing the list of statements.
1359013590
continue;
1359113591
}
1359213592

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.
1359613597
if (context_terminator(context, &parser->current)) break;
1359713598

1359813599
// At this point, we have a syntax error, because the statement was not
1359913600
// 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.
1360313604
//
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.
1360813609
if (PM_NODE_TYPE_P(node, PM_MISSING_NODE)) {
1360913610
parser_lex(parser);
1361013611

1361113612
while (accept2(parser, PM_TOKEN_NEWLINE, PM_TOKEN_SEMICOLON));
1361213613
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)) {
1361413615
// This is an inlined version of accept1 because the error that we
1361513616
// want to add has varargs. If this happens again, we should
1361613617
// probably extract a helper function.
@@ -17428,7 +17429,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
1742817429

1742917430
// If we didn't find a terminator and we didn't find a right
1743017431
// parenthesis, then this is a syntax error.
17431-
if (!terminator_found) {
17432+
if (!terminator_found && !match1(parser, PM_TOKEN_EOF)) {
1743217433
PM_PARSER_ERR_TOKEN_FORMAT(parser, parser->current, PM_ERR_EXPECT_EOL_AFTER_STATEMENT, pm_token_type_human(parser->current.type));
1743317434
}
1743417435

@@ -17457,7 +17458,9 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
1745717458
if (match1(parser, PM_TOKEN_PARENTHESIS_RIGHT)) break;
1745817459
} else if (match1(parser, PM_TOKEN_PARENTHESIS_RIGHT)) {
1745917460
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.
1746117464
PM_PARSER_ERR_TOKEN_FORMAT(parser, parser->current, PM_ERR_EXPECT_EOL_AFTER_STATEMENT, pm_token_type_human(parser->current.type));
1746217465
}
1746317466
}

templates/src/token_type.c.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const char *
3030
pm_token_type_human(pm_token_type_t token_type) {
3131
switch (token_type) {
3232
case PM_TOKEN_EOF:
33-
return "end of file";
33+
return "end-of-input";
3434
case PM_TOKEN_MISSING:
3535
return "missing token";
3636
case PM_TOKEN_NOT_PROVIDED:

test/prism/errors_test.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,7 @@ def test_unterminated_s_symbol
195195

196196
def test_unterminated_parenthesized_expression
197197
assert_errors expression('(1 + 2'), '(1 + 2', [
198-
["unexpected end of file, expecting end-of-input", 6..6],
199-
["unexpected end of file, assuming it is closing the parent top level context", 6..6],
198+
["unexpected end-of-input, assuming it is closing the parent top level context", 6..6],
200199
["expected a matching `)`", 6..6]
201200
]
202201
end
@@ -210,8 +209,8 @@ def test_missing_terminator_in_parentheses
210209
def test_unterminated_argument_expression
211210
assert_errors expression('a %'), 'a %', [
212211
["invalid `%` token", 2..3],
213-
["unexpected end of file; expected an expression after the operator", 3..3],
214-
["unexpected end of file, assuming it is closing the parent top level context", 3..3]
212+
["unexpected end-of-input; expected an expression after the operator", 3..3],
213+
["unexpected end-of-input, assuming it is closing the parent top level context", 3..3]
215214
]
216215
end
217216

@@ -365,7 +364,7 @@ def test_block_beginning_with_brace_and_ending_with_end
365364
assert_error_messages "x.each { x end", [
366365
"unexpected 'end', expecting end-of-input",
367366
"unexpected 'end', ignoring it",
368-
"unexpected end of file, assuming it is closing the parent top level context",
367+
"unexpected end-of-input, assuming it is closing the parent top level context",
369368
"expected a block beginning with `{` to end with `}`"
370369
]
371370
end
@@ -1482,8 +1481,7 @@ def test_shadow_args_in_lambda
14821481

14831482
assert_errors expression(source), source, [
14841483
["expected a `do` keyword or a `{` to open the lambda block", 3..3],
1485-
["unexpected end of file, expecting end-of-input", 7..7],
1486-
["unexpected end of file, assuming it is closing the parent top level context", 7..7],
1484+
["unexpected end-of-input, assuming it is closing the parent top level context", 7..7],
14871485
["expected a lambda block beginning with `do` to end with `end`", 7..7]
14881486
]
14891487
end
@@ -1541,7 +1539,7 @@ def test_while_endless_method
15411539

15421540
assert_errors expression(source), source, [
15431541
["expected a predicate expression for the `while` statement", 22..22],
1544-
["unexpected end of file, assuming it is closing the parent top level context", 22..22],
1542+
["unexpected end-of-input, assuming it is closing the parent top level context", 22..22],
15451543
["expected an `end` to close the `while` statement", 22..22]
15461544
]
15471545
end

0 commit comments

Comments
 (0)