Skip to content

Commit ec5c11c

Browse files
authored
Merge pull request #3243 from ydah/reject-invalid-operator
Reject invalid operator after match predicate or after match required
2 parents 9ccb069 + d0d9699 commit ec5c11c

7 files changed

+45
-0
lines changed

src/prism.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21407,6 +21407,33 @@ parse_expression_infix(pm_parser_t *parser, pm_node_t *node, pm_binding_power_t
2140721407
case PM_TOKEN_STAR:
2140821408
case PM_TOKEN_STAR_STAR: {
2140921409
parser_lex(parser);
21410+
pm_token_t operator = parser->previous;
21411+
switch (PM_NODE_TYPE(node)) {
21412+
case PM_RESCUE_MODIFIER_NODE: {
21413+
pm_rescue_modifier_node_t *cast = (pm_rescue_modifier_node_t *) node;
21414+
if (PM_NODE_TYPE_P(cast->rescue_expression, PM_MATCH_PREDICATE_NODE) || PM_NODE_TYPE_P(cast->rescue_expression, PM_MATCH_REQUIRED_NODE)) {
21415+
PM_PARSER_ERR_TOKEN_FORMAT(parser, operator, PM_ERR_EXPECT_EOL_AFTER_STATEMENT, pm_token_type_human(operator.type));
21416+
}
21417+
break;
21418+
}
21419+
case PM_AND_NODE: {
21420+
pm_and_node_t *cast = (pm_and_node_t *) node;
21421+
if (PM_NODE_TYPE_P(cast->right, PM_MATCH_PREDICATE_NODE) || PM_NODE_TYPE_P(cast->right, PM_MATCH_REQUIRED_NODE)) {
21422+
PM_PARSER_ERR_TOKEN_FORMAT(parser, operator, PM_ERR_EXPECT_EOL_AFTER_STATEMENT, pm_token_type_human(operator.type));
21423+
}
21424+
break;
21425+
}
21426+
case PM_OR_NODE: {
21427+
pm_or_node_t *cast = (pm_or_node_t *) node;
21428+
if (PM_NODE_TYPE_P(cast->right, PM_MATCH_PREDICATE_NODE) || PM_NODE_TYPE_P(cast->right, PM_MATCH_REQUIRED_NODE)) {
21429+
PM_PARSER_ERR_TOKEN_FORMAT(parser, operator, PM_ERR_EXPECT_EOL_AFTER_STATEMENT, pm_token_type_human(operator.type));
21430+
}
21431+
break;
21432+
}
21433+
default:
21434+
break;
21435+
}
21436+
2141021437
pm_node_t *argument = parse_expression(parser, binding_power, false, false, PM_ERR_EXPECT_EXPRESSION_AFTER_OPERATOR, (uint16_t) (depth + 1));
2141121438
return (pm_node_t *) pm_call_node_binary_create(parser, node, &token, argument, 0);
2141221439
}
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)