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

ruby-changes:60262

From: Nobuyoshi <ko1@a...>
Date: Mon, 2 Mar 2020 15:53:03 +0900 (JST)
Subject: [ruby-changes:60262] f5c904c2a9 (master): Allow newlines inside braced pattern

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

From f5c904c2a907013e22ff74bc3686952c5448d493 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


diff --git a/parse.y b/parse.y
index 8314f07..f0f2f8b 100644
--- a/parse.y
+++ b/parse.y
@@ -3955,12 +3955,17 @@ p_expr_basic	: p_value https://github.com/ruby/ruby/blob/trunk/parse.y#L3955
 			$$ = 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, $$, &@$);
@@ -5420,6 +5425,9 @@ rparen		: opt_nl ')' https://github.com/ruby/ruby/blob/trunk/parse.y#L5425
 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/

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