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

ruby-changes:50704

From: nobu <ko1@a...>
Date: Wed, 21 Mar 2018 19:32:22 +0900 (JST)
Subject: [ruby-changes:50704] nobu:r62872 (trunk): parse.y: unindent continued line

nobu	2018-03-21 19:32:15 +0900 (Wed, 21 Mar 2018)

  New Revision: 62872

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

  Log:
    parse.y: unindent continued line
    
    * parse.y (tokadd_string): stop at continued line in dedented here
      documents, to dedent for each lines before removing escaped
      newlines.  [ruby-core:86236] [Bug #14621]

  Modified files:
    trunk/parse.y
    trunk/test/ruby/test_syntax.rb
Index: parse.y
===================================================================
--- parse.y	(revision 62871)
+++ parse.y	(revision 62872)
@@ -5642,7 +5642,14 @@ tokadd_string(struct parser_params *p, https://github.com/ruby/ruby/blob/trunk/parse.y#L5642
 	    switch (c) {
 	      case '\n':
 		if (func & STR_FUNC_QWORDS) break;
-		if (func & STR_FUNC_EXPAND) continue;
+		if (func & STR_FUNC_EXPAND) {
+		    if (!(func & STR_FUNC_INDENT) || (p->heredoc_indent < 0))
+			continue;
+		    if (c == term) {
+			c = '\\';
+			goto terminate;
+		    }
+		}
 		tokadd(p, '\\');
 		break;
 
@@ -5723,6 +5730,7 @@ tokadd_string(struct parser_params *p, https://github.com/ruby/ruby/blob/trunk/parse.y#L5730
         }
 	tokadd(p, c);
     }
+  terminate:
     if (enc) *encp = enc;
     return c;
 }
Index: test/ruby/test_syntax.rb
===================================================================
--- test/ruby/test_syntax.rb	(revision 62871)
+++ test/ruby/test_syntax.rb	(revision 62872)
@@ -721,6 +721,12 @@ e" https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L721
     assert_dedented_heredoc(expected, result)
   end
 
+  def test_dedented_heredoc_continued_line
+    result = "  1\\\n" "  2\n"
+    expected = "1\\\n" "2\n"
+    assert_dedented_heredoc(expected, result)
+  end
+
   def test_lineno_after_heredoc
     bug7559 = '[ruby-dev:46737]'
     expected, _, actual = __LINE__, <<eom, __LINE__

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

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