ripper/lexer.rb: nested indented heredoc
* ext/ripper/lib/ripper/lexer.rb (on_heredoc_dedent): insert stripped leading spaces as `on_ignored_sp` elements, so that the original source can be reconsructed. [ruby-core:80977] [Bug #13536] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58584 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8727dce2bf
commit
4671737b0f
@ -66,13 +66,20 @@ class Ripper
|
|||||||
private
|
private
|
||||||
|
|
||||||
def on_heredoc_dedent(v, w)
|
def on_heredoc_dedent(v, w)
|
||||||
@buf.last.each do |e|
|
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
|
||||||
|
tok = e.tok.dup if w > 0 and /\A\s/ =~ e.tok
|
||||||
if (n = dedent_string(e.tok, w)) > 0
|
if (n = dedent_string(e.tok, w)) > 0
|
||||||
|
ignored_sp << [i, Elem.new(e.pos.dup, :on_ignored_sp, tok[0, n])]
|
||||||
e.pos[1] += n
|
e.pos[1] += n
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
ignored_sp.reverse_each do |i, e|
|
||||||
|
heredoc[i, 0] = [e]
|
||||||
|
end
|
||||||
v
|
v
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -20,5 +20,16 @@ class TestRipper::Lexer < Test::Unit::TestCase
|
|||||||
D
|
D
|
||||||
E
|
E
|
||||||
assert_equal(str, Ripper.tokenize(str).join(""), bug)
|
assert_equal(str, Ripper.tokenize(str).join(""), bug)
|
||||||
|
|
||||||
|
str = <<~'E'
|
||||||
|
<<~"D"
|
||||||
|
#{
|
||||||
|
<<~"B"
|
||||||
|
this must be a valid ruby
|
||||||
|
B
|
||||||
|
}
|
||||||
|
D
|
||||||
|
E
|
||||||
|
assert_equal(str, Ripper.tokenize(str).join(""), bug)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -105,6 +105,7 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase
|
|||||||
Ripper.lex("1r\n2i\n3ri\n4.2r\n5.6ri")
|
Ripper.lex("1r\n2i\n3ri\n4.2r\n5.6ri")
|
||||||
assert_equal [[[1, 0], :on_heredoc_beg, "<<~EOS"],
|
assert_equal [[[1, 0], :on_heredoc_beg, "<<~EOS"],
|
||||||
[[1, 6], :on_nl, "\n"],
|
[[1, 6], :on_nl, "\n"],
|
||||||
|
[[2, 0], :on_ignored_sp, " "],
|
||||||
[[2, 2], :on_tstring_content, "heredoc\n"],
|
[[2, 2], :on_tstring_content, "heredoc\n"],
|
||||||
[[3, 0], :on_heredoc_end, "EOS"]
|
[[3, 0], :on_heredoc_end, "EOS"]
|
||||||
],
|
],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user