Skip to content

Commit

Permalink
+ ruby31.y: Allow value omission in Hash literals
Browse files Browse the repository at this point in the history
Closes #817.

This commit tracks upstream commit ruby/ruby@c60dbcd
  • Loading branch information
skryukov committed Sep 21, 2021
1 parent c7854d0 commit f096464
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/parser/ruby31.y
Expand Up @@ -3098,6 +3098,11 @@ f_opt_paren_args: f_paren_args
{
result = @builder.pair_keyword(val[0], val[1])
}
| tLABEL
{
value = @builder.call_method(nil, nil, val[0])
result = @builder.pair_keyword(val[0], value)
}
| tSTRING_BEG string_contents tLABEL_END arg_value
{
result = @builder.pair_quoted(val[0], val[1], val[2], val[3])
Expand Down
15 changes: 15 additions & 0 deletions test/test_parser.rb
Expand Up @@ -10054,6 +10054,21 @@ def test_private_endless_method_command_syntax
SINCE_3_1)
end

def test_value_omission
assert_parses(
s(:hash,
s(:pair, s(:sym, :a), s(:send, nil, :a)),
s(:pair, s(:sym, :b), s(:send, nil, :b))),
%q{{a:, b:}},
%q{^ begin
| ^ end
| ^ operator (pair)
| ~ expression (pair.sym)
| ~~ expression (pair)
|~~~~~~~~ expression},
SINCE_3_1)
end

def test_rasgn_line_continuation
assert_diagnoses(
[:error, :unexpected_token, { :token => 'tASSOC' }],
Expand Down

0 comments on commit f096464

Please sign in to comment.