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

ruby-changes:48099

From: nobu <ko1@a...>
Date: Thu, 19 Oct 2017 14:10:44 +0900 (JST)
Subject: [ruby-changes:48099] nobu:r60213 (trunk): parse.y: indent at '#'

nobu	2017-10-19 14:10:38 +0900 (Thu, 19 Oct 2017)

  New Revision: 60213

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

  Log:
    parse.y: indent at '#'
    
    * parse.y (parser_here_document): update indent at '#', which is
      not a space.  [ruby-core:83368] [Bug #14032]

  Modified files:
    trunk/parse.y
    trunk/test/ripper/test_lexer.rb
    trunk/test/ruby/test_syntax.rb
Index: test/ruby/test_syntax.rb
===================================================================
--- test/ruby/test_syntax.rb	(revision 60212)
+++ test/ruby/test_syntax.rb	(revision 60213)
@@ -659,6 +659,14 @@ e" https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L659
     end
   end
 
+  def test_dedented_heredoc_expr_at_beginning
+    result = "  a\n" \
+             '#{1}'"\n"
+    expected = "  a\n" \
+             '#{1}'"\n"
+    assert_dedented_heredoc(expected, result)
+  end
+
   def test_lineno_after_heredoc
     bug7559 = '[ruby-dev:46737]'
     expected, _, actual = __LINE__, <<eom, __LINE__
Index: test/ripper/test_lexer.rb
===================================================================
--- test/ripper/test_lexer.rb	(revision 60212)
+++ test/ripper/test_lexer.rb	(revision 60213)
@@ -70,4 +70,24 @@ class TestRipper::Lexer < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/ripper/test_lexer.rb#L70
     ]
     assert_equal expect, Ripper.lex(src).map {|e| e[1]}
   end
+
+  def test_expr_at_beginning_in_heredoc
+    src = <<~'E'
+    <<~B
+      a
+    #{1}
+    B
+    E
+    expect = %I[
+      on_heredoc_beg
+      on_nl
+      on_tstring_content
+      on_embexpr_beg
+      on_int
+      on_embexpr_end
+      on_tstring_content
+      on_heredoc_end
+    ]
+    assert_equal expect, Ripper.lex(src).map {|e| e[1]}
+  end
 end
Index: parse.y
===================================================================
--- parse.y	(revision 60212)
+++ parse.y	(revision 60213)
@@ -6732,6 +6732,12 @@ parser_here_document(struct parser_param https://github.com/ruby/ruby/blob/trunk/parse.y#L6732
 	newtok();
 	if (c == '#') {
 	    int t = parser_peek_variable_name(parser);
+	    if (heredoc_line_indent != -1) {
+		if (heredoc_indent > heredoc_line_indent) {
+		    heredoc_indent = heredoc_line_indent;
+		}
+		heredoc_line_indent = -1;
+	    }
 	    if (t) return t;
 	    tokadd('#');
 	    c = nextc();

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

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