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

ruby-changes:54831

From: nagachika <ko1@a...>
Date: Mon, 11 Feb 2019 20:04:46 +0900 (JST)
Subject: [ruby-changes:54831] nagachika:r67050 (ruby_2_5): merge revision(s) 62872, 62873: [Backport #14621]

nagachika	2019-02-11 20:04:41 +0900 (Mon, 11 Feb 2019)

  New Revision: 67050

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

  Log:
    merge revision(s) 62872,62873: [Backport #14621]
    
    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]
    
    parse.y: terminator at continued line
    
    * parse.y (here_document): a continuing line is not the
      terminator.  [ruby-core:86283] [Bug #14621]

  Modified directories:
    branches/ruby_2_5/
  Modified files:
    branches/ruby_2_5/parse.y
    branches/ruby_2_5/test/ruby/test_syntax.rb
    branches/ruby_2_5/version.h
Index: ruby_2_5/parse.y
===================================================================
--- ruby_2_5/parse.y	(revision 67049)
+++ ruby_2_5/parse.y	(revision 67050)
@@ -6394,7 +6394,14 @@ parser_tokadd_string(struct parser_param https://github.com/ruby/ruby/blob/trunk/ruby_2_5/parse.y#L6394
 	    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) || (heredoc_indent < 0))
+			continue;
+		    if (c == term) {
+			c = '\\';
+			goto terminate;
+		    }
+		}
 		tokadd('\\');
 		break;
 
@@ -6475,6 +6482,7 @@ parser_tokadd_string(struct parser_param https://github.com/ruby/ruby/blob/trunk/ruby_2_5/parse.y#L6482
         }
 	tokadd(c);
     }
+  terminate:
     if (enc) *encp = enc;
     return c;
 }
@@ -7019,7 +7027,13 @@ parser_here_document(struct parser_param https://github.com/ruby/ruby/blob/trunk/ruby_2_5/parse.y#L7027
 	return 0;
     }
     bol = was_bol();
-    if (bol && whole_match_p(eos, len, indent)) {
+    /* `heredoc_line_indent == -1` means
+     * - "after an interpolation in the same line", or
+     * - "in a continuing line"
+     */
+    if (bol &&
+        (heredoc_line_indent != -1 || (heredoc_line_indent = 0)) &&
+	whole_match_p(eos, len, indent)) {
 	dispatch_heredoc_end();
 	heredoc_restore(&lex_strterm->u.heredoc);
 	lex_strterm = 0;
@@ -7090,6 +7104,7 @@ parser_here_document(struct parser_param https://github.com/ruby/ruby/blob/trunk/ruby_2_5/parse.y#L7104
 		goto restore;
 	    }
 	    if (c != '\n') {
+		if (c == '\\') heredoc_line_indent = -1;
 	      flush:
 		str = STR_NEW3(tok(), toklen(), enc, func);
 	      flush_str:
Index: ruby_2_5/version.h
===================================================================
--- ruby_2_5/version.h	(revision 67049)
+++ ruby_2_5/version.h	(revision 67050)
@@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_5/version.h#L1
 #define RUBY_VERSION "2.5.4"
-#define RUBY_RELEASE_DATE "2019-02-05"
-#define RUBY_PATCHLEVEL 139
+#define RUBY_RELEASE_DATE "2019-02-11"
+#define RUBY_PATCHLEVEL 140
 
 #define RUBY_RELEASE_YEAR 2019
 #define RUBY_RELEASE_MONTH 2
-#define RUBY_RELEASE_DAY 5
+#define RUBY_RELEASE_DAY 11
 
 #include "ruby/version.h"
 
Index: ruby_2_5/test/ruby/test_syntax.rb
===================================================================
--- ruby_2_5/test/ruby/test_syntax.rb	(revision 67049)
+++ ruby_2_5/test/ruby/test_syntax.rb	(revision 67050)
@@ -678,6 +678,24 @@ e" https://github.com/ruby/ruby/blob/trunk/ruby_2_5/test/ruby/test_syntax.rb#L678
     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)
+    assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /can't find string "TEXT"/)
+    begin;
+      <<-TEXT
+      \
+      TEXT
+    end;
+    assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /can't find string "TEXT"/)
+    begin;
+      <<~TEXT
+      \
+      TEXT
+    end;
+  end
+
   def test_lineno_after_heredoc
     bug7559 = '[ruby-dev:46737]'
     expected, _, actual = __LINE__, <<eom, __LINE__
Index: ruby_2_5
===================================================================
--- ruby_2_5	(revision 67049)
+++ ruby_2_5	(revision 67050)

Property changes on: ruby_2_5
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
   Merged /trunk:r62872-62873

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

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