Skip to content

Commit d0d9699

Browse files
committed
Reject invalid operator after match predicate or after match required
Partially fixes: #3171
1 parent 93c0474 commit d0d9699

7 files changed

+45
-0
lines changed

src/prism.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21403,6 +21403,33 @@ parse_expression_infix(pm_parser_t *parser, pm_node_t *node, pm_binding_power_t
2140321403
case PM_TOKEN_STAR:
2140421404
case PM_TOKEN_STAR_STAR: {
2140521405
parser_lex(parser);
21406+
pm_token_t operator = parser->previous;
21407+
switch (PM_NODE_TYPE(node)) {
21408+
case PM_RESCUE_MODIFIER_NODE: {
21409+
pm_rescue_modifier_node_t *cast = (pm_rescue_modifier_node_t *) node;
21410+
if (PM_NODE_TYPE_P(cast->rescue_expression, PM_MATCH_PREDICATE_NODE) || PM_NODE_TYPE_P(cast->rescue_expression, PM_MATCH_REQUIRED_NODE)) {
21411+
PM_PARSER_ERR_TOKEN_FORMAT(parser, operator, PM_ERR_EXPECT_EOL_AFTER_STATEMENT, pm_token_type_human(operator.type));
21412+
}
21413+
break;
21414+
}
21415+
case PM_AND_NODE: {
21416+
pm_and_node_t *cast = (pm_and_node_t *) node;
21417+
if (PM_NODE_TYPE_P(cast->right, PM_MATCH_PREDICATE_NODE) || PM_NODE_TYPE_P(cast->right, PM_MATCH_REQUIRED_NODE)) {
21418+
PM_PARSER_ERR_TOKEN_FORMAT(parser, operator, PM_ERR_EXPECT_EOL_AFTER_STATEMENT, pm_token_type_human(operator.type));
21419+
}
21420+
break;
21421+
}
21422+
case PM_OR_NODE: {
21423+
pm_or_node_t *cast = (pm_or_node_t *) node;
21424+
if (PM_NODE_TYPE_P(cast->right, PM_MATCH_PREDICATE_NODE) || PM_NODE_TYPE_P(cast->right, PM_MATCH_REQUIRED_NODE)) {
21425+
PM_PARSER_ERR_TOKEN_FORMAT(parser, operator, PM_ERR_EXPECT_EOL_AFTER_STATEMENT, pm_token_type_human(operator.type));
21426+
}
21427+
break;
21428+
}
21429+
default:
21430+
break;
21431+
}
21432+
2140621433
pm_node_t *argument = parse_expression(parser, binding_power, false, false, PM_ERR_EXPECT_EXPRESSION_AFTER_OPERATOR, (uint16_t) (depth + 1));
2140721434
return (pm_node_t *) pm_call_node_binary_create(parser, node, &token, argument, 0);
2140821435
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1 and 2 in 3 % 4
2+
^ unexpected '%', expecting end-of-input
3+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1 or 2 in 3 + 4
2+
^ unexpected '+', expecting end-of-input
3+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1 rescue 2 in 3 << 4
2+
^~ unexpected <<, expecting end-of-input
3+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1 and 2 => 3 - 4
2+
^ unexpected '-', expecting end-of-input
3+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1 or 2 => 3 ^ 4
2+
^ unexpected '^', expecting end-of-input
3+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1 rescue 2 => 3 ** 4
2+
^~ unexpected '**', expecting end-of-input
3+

0 commit comments

Comments
 (0)