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

ruby-changes:55853

From: Nobuyoshi <ko1@a...>
Date: Mon, 27 May 2019 00:45:47 +0900 (JST)
Subject: [ruby-changes:55853] Nobuyoshi Nakada: a43c637660 (trunk): parse.y: broke the terminator condition down

https://git.ruby-lang.org/ruby.git/commit/?id=a43c637660

From a43c637660cd3c893401e899014d721d2fa2a5b4 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Mon, 27 May 2019 00:07:05 +0900
Subject: parse.y: broke the terminator condition down

* parse.y (here_document): broke the terminator condition down
  into each piece, the positional condition, resetting the
  dedented here-document indentation, and matching identifier.
  suppress a false warning by icc.

diff --git a/parse.y b/parse.y
index 9036f58..f22b862 100644
--- a/parse.y
+++ b/parse.y
@@ -7201,13 +7201,17 @@ here_document(struct parser_params *p, rb_strterm_heredoc_t *here) https://github.com/ruby/ruby/blob/trunk/parse.y#L7201
 	return 0;
     }
     bol = was_bol(p);
-    /* `heredoc_line_indent == -1` means
-     * - "after an interpolation in the same line", or
-     * - "in a continuing line"
-     */
-    if (bol &&
-	(p->heredoc_line_indent != -1 || (p->heredoc_line_indent = 0)) &&
-	whole_match_p(p, eos, len, indent)) {
+    if (!bol) {
+	/* not beginning of line, cannot be the terminater */
+    }
+    else if (p->heredoc_line_indent == -1) {
+	/* `heredoc_line_indent == -1` means
+	 * - "after an interpolation in the same line", or
+	 * - "in a continuing line"
+	 */
+	p->heredoc_line_indent = 0;
+    }
+    else if (whole_match_p(p, eos, len, indent)) {
 	dispatch_heredoc_end(p);
 	heredoc_restore(p, &p->lex.strterm->u.heredoc);
 	p->lex.strterm = 0;
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb
index e640262..4e52bc4 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -753,6 +753,8 @@ e" https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L753
       \
       TEXT
     end;
+
+    assert_equal("  TEXT\n", eval("<<~eos\n" "  \\\n" "TEXT\n" "eos\n"))
   end
 
   def test_lineno_after_heredoc
-- 
cgit v0.10.2


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

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