1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
#!/usr/bin/env ruby -ws
$b ||= false # bug mode -- ripper is buggy, use Ripper.sexp
$d ||= false # debug -- turn on yydebug
$p ||= false # Use pp
require "ripper/sexp"
require "pp" if $p
if ARGV.empty? then
warn "reading from stdin"
ARGV << "-"
end
class MySexpBuilder < Ripper::SexpBuilderPP
def on_parse_error msg
Kernel.warn msg
end
end
ARGV.each do |path|
src = path == "-" ? $stdin.read : File.read(path)
sexp = nil
if $b then
sexp = Ripper.sexp src
else
rip = MySexpBuilder.new src
rip.yydebug = $d
sexp = rip.parse
if rip.error? then
warn "skipping"
next
end
end
puts "accept"
if $p then
pp sexp
else
p sexp
end
end
|