Skip to content
Open
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
9 changes: 8 additions & 1 deletion src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -22343,14 +22343,21 @@ 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: {
// These expressions are also statements, by virtue of the
// right-hand side of the expression (i.e., the last argument to
// the call node) being an implicit array.
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;
}

pm_call_node_t *cast = (pm_call_node_t *) node;
if (cast->arguments != NULL && cast->opening_loc.start == NULL && (pm_binding_powers[parser->current.type].left >= PM_BINDING_POWER_MATCH && pm_binding_powers[parser->current.type].left < PM_BINDING_POWER_TERNARY)) {
return node;
}
Copy link
Member

Choose a reason for hiding this comment

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

I need @kddnewton's opinion here, but I feel like testing for a specific token isn't the right fix and that we should be using binding power instead (but this is just a gut feeling). Is in the only keyword that has a problem?

Copy link
Member

@tompng tompng Oct 1, 2025

Choose a reason for hiding this comment

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

Is in the only keyword that has a problem?

Looks like in, =>, ., &. and all binary operators except + - ** & * are wrongly accepted after A.print message: but not after a.print message:

Copy link
Member

Choose a reason for hiding this comment

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

And ternary operator A.print message: ? 1 : 2

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @tenderlove that this is not the correct fix. The code that is supposed to handle this is here:

prism/src/prism.c

Lines 22253 to 22261 in ce4abe1

case PM_CALL_NODE:
// If we have a call node, then we need to check if it looks like a
// method call without parentheses that contains arguments. If it
// does, then it has different rules for parsing infix operators,
// namely that it only accepts composition (and/or) and modifiers
// (if/unless/etc.).
if ((pm_binding_powers[parser->current.type].left > PM_BINDING_POWER_COMPOSITION) && pm_call_node_command_p((pm_call_node_t *) node)) {
return node;
}

But parse_expression_prefix returns PM_CONSTANT_READ_NODE. So I feel like the fix would be to modify parse_expression_prefix so that it parses further instead of just one node deep. Or this check is also needed at some other place.

But I did not manage to actually fix it myself last I looked into this.


break;
}
default:
break;
}
Expand Down
13 changes: 13 additions & 0 deletions test/prism/errors/command_call_in.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,17 @@ foo 1 in a
^~ unexpected 'in', expecting end-of-input
^~ unexpected 'in', ignoring it
a = foo 2 in b
A.print foo in 'BAR'
^~ unexpected 'in', expecting end-of-input
^~ unexpected 'in', ignoring it
A.print foo: bar in 'BAR'
^~ unexpected 'in', expecting end-of-input
^~ unexpected 'in', ignoring it
A.print message: in 'BAR'
^~ unexpected 'in', expecting end-of-input
^~ unexpected 'in', ignoring it
A.print message:
in 'BAR'
^~ unexpected 'in', expecting end-of-input
^~ unexpected 'in', ignoring it