Forum: Ruby Bug in Ripper

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
jonT (Guest)
on 2006-02-28 15:57
(Received via mailing list)

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:

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.


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 ")

  ESC = {'&' => '&amp;', '<' => '&lt;', '>' => '&gt;' }
  def escape(str)
    tbl = ESC
    str.gsub(/[&<>]/) {|ch| tbl[ch] }

This topic is locked and can not be replied to.