From f5c904c2a907013e22ff74bc3686952c5448d493 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 2 Mar 2020 15:49:03 +0900 Subject: [PATCH] Allow newlines inside braced pattern --- parse.y | 12 ++++++++++-- test/ruby/test_pattern_matching.rb | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/parse.y b/parse.y index 8314f07759..f0f2f8bbf9 100644 --- a/parse.y +++ b/parse.y @@ -3955,12 +3955,17 @@ p_expr_basic : p_value $$ = new_array_pattern_tail(p, Qnone, 0, 0, Qnone, &@$); $$ = new_array_pattern(p, Qnone, Qnone, $$, &@$); } - | tLBRACE {$$ = push_pktbl(p);} p_kwargs '}' + | tLBRACE + { + $$ = push_pktbl(p); + p->in_kwarg = 0; + } + p_kwargs rbrace { pop_pktbl(p, $2); $$ = new_hash_pattern(p, Qnone, $3, &@$); } - | tLBRACE '}' + | tLBRACE rbrace { $$ = new_hash_pattern_tail(p, Qnone, 0, &@$); $$ = new_hash_pattern(p, Qnone, $$, &@$); @@ -5420,6 +5425,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":