Sha256: 3bb833f2a69bf972417199499ef889e27fc179faf2cdb609daeb290bb0e6b0d1

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

#!/usr/local/bin/ruby -ws

require 'pp'
begin require 'rubygems' rescue LoadError end
require 'parse_tree'
require 'sexp'

$a ||= false
$h ||= false
$n ||= false
$r ||= false
$s ||= false
$u ||= false
$n = $n.intern if $n

if $h then
  puts "usage: #{File.basename $0} [options] [file...]"
  puts "options:"
  puts "-h      : display usage"
  puts "-a      : all nodes, including newline"
  puts "-n=node : only display matching nodes"
  puts "-r      : raw arrays, no sexps"
  puts "-s      : structural sexps, strip all content and show bare tree"
  puts "-u      : unified sexps"

  exit 1
end

ARGV.push "-" if ARGV.empty?

if $u then
  require 'sexp_processor'
  require 'unified_ruby'

  class Unifier < SexpProcessor
    include UnifiedRuby
  end
end

parse_tree = ParseTree.new($a)
unifier = Unifier.new if $u

ARGV.each do |file|
  ruby = file == "-" ? $stdin.read : File.read(file)

  sexp = parse_tree.parse_tree_for_string(ruby, file).first
  sexp = Sexp.from_array sexp unless $r
  sexp = unifier.process(sexp) if $u
  sexp = sexp.structure if $s

  if $n then
    sexp.each_of_type $n do |node|
      p node
    end
  elsif defined? $q then
    p sexp
  else
    pp sexp
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ParseTree-3.0.1-x86-mingw32 bin/parse_tree_show
ParseTree-3.0.1-x86-mswin32-60 bin/parse_tree_show