seattlerb / ruby_parser

ruby_parser is a ruby parser written in pure ruby. It outputs s-expressions which can be manipulated and converted back to ruby via the ruby2ruby gem.
http://www.zenspider.com/projects/ruby_parser.html
476 stars 100 forks source link

Heredocs with line continuations lower line numbers for later lines #292

Closed mvz closed 3 years ago

mvz commented 5 years ago
[38] pry(main)> str = "<<TXT\nfoo\\\nbar\nTXT\nfoo"; puts str
<<TXT
foo\
bar
TXT
foo
=> nil
[39] pry(main)> RubyParser.for_current_ruby.parse(str)
=> s(:block, s(:str, "foobar\n").line(1), s(:call, nil, :foo).line(4)).line(1)

The call to foo is on line 5, but s(:call, nil, :foo) has line number 4.

zenspider commented 5 years ago

Heredocs and line numbers are just a complete clusterfuck. Unfortunately, they're not going to get fixed until I completely rewrite all string/heredoc parsing entirely. It's just bad. Real bad.

I think I already have a skipped test or two that covers this issue. If not, then can you send me a PR with one for this case?

zenspider commented 3 years ago

Aaaand I completely rewrote it. This is fixed. Release coming soonish.