Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -19195,10 +19195,12 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
pm_arguments_t arguments = { 0 };
pm_node_t *receiver = NULL;

// If we do not accept a command call, then we also do not accept a
// not without parentheses. In this case we need to reject this
// syntax.
if (!accepts_command_call && !match1(parser, PM_TOKEN_PARENTHESIS_LEFT)) {
// The `not` keyword without parentheses is only valid in contexts
// where it would be parsed as an expression (i.e., at or below
// the `not` binding power level). In other contexts (e.g., method
// arguments, array elements, assignment right-hand sides),
// parentheses are required: `not(x)`.
if (binding_power > PM_BINDING_POWER_NOT && !match1(parser, PM_TOKEN_PARENTHESIS_LEFT)) {
if (match1(parser, PM_TOKEN_PARENTHESIS_LEFT_PARENTHESES)) {
pm_parser_err(parser, PM_TOKEN_END(parser, &parser->previous), 1, PM_ERR_EXPECT_LPAREN_AFTER_NOT_LPAREN);
} else {
Expand Down
4 changes: 4 additions & 0 deletions test/prism/errors/not_without_parens_assignment.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
x = not y
^ expected a `(` after `not`
^ unexpected local variable or method, expecting end-of-input

7 changes: 7 additions & 0 deletions test/prism/errors/not_without_parens_call.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
foo(not y)
^ expected a `(` after `not`
^ unexpected local variable or method; expected a `)` to close the arguments
^ unexpected local variable or method, expecting end-of-input
^ unexpected ')', expecting end-of-input
^ unexpected ')', ignoring it

4 changes: 4 additions & 0 deletions test/prism/errors/not_without_parens_command.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
foo not y
^ expected a `(` after `not`
^ unexpected local variable or method, expecting end-of-input

4 changes: 4 additions & 0 deletions test/prism/errors/not_without_parens_command_call.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
a.b not y
^ expected a `(` after `not`
^ unexpected local variable or method, expecting end-of-input

4 changes: 4 additions & 0 deletions test/prism/errors/not_without_parens_return.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
return not y
^ expected a `(` after `not`
^ unexpected local variable or method, expecting end-of-input

Loading