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
2 changes: 2 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ errors:
- EXPECT_FOR_DELIMITER
- EXPECT_IDENT_REQ_PARAMETER
- EXPECT_IN_DELIMITER
- EXPECT_LPAREN_AFTER_NOT_LPAREN
- EXPECT_LPAREN_AFTER_NOT_OTHER
- EXPECT_LPAREN_REQ_PARAMETER
- EXPECT_MESSAGE
- EXPECT_RBRACKET
Expand Down
14 changes: 14 additions & 0 deletions src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -19756,6 +19756,20 @@ 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)) {
if (match1(parser, PM_TOKEN_PARENTHESIS_LEFT_PARENTHESES)) {
pm_parser_err(parser, parser->previous.end, parser->previous.end + 1, PM_ERR_EXPECT_LPAREN_AFTER_NOT_LPAREN);
} else {
accept1(parser, PM_TOKEN_NEWLINE);
pm_parser_err_current(parser, PM_ERR_EXPECT_LPAREN_AFTER_NOT_OTHER);
}

return (pm_node_t *) pm_missing_node_create(parser, parser->current.start, parser->current.end);
}

accept1(parser, PM_TOKEN_NEWLINE);

if (accept1(parser, PM_TOKEN_PARENTHESIS_LEFT)) {
Expand Down
2 changes: 2 additions & 0 deletions templates/src/diagnostic.c.erb
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
[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_AFTER_NOT_LPAREN] = { "expected a `(` immediately after `not`", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_EXPECT_LPAREN_AFTER_NOT_OTHER] = { "expected a `(` after `not`", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_EXPECT_LPAREN_REQ_PARAMETER] = { "expected a `(` to start a required parameter", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_EXPECT_MESSAGE] = { "unexpected %s; expecting a message to send to the receiver", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_EXPECT_RBRACKET] = { "expected a matching `]`", PM_ERROR_LEVEL_SYNTAX },
Expand Down
17 changes: 17 additions & 0 deletions test/prism/errors/command_calls_31.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
true && not true
^~~~ expected a `(` after `not`
^~~~ unexpected 'true', expecting end-of-input

true || not true
^~~~ expected a `(` after `not`
^~~~ unexpected 'true', expecting end-of-input

true && not (true)
^ expected a `(` immediately after `not`
^ unexpected '(', expecting end-of-input

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error message is a bit weird, but I am not sure how to fix it.


Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to add a test to confirm that

true && not
true

be rejected, but I am not sure how to write the test.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we can write something like this in test/prism/errors/command_calls_31.txt:

true && not
true
^~~~ expected a `(` after `not`
^~~~ unexpected 'true', expecting end-of-input

true && not
true
^~~~ expected a `(` after `not`
^~~~ unexpected 'true', expecting end-of-input

Loading