Sha256: 38ae4a39875ca636cd4d4ee581c5d350fc5b26ac1160d762e8df776306d9c1cf

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 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

$u ||= ! $U

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 (now the default)"
  puts "-U      : UNunified sexps"

  exit 1
end

ARGV.push "-" if ARGV.empty?

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

  class Unifier
    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.2-x86-mswin32-60 bin/parse_tree_show
ParseTree-3.0.2-x86-mingw32 bin/parse_tree_show