Skip to content

Commit

Permalink
+ ruby27.y: Allow trailing comma in hash pattern (#661)
Browse files Browse the repository at this point in the history
This commit tracks upstream commit ruby/ruby@93aaa0b.

This is the following commit cherry picked from 2.8.0-dev to 2.7.1.
ruby/ruby@d25a4f4

Closes #655.
  • Loading branch information
koic committed Apr 1, 2020
1 parent 2ee965a commit 900a652
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/parser/ruby27.y
Expand Up @@ -1986,6 +1986,10 @@ opt_block_args_tail:
{
result = val[0]
}
| p_kwarg tCOMMA
{
result = val[0]
}
| p_kwrest
{
result = val[0]
Expand Down
12 changes: 12 additions & 0 deletions test/test_parser.rb
Expand Up @@ -8675,6 +8675,18 @@ def test_pattern_matching_hash
| ~ end (in_pattern.hash_pattern)}
)

assert_parses_pattern_match(
s(:in_pattern,
s(:hash_pattern,
s(:pair, s(:sym, :a), s(:int, 1))),
nil,
s(:true)),
%q{in { a: 1, } then true},
%q{ ~~~~~~~~~ expression (in_pattern.hash_pattern)
| ~ begin (in_pattern.hash_pattern)
| ~ end (in_pattern.hash_pattern)}
)

assert_parses_pattern_match(
s(:in_pattern,
s(:hash_pattern,
Expand Down

0 comments on commit 900a652

Please sign in to comment.