[前][次][番号順一覧][スレッド一覧]

ruby-changes:60538

From: Nobuyoshi <ko1@a...>
Date: Sat, 28 Mar 2020 06:14:09 +0900 (JST)
Subject: [ruby-changes:60538] 004c298738 (ruby_2_7): Allow newlines inside braced pattern

https://git.ruby-lang.org/ruby.git/commit/?id=004c298738

From 004c298738dc0924e7483b0c3f41c798dabe9e5b Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Mon, 2 Mar 2020 15:49:03 +0900
Subject: Allow newlines inside braced pattern

(cherry picked from commit f5c904c2a907013e22ff74bc3686952c5448d493)

diff --git a/parse.y b/parse.y
index b1a7e08..d249039 100644
--- a/parse.y
+++ b/parse.y
@@ -3937,12 +3937,17 @@ p_expr_basic	: p_value https://github.com/ruby/ruby/blob/trunk/parse.y#L3937
 			$$ = 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 ')' https://github.com/ruby/ruby/blob/trunk/parse.y#L5407
 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 a3b7dcf..f9217aa 100644
--- a/test/ruby/test_pattern_matching.rb
+++ b/test/ruby/test_pattern_matching.rb
@@ -1051,6 +1051,20 @@ END https://github.com/ruby/ruby/blob/trunk/test/ruby/test_pattern_matching.rb#L1051
       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":
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]