Bug in Ripper

J

jonT

Hi,

Minero Aoki 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 = {'&' => '&amp;', '<' => '&lt;', '>' => '&gt;' }
def escape(str)
tbl = ESC
str.gsub(/[&<>]/) {|ch| tbl[ch] }
end
end

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top