Skip to content

Commit 225cdaa

Browse files
matzclaude
andcommitted
mruby-compiler: eliminate bison shift-reduce conflict for 'in'
Add precedence declarations to resolve the ambiguity between: - One-line pattern match: `arg in pattern` - Case/in clause: `case expr; in pattern; end` When seeing `arg in`, the parser should shift to parse `arg in pattern` as a complete expression (matching CRuby behavior), not reduce `arg` to start a case clause. Changes: - Add keyword_in to %nonassoc precedence declarations - Add %prec tLOWEST to the plain `arg` reduction rule This eliminates all bison shift-reduce conflicts (was 2, now 0). Co-authored-by: Claude <noreply@anthropic.com>
1 parent a91ffcf commit 225cdaa

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

mrbgems/mruby-compiler/core/parse.y

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,7 +2153,7 @@ prohibit_literals(parser_state *p, node *n)
21532153
%nonassoc tLOWEST
21542154
%nonassoc tLBRACE_ARG
21552155

2156-
%nonassoc modifier_if modifier_unless modifier_while modifier_until
2156+
%nonassoc modifier_if modifier_unless modifier_while modifier_until keyword_in
21572157
%left keyword_or keyword_and
21582158
%right keyword_not
21592159
%right '=' tOP_ASGN
@@ -2447,7 +2447,7 @@ expr : command_call
24472447
p->in_kwarg--;
24482448
$$ = new_match_pat(p, $1, $4, FALSE);
24492449
}
2450-
| arg
2450+
| arg %prec tLOWEST
24512451
;
24522452

24532453
defn_head : keyword_def fname

0 commit comments

Comments
 (0)