ParseTree 1.5.0 Released

ParseTree version 1.5.0 has been released!

http://rubyforge.org/projects/parsetree/
zenspider projects | software projects | by ryan davis

** DESCRIPTION:

ParseTree is a C extension (using RubyInline) that extracts the parse
tree for an entire class or a specific method and returns it as a
s-expression (aka sexp) using ruby’s arrays, strings, symbols, and
integers.

As an example:

def conditional1(arg1)
if arg1 == 0 then
return 1
end
return 0
end

becomes:

[:defn,
:conditional1,
[:scope,
[:block,
[:args, :arg1],
[:if,
[:call, [:lvar, :arg1], :==, [:array, [:lit, 0]]],
[:return, [:lit, 1]],
nil],
[:return, [:lit, 0]]]]]

** FEATURES/PROBLEMS:

  • Uses RubyInline, so it just drops in.

  • Includes SexpProcessor and CompositeSexpProcessor.

    • Allows you to write very clean filters.
  • Includes parse_tree_show, which lets you quickly snoop code.

    • echo “1+1” | parse_tree_show -f for quick snippet output.
  • Includes parse_tree_abc, which lets you get abc metrics on code.

    • abc metrics = numbers of assignments, branches, and calls.
    • whitespace independent metric for method complexity.
  • Includes parse_tree_deps, which shows you basic class level
    dependencies.

  • Only works on methods in classes/modules, not arbitrary code.

  • Does not work on the core classes, as they are not ruby (yet).

    http://rubyforge.org/projects/parsetree/
    zenspider projects | software projects | by ryan davis

Changes:

  • 5 minor enhancements:
    Added parse_tree_audit.
    Added reporting of unsupported nodes that have processors.
    YAY! class method support! generated as :“self.blah”
    Add parse_tree_for_string.
    Converted Rakefile+gemspec to Hoe-based Rakefile.

  • 6 bug fixes:
    Did some preliminary work on 1.9 compatibility.
    Fixed tests for some changes/clarifications.
    Fixed resbody: should have nil exceptions list when no exception
    rescued.
    Fixed op_asgn1 and op_asgn2.
    Fixed incompatibility with new inline changes.
    Fixed VALUE decl in parse_tree.rb

    http://rubyforge.org/projects/parsetree/
    zenspider projects | software projects | by ryan davis

On Sun, 24 Sep 2006 22:02:25 +0200, Ryan D.
[email protected]
wrote:

ParseTree version 1.5.0 has been released!

[snip]

** FEATURES/PROBLEMS:

  • Uses RubyInline, so it just drops in.

There seems to be a problem with RubyInline’s strip_comments(). I’m not
sure what the exact problem is, but it converts

case NODE_LAMBDA:
puts(“no worky in 1.9 yet”);
break;
#{if_version :<, “1.9”, “#endif”}

// Nodes we found but have yet to decypher
// I think these are all runtime only… not positive but…
case NODE_MEMO: // enum.c zip
case NODE_CREF:

to

case NODE_LAMBDA:
puts(“no worky in 1.9 yet”);
break;
#endif case NODE_MEMO: case NODE_CREF:

Which obviously won’t compile.

(Tested on ruby 1.8.4 (2005-12-24) [i686-linux] and ruby 1.8.5
(2006-08-25) [i686-linux], RubyInline-3.6.0, everything installed using
gems)

[snip]

Changes:

  • 5 minor enhancements:
    Added parse_tree_audit.
    Added reporting of unsupported nodes that have processors.
    YAY! class method support! generated as :“self.blah”
    Add parse_tree_for_string.

You made a mistake when copying the code from RubyNode:

You always have to set ruby_eval_tree_begin to 0 (in 1.8), otherwise the
code in BEGIN blocks will be executed the next time eval is called
(which
is immediatly in irb):

$ ruby
require “parse_tree”
p ParseTree.new.parse_tree_for_string(“BEGIN { puts ‘evil’ }; puts
‘hello’”)
puts “before eval”
p eval(“‘eval’”)
^D
[[:fcall, :puts, [:array, [:str, “hello”]]]]
before eval
evil
“eval”

Converted Rakefile+gemspec to Hoe-based Rakefile.

  • 6 bug fixes:
    Did some preliminary work on 1.9 compatibility.
    Fixed tests for some changes/clarifications.
    Fixed resbody: should have nil exceptions list when no exception
    rescued.
    Fixed op_asgn1 and op_asgn2.
    Fixed incompatibility with new inline changes.
    Fixed VALUE decl in parse_tree.rb

There have been changes to NODE_ALIAS and NODE_VALIAS in 1.8.5:

$ irb -r parse_tree

ParseTree.new.parse_tree_for_string(“class A; alias a b; end”)
/home/dba/i/ruby-1.8.5/lib/ruby/1.8/irb.rb:298: [BUG] Segmentation fault
ruby 1.8.5 (2006-08-25) [i686-linux]

$ ruby -ve ‘require “parse_tree”; p
ParseTree.new.parse_tree_for_string(“class A; alias $a $b; end”)’
ruby 1.8.4 (2005-12-24) [i686-linux]
[[:class, :A, [:scope, [:valias, :$b, :$a]]]]

$ ruby -ve ‘require “parse_tree”; p
ParseTree.new.parse_tree_for_string(“class A; alias $a $b; end”)’
ruby 1.8.5 (2006-08-25) [i686-linux]
[[:class, :A, [:scope, [:valias, :$a, :$b]]]]

Dominik

On Sep 24, 2006, at 3:36 PM, Dominik B. wrote:

There seems to be a problem with RubyInline’s strip_comments(). I’m
not sure what the exact problem is, but it converts

Please file a bug.