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

ruby-changes:25279

From: nobu <ko1@a...>
Date: Fri, 26 Oct 2012 13:24:43 +0900 (JST)
Subject: [ruby-changes:25279] nobu:r37331 (trunk): parse.y: concatenated literals

nobu	2012-10-26 13:24:29 +0900 (Fri, 26 Oct 2012)

  New Revision: 37331

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37331

  Log:
    parse.y: concatenated literals
    
    * parse.y (literal_concat_gen): merge fixed strings across
      concatenated literals, after an interpolation.

  Modified files:
    trunk/ChangeLog
    trunk/parse.y

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 37330)
+++ ChangeLog	(revision 37331)
@@ -1,3 +1,8 @@
+Fri Oct 26 13:24:20 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (literal_concat_gen): merge fixed strings across
+	  concatenated literals, after an interpolation.
+
 Thu Oct 25 17:48:54 2012  NAKAMURA Usaku  <usa@r...>
 
 	* win32/win32.c (has_redirection): should use shell (cmd.exe) when
Index: parse.y
===================================================================
--- parse.y	(revision 37330)
+++ parse.y	(revision 37331)
@@ -8246,6 +8246,8 @@
 literal_concat_gen(struct parser_params *parser, NODE *head, NODE *tail)
 {
     enum node_type htype;
+    NODE *headlast;
+    VALUE lit;
 
     if (!head) return tail;
     if (!tail) return head;
@@ -8254,11 +8256,20 @@
     if (htype == NODE_EVSTR) {
 	NODE *node = NEW_DSTR(Qnil);
 	head = list_append(node, head);
+	htype = NODE_DSTR;
     }
     switch (nd_type(tail)) {
       case NODE_STR:
+	if (htype == NODE_DSTR && (headlast = head->nd_next->nd_end->nd_head) &&
+	    nd_type(headlast) == NODE_STR) {
+	    htype = NODE_STR;
+	    lit = headlast->nd_lit;
+	}
+	else {
+	    lit = head->nd_lit;
+	}
 	if (htype == NODE_STR) {
-	    if (!literal_concat0(parser, head->nd_lit, tail->nd_lit)) {
+	    if (!literal_concat0(parser, lit, tail->nd_lit)) {
 	      error:
 		rb_gc_force_recycle((VALUE)head);
 		rb_gc_force_recycle((VALUE)tail);
@@ -8280,11 +8291,20 @@
 	    head = tail;
 	}
 	else if (NIL_P(tail->nd_lit)) {
+	  append:
 	    head->nd_alen += tail->nd_alen - 1;
 	    head->nd_next->nd_end->nd_next = tail->nd_next;
 	    head->nd_next->nd_end = tail->nd_next->nd_end;
 	    rb_gc_force_recycle((VALUE)tail);
 	}
+	else if (htype == NODE_DSTR && (headlast = head->nd_next->nd_end->nd_head) &&
+		 nd_type(headlast) == NODE_STR) {
+	    lit = headlast->nd_lit;
+	    if (!literal_concat0(parser, lit, tail->nd_lit))
+		goto error;
+	    tail->nd_lit = Qnil;
+	    goto append;
+	}
 	else {
 	    nd_set_type(tail, NODE_ARRAY);
 	    tail->nd_head = NEW_STR(tail->nd_lit);

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

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