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

ruby-changes:54942

From: usa <ko1@a...>
Date: Thu, 28 Feb 2019 23:52:12 +0900 (JST)
Subject: [ruby-changes:54942] usa:r67147 (ruby_2_4): merge revision(s) 62872, 62873: [Backport #14621]

usa	2019-02-28 23:52:06 +0900 (Thu, 28 Feb 2019)

  New Revision: 67147

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

  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_4/
  Modified files:
    branches/ruby_2_4/parse.y
    branches/ruby_2_4/test/ruby/test_syntax.rb
    branches/ruby_2_4/version.h
Index: ruby_2_4/version.h
===================================================================
--- ruby_2_4/version.h	(revision 67146)
+++ ruby_2_4/version.h	(revision 67147)
@@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/version.h#L1
 #define RUBY_VERSION "2.4.6"
-#define RUBY_RELEASE_DATE "2019-02-01"
-#define RUBY_PATCHLEVEL 347
+#define RUBY_RELEASE_DATE "2019-02-28"
+#define RUBY_PATCHLEVEL 348
 
 #define RUBY_RELEASE_YEAR 2019
 #define RUBY_RELEASE_MONTH 2
-#define RUBY_RELEASE_DAY 1
+#define RUBY_RELEASE_DAY 28
 
 #include "ruby/version.h"
 
Index: ruby_2_4/test/ruby/test_syntax.rb
===================================================================
--- ruby_2_4/test/ruby/test_syntax.rb	(revision 67146)
+++ ruby_2_4/test/ruby/test_syntax.rb	(revision 67147)
@@ -667,6 +667,24 @@ e" https://github.com/ruby/ruby/blob/trunk/ruby_2_4/test/ruby/test_syntax.rb#L667
     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_4/parse.y
===================================================================
--- ruby_2_4/parse.y	(revision 67146)
+++ ruby_2_4/parse.y	(revision 67147)
@@ -6187,7 +6187,14 @@ parser_tokadd_string(struct parser_param https://github.com/ruby/ruby/blob/trunk/ruby_2_4/parse.y#L6187
 	    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;
 
@@ -6265,6 +6272,7 @@ parser_tokadd_string(struct parser_param https://github.com/ruby/ruby/blob/trunk/ruby_2_4/parse.y#L6272
         }
 	tokadd(c);
     }
+  terminate:
     *encp = enc;
     return c;
 }
@@ -6718,6 +6726,7 @@ parser_here_document(struct parser_param https://github.com/ruby/ruby/blob/trunk/ruby_2_4/parse.y#L6726
     long len;
     VALUE str = 0;
     rb_encoding *enc = current_enc;
+    int bol;
 
     eos = RSTRING_PTR(here->nd_lit);
     len = RSTRING_LEN(here->nd_lit) - 1;
@@ -6754,7 +6763,14 @@ parser_here_document(struct parser_param https://github.com/ruby/ruby/blob/trunk/ruby_2_4/parse.y#L6763
 	heredoc_restore(lex_strterm);
 	return 0;
     }
-    if (was_bol() && whole_match_p(eos, len, indent)) {
+    bol = was_bol();
+    /* `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);
 	return tSTRING_END;
@@ -6825,6 +6841,7 @@ parser_here_document(struct parser_param https://github.com/ruby/ruby/blob/trunk/ruby_2_4/parse.y#L6841
 		goto restore;
 	    }
 	    if (c != '\n') {
+		if (c == '\\') heredoc_line_indent = -1;
 	      flush:
 		set_yylval_str(STR_NEW3(tok(), toklen(), enc, func));
 		flush_string_content(enc);
Index: ruby_2_4
===================================================================
--- ruby_2_4	(revision 67146)
+++ ruby_2_4	(revision 67147)

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

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

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