Bug in Ripper

Hi,

Minero A. has confirmed that the following is a bug. I’m not (yet!)
sufficinetly familiar with the Ruby internals to have a go at fixing it
though :(.

Any ideas? - perhaps a patch or even a hint of where to look in parse.y
would help.

Essentially Ripper treats the input:
='foo

as an op (the =), followed by a tstring_beg (the ') and a tstring_end
(foo). It should treat foo as a tstring_content. [I understand that this isn’t valid ruby code, but it’s not great given the expected use of Ripper to parse incomplete code (e.g. Autocompletion)].

Sample code can be found at the bottom of this post.

Cheers,
Jon

require ‘ripper/filter’

class JonsFilter < Ripper::Filter
def initialize(str)
super str
Ripper.private_instance_methods.grep(/^on_/).each { |n| m=n.to_s
eval(" def " + m + “(tok, f) puts '<” + m[3…m.length-1] + “>’ +
escape(tok) + '</” + m[3…m.length-1] + ">’ end ")
}
end

ESC = {’&’ => ‘&’, ‘<’ => ‘<’, ‘>’ => ‘>’ }
def escape(str)
tbl = ESC
str.gsub(/[&<>]/) {|ch| tbl[ch] }
end
end

$input="='foo"
JonsFilter.new($input).parse($stdout)