bin/parse_tree_show in ParseTree-2.0.2 vs bin/parse_tree_show in ParseTree-2.1.0
- old
+ new
@@ -3,15 +3,31 @@
require 'pp'
begin require 'rubygems' rescue LoadError end
require 'parse_tree'
require 'sexp'
-$u ||= false
+$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'
@@ -19,16 +35,17 @@
class Unifier < SexpProcessor
include UnifiedRuby
end
end
-parse_tree = ParseTree.new
+parse_tree = ParseTree.new($a)
unifier = Unifier.new if $u
ARGV.each do |file|
ruby = file == "-" ? $stdin.read : File.read(file)
- sexp = Sexp.from_array parse_tree.parse_tree_for_string(ruby, file).first
+ 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|