diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-03-02 15:49:03 +0900 |
---|---|---|
committer | NARUSE, Yui <naruse@airemix.jp> | 2020-03-27 14:57:42 +0900 |
commit | 004c298738dc0924e7483b0c3f41c798dabe9e5b (patch) | |
tree | 95a0ce32442772382a2e1c3dced844ab3f5b5581 | |
parent | 93aaa0bcce829b880d8f52a9168d17c93ecde85b (diff) |
Allow newlines inside braced pattern
(cherry picked from commit f5c904c2a907013e22ff74bc3686952c5448d493)
-rw-r--r-- | parse.y | 12 | ||||
-rw-r--r-- | test/ruby/test_pattern_matching.rb | 14 |
2 files changed, 24 insertions, 2 deletions
@@ -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, $$, &@$); @@ -5402,6 +5407,9 @@ rparen : opt_nl ')' rbracket : opt_nl ']' ; +rbrace : opt_nl '}' + ; + trailer : /* none */ | '\n' | ',' diff --git a/test/ruby/test_pattern_matching.rb b/test/ruby/test_pattern_matching.rb index a3b7dcfd18..f9217aa7da 100644 --- a/test/ruby/test_pattern_matching.rb +++ b/test/ruby/test_pattern_matching.rb @@ -1051,6 +1051,20 @@ END 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": |