Skip to content

Commit

Permalink
Allow newlines inside braced pattern
Browse files Browse the repository at this point in the history
(cherry picked from commit f5c904c)
  • Loading branch information
nobu authored and nurse committed Mar 27, 2020
1 parent 93aaa0b commit 004c298
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
12 changes: 10 additions & 2 deletions parse.y
Expand Up @@ -3937,12 +3937,17 @@ p_expr_basic : p_value
$$ = new_array_pattern_tail(p, Qnone, 0, 0, Qnone, &@$);
$$ = new_array_pattern(p, Qnone, Qnone, $$, &@$);
}
| tLBRACE {$<tbl>$ = push_pktbl(p);} p_kwargs '}'
| tLBRACE
{
$<tbl>$ = push_pktbl(p);
p->in_kwarg = 0;
}
p_kwargs rbrace
{
pop_pktbl(p, $<tbl>2);
$$ = new_hash_pattern(p, Qnone, $3, &@$);
}
| tLBRACE '}'
| tLBRACE rbrace
{
$$ = new_hash_pattern_tail(p, Qnone, 0, &@$);
$$ = new_hash_pattern(p, Qnone, $$, &@$);
Expand Down Expand Up @@ -5402,6 +5407,9 @@ rparen : opt_nl ')'
rbracket : opt_nl ']'
;

rbrace : opt_nl '}'
;

trailer : /* none */
| '\n'
| ','
Expand Down
14 changes: 14 additions & 0 deletions test/ruby/test_pattern_matching.rb
Expand Up @@ -1051,6 +1051,20 @@ def test_hash_pattern
end
end
assert_block do
case {a: 0}
in {a: 1
}
false
in {a:
2}
false
in {a:
}
true
end
end
assert_syntax_error(%q{
case _
in "a-b":
Expand Down

0 comments on commit 004c298

Please sign in to comment.