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

ruby-changes:43938

From: nobu <ko1@a...>
Date: Fri, 26 Aug 2016 17:29:25 +0900 (JST)
Subject: [ruby-changes:43938] nobu:r56011 (trunk): parse.y: new_xstring_gen

nobu	2016-08-26 17:29:18 +0900 (Fri, 26 Aug 2016)

  New Revision: 56011

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

  Log:
    parse.y: new_xstring_gen
    
    * parse.y (new_xstring_gen): extract from the rule.

  Modified files:
    trunk/parse.y
Index: parse.y
===================================================================
--- parse.y	(revision 56010)
+++ parse.y	(revision 56011)
@@ -504,6 +504,9 @@ static NODE *new_hash_gen(struct parser_ https://github.com/ruby/ruby/blob/trunk/parse.y#L504
 static NODE *new_regexp_gen(struct parser_params *, NODE *, int);
 #define new_regexp(node, opt) new_regexp_gen(parser, node, opt)
 
+static NODE *new_xstring_gen(struct parser_params *, NODE *);
+#define new_xstring(node) new_xstring_gen(parser, node)
+
 static NODE *match_op_gen(struct parser_params*,NODE*,NODE*);
 #define match_op(node1,node2) match_op_gen(parser, (node1), (node2))
 
@@ -564,6 +567,9 @@ static VALUE new_attr_op_assign_gen(stru https://github.com/ruby/ruby/blob/trunk/parse.y#L567
 static VALUE new_regexp_gen(struct parser_params *, VALUE, VALUE);
 #define new_regexp(node, opt) new_regexp_gen(parser, node, opt)
 
+static VALUE new_xstring_gen(struct parser_params *, VALUE);
+#define new_xstring(str) new_xstring_gen(parser, str)
+
 #define const_path_field(w, n) dispatch2(const_path_field, (w), (n))
 #define top_const_field(n) dispatch1(top_const_field, (n))
 static VALUE const_decl_gen(struct parser_params *parser, VALUE path);
@@ -3898,33 +3904,9 @@ string1		: tSTRING_BEG string_contents t https://github.com/ruby/ruby/blob/trunk/parse.y#L3904
 
 xstring		: tXSTRING_BEG xstring_contents tSTRING_END
 		    {
-		    /*%%%*/
-			NODE *node = $2;
-		    /*%
-		    %*/
 			heredoc_dedent($2);
 			heredoc_indent = 0;
-		    /*%%%*/
-			if (!node) {
-			    node = NEW_XSTR(STR_NEW0());
-			}
-			else {
-			    switch (nd_type(node)) {
-			      case NODE_STR:
-				nd_set_type(node, NODE_XSTR);
-				break;
-			      case NODE_DSTR:
-				nd_set_type(node, NODE_DXSTR);
-				break;
-			      default:
-				node = NEW_NODE(NODE_DXSTR, Qnil, 1, NEW_LIST(node));
-				break;
-			    }
-			}
-			$$ = node;
-		    /*%
-			$$ = dispatch1(xstring_literal, $2);
-		    %*/
+			$$ = new_xstring($2);
 		    }
 		;
 
@@ -9118,6 +9100,26 @@ new_regexp_gen(struct parser_params *par https://github.com/ruby/ruby/blob/trunk/parse.y#L9100
     }
     return node;
 }
+
+static NODE *
+new_xstring_gen(struct parser_params *parser, NODE *node)
+{
+    if (!node) {
+	return NEW_XSTR(STR_NEW0());
+    }
+    switch (nd_type(node)) {
+      case NODE_STR:
+	nd_set_type(node, NODE_XSTR);
+	break;
+      case NODE_DSTR:
+	nd_set_type(node, NODE_DXSTR);
+	break;
+      default:
+	node = NEW_NODE(NODE_DXSTR, Qnil, 1, NEW_LIST(node));
+	break;
+    }
+    return node;
+}
 #else  /* !RIPPER */
 static int
 id_is_var_gen(struct parser_params *parser, ID id)
@@ -9155,6 +9157,12 @@ new_regexp_gen(struct parser_params *par https://github.com/ruby/ruby/blob/trunk/parse.y#L9157
     }
     return dispatch2(regexp_literal, re, opt);
 }
+
+static VALUE
+new_xstring_gen(struct parser_params *parser, VALUE str)
+{
+    return dispatch1(xstring_literal, str);
+}
 #endif /* !RIPPER */
 
 static const char lex_state_names[][13] = {

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

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