require 'ripper/filter'
class ColorizeFilter < Ripper::Filter
def on_default(event, tok, f)
f << escape(tok)
end
def on_comment(tok, f)
f << %Q[]
end
def on_tstring_content(tok, f)
f << %Q[#{escape(tok)}]
end
ESC = {
'&' => '&',
'<' => '<',
'>' => '>'
}
def escape(str)
tbl = ESC
str.gsub(/[&<>]/) {|ch| tbl[ch] }
end
end
if $0 == __FILE__
ColorizeFilter.new(ARGF).parse($stdout)
end