# Bug in Ripper

**URL:** <https://www.ruby-forum.com/t/bug-in-ripper/74738>\
**Category:** Ruby\
**Created:** [February 28, 2006, 2:57pm UTC](https://www.ruby-forum.com/t/bug-in-ripper/74738 "2006-02-28T14:57:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonT](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@jonT](https://www.ruby-forum.com/u/jonT)\
**Post date:** [February 28, 2006, 2:57pm UTC](https://www.ruby-forum.com/t/bug-in-ripper/74738/1 "2006-02-28T14:57:41Z")

</div>

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)
