ruby-changes:48098
From: nobu <ko1@a...>
Date: Thu, 19 Oct 2017 13:25:35 +0900 (JST)
Subject: [ruby-changes:48098] nobu:r60212 (trunk): lexer.rb: no dedent strings in middle
nobu 2017-10-19 13:25:30 +0900 (Thu, 19 Oct 2017) New Revision: 60212 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60212 Log: lexer.rb: no dedent strings in middle * ext/ripper/lib/ripper/lexer.rb (on_heredoc_dedent): dedent only strings at the beginning, not strings in middle. [ruby-core:83343] [Bug #14027] Modified files: trunk/ext/ripper/lib/ripper/lexer.rb trunk/test/ripper/test_lexer.rb Index: test/ripper/test_lexer.rb =================================================================== --- test/ripper/test_lexer.rb (revision 60211) +++ test/ripper/test_lexer.rb (revision 60212) @@ -51,4 +51,23 @@ class TestRipper::Lexer < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/ripper/test_lexer.rb#L51 ] assert_equal expect, Ripper.lex(src).map {|e| e[1]} end + + def test_space_after_expr_in_heredoc + src = <<~'E' + <<~B + #{1} a + B + E + expect = %I[ + on_heredoc_beg + on_nl + on_ignored_sp + 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: ext/ripper/lib/ripper/lexer.rb =================================================================== --- ext/ripper/lib/ripper/lexer.rb (revision 60211) +++ ext/ripper/lib/ripper/lexer.rb (revision 60212) @@ -98,7 +98,7 @@ class Ripper https://github.com/ruby/ruby/blob/trunk/ext/ripper/lib/ripper/lexer.rb#L98 ignored_sp = [] heredoc = @buf.last heredoc.each_with_index do |e, i| - if Elem === e and e.event == :on_tstring_content + if Elem === e and e.event == :on_tstring_content and e.pos[1].zero? tok = e.tok.dup if w > 0 and /\A\s/ =~ e.tok if (n = dedent_string(e.tok, w)) > 0 if e.tok.empty? -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/