Skip to content

Commit 795619e

Browse files
Earlopainmatzbot
authored andcommitted
[ruby/prism] Revert "Reject infix operators on command call on
writes" (ruby/prism#3960) This reverts commit ruby/prism@4e71dbfc7bd9. And also add a regression test. Seems like currently prism parses these the same that parse.y does. ruby/prism@03993421f2
1 parent 4d7f3ba commit 795619e

4 files changed

Lines changed: 6 additions & 33 deletions

File tree

prism/prism.c

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21619,26 +21619,6 @@ pm_call_node_command_p(const pm_call_node_t *node) {
2161921619
);
2162021620
}
2162121621

21622-
/**
21623-
* Determine if a given write node has a command call as its right-hand side. We
21624-
* need this because command calls as the values of writes cannot be extended by
21625-
* infix operators.
21626-
*/
21627-
static inline bool
21628-
pm_write_node_command_p(const pm_node_t *node) {
21629-
pm_node_t *value;
21630-
switch (PM_NODE_TYPE(node)) {
21631-
case PM_CLASS_VARIABLE_WRITE_NODE: value = ((pm_class_variable_write_node_t *) node)->value; break;
21632-
case PM_CONSTANT_PATH_WRITE_NODE: value = ((pm_constant_path_write_node_t *) node)->value; break;
21633-
case PM_CONSTANT_WRITE_NODE: value = ((pm_constant_write_node_t *) node)->value; break;
21634-
case PM_GLOBAL_VARIABLE_WRITE_NODE: value = ((pm_global_variable_write_node_t *) node)->value; break;
21635-
case PM_INSTANCE_VARIABLE_WRITE_NODE: value = ((pm_instance_variable_write_node_t *) node)->value; break;
21636-
case PM_LOCAL_VARIABLE_WRITE_NODE: value = ((pm_local_variable_write_node_t *) node)->value; break;
21637-
default: return false;
21638-
}
21639-
return PM_NODE_TYPE_P(value, PM_CALL_NODE) && pm_call_node_command_p((pm_call_node_t *) value);
21640-
}
21641-
2164221622
/**
2164321623
* Parse an expression at the given point of the parser using the given binding
2164421624
* power to parse subsequent chains. If this function finds a syntax error, it
@@ -21723,13 +21703,9 @@ parse_expression(pm_parser_t *parser, pm_binding_power_t binding_power, bool acc
2172321703
case PM_INSTANCE_VARIABLE_WRITE_NODE:
2172421704
case PM_LOCAL_VARIABLE_WRITE_NODE:
2172521705
// These expressions are statements, by virtue of the right-hand
21726-
// side of their write being an implicit array or a command call.
21727-
// This mirrors parse.y's behavior where `lhs = command_call`
21728-
// reduces to stmt (not expr), preventing and/or from following.
21729-
if (pm_binding_powers[parser->current.type].left > PM_BINDING_POWER_MODIFIER) {
21730-
if (PM_NODE_FLAG_P(node, PM_WRITE_NODE_FLAGS_IMPLICIT_ARRAY) || pm_write_node_command_p(node)) {
21731-
return node;
21732-
}
21706+
// side of their write being an implicit array.
21707+
if (PM_NODE_FLAG_P(node, PM_WRITE_NODE_FLAGS_IMPLICIT_ARRAY) && pm_binding_powers[parser->current.type].left > PM_BINDING_POWER_MODIFIER) {
21708+
return node;
2173321709
}
2173421710
break;
2173521711
case PM_CALL_NODE:

test/prism/errors/command_call_in.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@ foo 1 in a
22
^~ unexpected 'in', expecting end-of-input
33
^~ unexpected 'in', ignoring it
44
a = foo 2 in b
5-
^~ unexpected 'in', expecting end-of-input
6-
^~ unexpected 'in', ignoring it
75

test/prism/errors/write_command.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
foo = 123 | '456' or return
2+
3+
foo = 123 | '456' in BAR

0 commit comments

Comments
 (0)