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

ruby-changes:49893

From: nobu <ko1@a...>
Date: Tue, 23 Jan 2018 11:31:47 +0900 (JST)
Subject: [ruby-changes:49893] nobu:r62011 (trunk): parse.y: concat dedented heredoc

nobu	2018-01-23 11:31:42 +0900 (Tue, 23 Jan 2018)

  New Revision: 62011

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

  Log:
    parse.y: concat dedented heredoc
    
    * parse.y (heredoc_dedent): concat literal strings after dedented.

  Modified files:
    trunk/parse.y
Index: parse.y
===================================================================
--- parse.y	(revision 62010)
+++ parse.y	(revision 62011)
@@ -435,6 +435,7 @@ static void reg_fragment_setenc(struct p https://github.com/ruby/ruby/blob/trunk/parse.y#L435
 static int reg_fragment_check(struct parser_params*, VALUE, int);
 static NODE *reg_named_capture_assign(struct parser_params* p, VALUE regexp, const YYLTYPE *loc);
 
+static int literal_concat0(struct parser_params *p, VALUE head, VALUE tail);
 static NODE *heredoc_dedent(struct parser_params*,NODE*);
 #define get_id(id) (id)
 #define get_value(val) (val)
@@ -6015,28 +6016,47 @@ dedent_string(VALUE string, int width) https://github.com/ruby/ruby/blob/trunk/parse.y#L6016
 static NODE *
 heredoc_dedent(struct parser_params *p, NODE *root)
 {
-    NODE *node, *str_node;
+    NODE *node, *str_node, *prev_node;
     int bol = TRUE;
     int indent = p->heredoc_indent;
+    VALUE prev_lit = 0;
 
     if (indent <= 0) return root;
     p->heredoc_indent = 0;
     if (!root) return root;
 
-    node = str_node = root;
+    prev_node = node = str_node = root;
     if (nd_type(root) == NODE_ARRAY) str_node = root->nd_head;
 
     while (str_node) {
 	VALUE lit = str_node->nd_lit;
 	if (bol) dedent_string(lit, indent);
 	bol = TRUE;
+	if (!prev_lit) {
+	    prev_lit = lit;
+	}
+	else if (!literal_concat0(p, prev_lit, lit)) {
+	    return 0;
+	}
+	else {
+	    node = prev_node->nd_next = node->nd_next;
+	    if (!node) {
+		if (nd_type(prev_node) == NODE_DSTR)
+		    nd_set_type(prev_node, NODE_STR);
+		break;
+	    }
+	    goto next_str;
+	}
 
 	str_node = 0;
-	while ((node = node->nd_next) != 0 && nd_type(node) == NODE_ARRAY) {
+	while ((node = (prev_node = node)->nd_next) != 0) {
+	  next_str:
+	    if (nd_type(node) != NODE_ARRAY) break;
 	    if ((str_node = node->nd_head) != 0) {
 		enum node_type type = nd_type(str_node);
 		if (type == NODE_STR || type == NODE_DSTR) break;
 		bol = FALSE;
+		prev_lit = 0;
 		str_node = 0;
 	    }
 	}

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

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