summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-06 15:14:58 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-06 15:14:58 +0000
commit4671737b0f161263f5bd74eb4c76ab5b2cee7099 (patch)
tree55093faef49ac6550600489105156138042b73a5 /ext
parent8727dce2bf2e88b84ffaeda68e5520feb5c7eae3 (diff)
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
Diffstat (limited to 'ext')
-rw-r--r--ext/ripper/lib/ripper/lexer.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/ext/ripper/lib/ripper/lexer.rb b/ext/ripper/lib/ripper/lexer.rb
index 350b513..63dcf85 100644
--- a/ext/ripper/lib/ripper/lexer.rb
+++ b/ext/ripper/lib/ripper/lexer.rb
@@ -66,13 +66,20 @@ class Ripper
private
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
+ tok = e.tok.dup if w > 0 and /\A\s/ =~ e.tok
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
end
end
end
+ ignored_sp.reverse_each do |i, e|
+ heredoc[i, 0] = [e]
+ end
v
end