Skip to content

Commit

Permalink
parse.y: allow value omission in Hash literals introduced in Ruby3.1.
Browse files Browse the repository at this point in the history
`{x:, y:}` now is a syntax sugar of `{x: x, y: y}`.

This fix also includes the update of #4815 fix.
  • Loading branch information
matz committed Sep 13, 2021
1 parent 31fc74f commit 6c76926
Show file tree
Hide file tree
Showing 3 changed files with 3,375 additions and 3,443 deletions.
19 changes: 9 additions & 10 deletions mrbgems/mruby-compiler/core/parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -2585,8 +2585,7 @@ opt_block_arg : comma block_arg
}
;

comma : ','
| ',' opt_nl heredoc_bodies
comma : ',' opt_nl
;

args : arg
Expand Down Expand Up @@ -3995,22 +3994,22 @@ assocs : assoc
}
;

label_tag : tLABEL_TAG
| tLABEL_TAG heredoc_bodies
;

assoc : arg tASSOC arg
{
void_expr_error(p, $1);
void_expr_error(p, $3);
$$ = cons($1, $3);
}
| tIDENTIFIER label_tag arg
| tIDENTIFIER tLABEL_TAG arg
{
void_expr_error(p, $3);
$$ = cons(new_sym(p, $1), $3);
}
| string_fragment label_tag arg
| tIDENTIFIER tLABEL_TAG
{
$$ = cons(new_sym(p, $1), new_lvar(p, $1));
}
| string_fragment tLABEL_TAG arg
{
void_expr_error(p, $3);
if (typen($1->car) == NODE_DSTR) {
Expand Down Expand Up @@ -4069,7 +4068,7 @@ opt_terms : /* none */
;

opt_nl : /* none */
| nl
| opt_nl nl
;

rparen : opt_terms ')'
Expand All @@ -4082,14 +4081,14 @@ trailer : /* none */

term : ';' {yyerrok;}
| nl
| heredoc_body
;

nl : '\n'
{
p->lineno += $<num>1;
p->column = 0;
}
| heredoc_body
;

terms : term
Expand Down
Loading

0 comments on commit 6c76926

Please sign in to comment.