From 225cdaa16a24ff0287b86fab77fd7bbe34004a78 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Mon, 29 Dec 2025 17:56:54 +0900 Subject: [PATCH] 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 --- mrbgems/mruby-compiler/core/parse.y | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y index 63ddfca05..7e98f3bbc 100644 --- a/mrbgems/mruby-compiler/core/parse.y +++ b/mrbgems/mruby-compiler/core/parse.y @@ -2153,7 +2153,7 @@ prohibit_literals(parser_state *p, node *n) %nonassoc tLOWEST %nonassoc tLBRACE_ARG -%nonassoc modifier_if modifier_unless modifier_while modifier_until +%nonassoc modifier_if modifier_unless modifier_while modifier_until keyword_in %left keyword_or keyword_and %right keyword_not %right '=' tOP_ASGN @@ -2447,7 +2447,7 @@ expr : command_call p->in_kwarg--; $$ = new_match_pat(p, $1, $4, FALSE); } - | arg + | arg %prec tLOWEST ; defn_head : keyword_def fname