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>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2025-12-29 17:56:54 +09:00
parent a91ffcfe0d
commit 225cdaa16a
+2 -2
View File
@@ -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