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

ruby-changes:47456

From: nobu <ko1@a...>
Date: Fri, 11 Aug 2017 10:27:31 +0900 (JST)
Subject: [ruby-changes:47456] nobu:r59572 (trunk): separate hash literal and keyword arguments

nobu	2017-08-11 10:27:24 +0900 (Fri, 11 Aug 2017)

  New Revision: 59572

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59572

  Log:
    separate hash literal and keyword arguments
    
    * compile.c (compile_array_keyword_arg): separate keyword splat
      inside hash literal from argument list.
    
    * parse.y (rparen): flag hash literal.

  Modified files:
    trunk/compile.c
    trunk/node.c
    trunk/parse.y
Index: parse.y
===================================================================
--- parse.y	(revision 59571)
+++ parse.y	(revision 59572)
@@ -2546,6 +2546,7 @@ primary		: literal https://github.com/ruby/ruby/blob/trunk/parse.y#L2546
 		    {
 		    /*%%%*/
 			$$ = new_hash($2);
+			$$->nd_alen = TRUE;
 		    /*%
 			$$ = dispatch1(hash, escape_Qundef($2));
 		    %*/
Index: node.c
===================================================================
--- node.c	(revision 59571)
+++ node.c	(revision 59572)
@@ -545,9 +545,16 @@ dump_node(VALUE buf, VALUE indent, int c https://github.com/ruby/ruby/blob/trunk/node.c#L545
 	break;
 
       case NODE_HASH:
-	ANN("hash constructor");
-	ANN("format: { [nd_head] }");
-	ANN("example: { 1 => 2, 3 => 4 }");
+	if (!node->nd_alen) {
+	    ANN("keyword arguments");
+	    ANN("format: nd_head");
+	    ANN("example: a: 1, b: 2");
+	}
+	else {
+	    ANN("hash constructor");
+	    ANN("format: { [nd_head] }");
+	    ANN("example: { 1 => 2, 3 => 4 }");
+	}
 	LAST_NODE;
 	F_NODE(nd_head, "contents");
 	break;
Index: compile.c
===================================================================
--- compile.c	(revision 59571)
+++ compile.c	(revision 59572)
@@ -3053,7 +3053,7 @@ compile_array_keyword_arg(rb_iseq_t *ise https://github.com/ruby/ruby/blob/trunk/compile.c#L3053
 
 	    assert(nd_type(node) == NODE_ARRAY);
 	    if (!key_node) {
-		if (flag) *flag |= VM_CALL_KW_SPLAT;
+		if (flag && !root_node->nd_alen) *flag |= VM_CALL_KW_SPLAT;
 		return FALSE;
 	    }
 	    else if (nd_type(key_node) == NODE_LIT && RB_TYPE_P(key_node->nd_lit, T_SYMBOL)) {

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

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