mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
parse.y: allow value omission in Hash literals introduced in Ruby3.1.
`{x:, y:}` now is a syntax sugar of `{x: x, y: y}`.
This fix also includes the update of #4815 fix.
This commit is contained in:
@@ -2585,8 +2585,7 @@ opt_block_arg : comma block_arg
|
||||
}
|
||||
;
|
||||
|
||||
comma : ','
|
||||
| ',' opt_nl heredoc_bodies
|
||||
comma : ',' opt_nl
|
||||
;
|
||||
|
||||
args : arg
|
||||
@@ -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) {
|
||||
@@ -4069,7 +4068,7 @@ opt_terms : /* none */
|
||||
;
|
||||
|
||||
opt_nl : /* none */
|
||||
| nl
|
||||
| opt_nl nl
|
||||
;
|
||||
|
||||
rparen : opt_terms ')'
|
||||
@@ -4082,7 +4081,6 @@ trailer : /* none */
|
||||
|
||||
term : ';' {yyerrok;}
|
||||
| nl
|
||||
| heredoc_body
|
||||
;
|
||||
|
||||
nl : '\n'
|
||||
@@ -4090,6 +4088,7 @@ nl : '\n'
|
||||
p->lineno += $<num>1;
|
||||
p->column = 0;
|
||||
}
|
||||
| heredoc_body
|
||||
;
|
||||
|
||||
terms : term
|
||||
|
||||
+3585
-3658
File diff suppressed because it is too large
Load Diff
@@ -1006,3 +1006,9 @@ assert('#== receiver should be specified value') do
|
||||
%i[has_value? value?].each{|m| assert_nothing_raised{h.__send__(m, v1)}}
|
||||
end
|
||||
end
|
||||
|
||||
assert('test value ommision') do
|
||||
x = 1
|
||||
y = 2
|
||||
assert_equal({x:1, y:2}, {x:, y:})
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user