mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user