bin/parse_tree_abc in ParseTree-1.3.0 vs bin/parse_tree_abc in ParseTree-1.3.2

- old
+ new

@@ -11,10 +11,12 @@ require_gem 'ParseTree' rescue LoadError require 'parse_tree' end + require 'sexp_processor' + old_classes = [] ObjectSpace.each_object(Module) do |klass| old_classes << klass end @@ -29,35 +31,22 @@ score = {} new_classes -= old_classes -def sexp_types(exp) - result = [] - if Array === exp.first then - result = sexp_types(exp.first) - else - result << exp.shift - exp.grep(Array).each do |subexp| - result.concat(sexp_types(subexp)) - end - end - result -end - -klasses = ParseTree.new.parse_tree(*new_classes) +klasses = Sexp.from_array(ParseTree.new.parse_tree(*new_classes)) klasses.each do |klass| klass.shift # :class klassname = klass.shift klass.shift # superclass methods = klass methods.each do |defn| a=b=c=0 defn.shift methodname = defn.shift - tokens = sexp_types(defn) + tokens = defn.structure.flatten tokens.each do |token| case token when :attrasgn, :attrset, :dasgn_curr, :iasgn, :lasgn, :masgn then a += 1 when :and, :case, :else, :if, :iter, :or, :rescue, :until, :when, :while then @@ -77,10 +66,16 @@ end puts "Method = assignments + branches + calls = total" puts count = 1 +ta = tb = tc = tval = 0 score.sort_by { |k,v| v }.reverse.each do |key,val| name, a, b, c = *key + ta += a + tb += b + tc += c + tval += val printf "%3d) %-50s = %2d + %2d + %2d = %3d\n", count, name, a, b, c, val count += 1 end +printf "%3d) %-50s = %2d + %2d + %2d = %3d\n", count, "Total", ta, tb, tc, tval