Skip to content

Commit d9151b8

Browse files
ydahkddnewton
authored andcommitted
Improve error handling for missing parentheses after 'not' in command calls
1 parent 0513cf2 commit d9151b8

4 files changed

Lines changed: 20 additions & 4 deletions

File tree

config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ errors:
101101
- EXPECT_FOR_DELIMITER
102102
- EXPECT_IDENT_REQ_PARAMETER
103103
- EXPECT_IN_DELIMITER
104-
- EXPECT_LPAREN_AFTER_NOT
104+
- EXPECT_LPAREN_AFTER_NOT_LPAREN
105+
- EXPECT_LPAREN_AFTER_NOT_OTHER
105106
- EXPECT_LPAREN_REQ_PARAMETER
106107
- EXPECT_MESSAGE
107108
- EXPECT_RBRACKET

src/prism.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19756,8 +19756,17 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
1975619756
pm_arguments_t arguments = { 0 };
1975719757
pm_node_t *receiver = NULL;
1975819758

19759+
// If we do not accept a command call, then we also do not accept a
19760+
// not without parentheses. In this case we need to reject this
19761+
// syntax.
1975919762
if (!accepts_command_call && !match1(parser, PM_TOKEN_PARENTHESIS_LEFT)) {
19760-
pm_parser_err_current(parser, PM_ERR_EXPECT_LPAREN_AFTER_NOT);
19763+
if (match1(parser, PM_TOKEN_PARENTHESIS_LEFT_PARENTHESES)) {
19764+
pm_parser_err(parser, parser->previous.end, parser->previous.end + 1, PM_ERR_EXPECT_LPAREN_AFTER_NOT_LPAREN);
19765+
} else {
19766+
accept1(parser, PM_TOKEN_NEWLINE);
19767+
pm_parser_err_current(parser, PM_ERR_EXPECT_LPAREN_AFTER_NOT_OTHER);
19768+
}
19769+
1976119770
return (pm_node_t *) pm_missing_node_create(parser, parser->current.start, parser->current.end);
1976219771
}
1976319772

templates/src/diagnostic.c.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
184184
[PM_ERR_EXPECT_FOR_DELIMITER] = { "unexpected %s; expected a 'do', newline, or ';' after the 'for' loop collection", PM_ERROR_LEVEL_SYNTAX },
185185
[PM_ERR_EXPECT_IDENT_REQ_PARAMETER] = { "expected an identifier for the required parameter", PM_ERROR_LEVEL_SYNTAX },
186186
[PM_ERR_EXPECT_IN_DELIMITER] = { "expected a delimiter after the patterns of an `in` clause", PM_ERROR_LEVEL_SYNTAX },
187-
[PM_ERR_EXPECT_LPAREN_AFTER_NOT] = { "expected a `(` after `not`", PM_ERROR_LEVEL_SYNTAX },
187+
[PM_ERR_EXPECT_LPAREN_AFTER_NOT_LPAREN] = { "expected a `(` immediately after `not`", PM_ERROR_LEVEL_SYNTAX },
188+
[PM_ERR_EXPECT_LPAREN_AFTER_NOT_OTHER] = { "expected a `(` after `not`", PM_ERROR_LEVEL_SYNTAX },
188189
[PM_ERR_EXPECT_LPAREN_REQ_PARAMETER] = { "expected a `(` to start a required parameter", PM_ERROR_LEVEL_SYNTAX },
189190
[PM_ERR_EXPECT_MESSAGE] = { "unexpected %s; expecting a message to send to the receiver", PM_ERROR_LEVEL_SYNTAX },
190191
[PM_ERR_EXPECT_RBRACKET] = { "expected a matching `]`", PM_ERROR_LEVEL_SYNTAX },

test/prism/errors/command_calls_31.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ true || not true
77
^~~~ unexpected 'true', expecting end-of-input
88

99
true && not (true)
10-
^ expected a `(` after `not`
10+
^ expected a `(` immediately after `not`
1111
^ unexpected '(', expecting end-of-input
1212

13+
true && not
14+
true
15+
^~~~ expected a `(` after `not`
16+
^~~~ unexpected 'true', expecting end-of-input
17+

0 commit comments

Comments
 (0)