1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

ripper/lexer.rb: nested indented heredoc

* ext/ripper/lib/ripper/lexer.rb (on_heredoc_dedent): fix for
  nested indedented here documents, where `Elem`s are nested too.
  [ruby-core:80977] [Bug #13536]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58545 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-05-02 17:48:10 +00:00
parent 3692fd69ca
commit d24c4683f7
2 changed files with 25 additions and 1 deletions

View file

@ -67,7 +67,7 @@ class Ripper
def on_heredoc_dedent(v, w)
@buf.last.each do |e|
if e.event == :on_tstring_content
if Elem === e and e.event == :on_tstring_content
if (n = dedent_string(e.tok, w)) > 0
e.pos[1] += n
end

24
test/ripper/test_lexer.rb Normal file
View file

@ -0,0 +1,24 @@
# frozen_string_literal: true
begin
require_relative 'dummyparser'
require 'test/unit'
ripper_test = true
module TestRipper; end
rescue LoadError
end
class TestRipper::Lexer < Test::Unit::TestCase
def test_nested_dedent_heredoc
bug = '[ruby-core:80977] [Bug #13536]'
str = <<~'E'
<<~"D"
#{
<<~"B"
this must be a valid ruby
B
}
D
E
assert_equal(str, Ripper.tokenize(str).join(""), bug)
end
end