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
17 changes: 16 additions & 1 deletion src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -21621,7 +21621,7 @@ parse_expression(pm_parser_t *parser, pm_binding_power_t binding_power, bool acc
return node;
}
break;
case PM_CALL_NODE:
case PM_CALL_NODE: {
// A do-block can attach to a command-style call
// produced by infix operators (e.g., dot-calls like
// `obj.method args do end`).
Expand All @@ -21635,7 +21635,22 @@ parse_expression(pm_parser_t *parser, pm_binding_power_t binding_power, bool acc
if (PM_NODE_FLAG_P(node, PM_CALL_NODE_FLAGS_IMPLICIT_ARRAY) && pm_binding_powers[parser->current.type].left > PM_BINDING_POWER_MODIFIER) {
return node;
}

// Command-style calls (calls with arguments but without
// parentheses) only accept composition (and/or) and modifier
// (if/unless/etc.) operators. We need to exclude operator calls
// (e.g., a + b) which also satisfy pm_call_node_command_p but
// are not commands.
const pm_call_node_t *cast = (const pm_call_node_t *) node;
if (
(pm_binding_powers[parser->current.type].left > PM_BINDING_POWER_COMPOSITION) &&
(cast->receiver == NULL || cast->call_operator_loc.length > 0) &&
pm_call_node_command_p(cast)
) {
return node;
}
break;
}
case PM_RESCUE_MODIFIER_NODE:
// A rescue modifier whose handler is a one-liner pattern match
// (=> or in) produces a statement. That means it cannot be
Expand Down
4 changes: 4 additions & 0 deletions test/prism/errors/command_call_in_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
a.b x in pattern
^~ unexpected 'in', expecting end-of-input
^~ unexpected 'in', ignoring it

4 changes: 4 additions & 0 deletions test/prism/errors/command_call_in_3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
a.b x: in pattern
^~ unexpected 'in', expecting end-of-input
^~ unexpected 'in', ignoring it

4 changes: 4 additions & 0 deletions test/prism/errors/command_call_in_4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
a.b &x in pattern
^~ unexpected 'in', expecting end-of-input
^~ unexpected 'in', ignoring it

4 changes: 4 additions & 0 deletions test/prism/errors/command_call_in_5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
a.b *x => pattern
^~ unexpected '=>', expecting end-of-input
^~ unexpected '=>', ignoring it

4 changes: 4 additions & 0 deletions test/prism/errors/command_call_in_6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
a.b x: => pattern
^~ unexpected '=>', expecting end-of-input
^~ unexpected '=>', ignoring it

4 changes: 4 additions & 0 deletions test/prism/errors/command_call_in_7.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
a.b &x => pattern
^~ unexpected '=>', expecting end-of-input
^~ unexpected '=>', ignoring it

4 changes: 0 additions & 4 deletions test/prism/errors_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ def test_unterminated_empty_string_closing
assert_nil statement.closing
end

def test_invalid_message_name
assert_equal :"", Prism.parse_statement("+.@foo,+=foo").write_name
end

def test_regexp_encoding_option_mismatch_error
# UTF-8 char with ASCII-8BIT modifier
result = Prism.parse('/Ȃ/n')
Expand Down