RubyNode is an interesting Ruby library that spits out semantic representations of code much in the same way the inspect method does with data. Here's a demo:
>> def plus_1(x) >> x + 1 >> end => nil >> pp method(:plus_1).body_node.transform [:scope, {:next=> [:block, [[:args, {:rest=>-1, :cnt=>1, :opt=>false}], [:call, {:args=>[:array, [[:lit, {:lit=>1}]]], :mid=>:+, :recv=>[:lvar, {:vid=>:x, :cnt=>2}]}]]], :rval=>[:cref, {:next=>false, :clss=>Object}], :tbl=>[:x]}]

Comments
Matt Mower ·
Any idea how this compares with Ryan Davis & Eric Hodel's work with ParseTree?
Peter Cooper ·
Unfortunately, no, as I haven't looked at that yet. Thanks for the reference though!
Gene ·
more node info
http://rubystuff.org/nodewrap/
http://sean-carley.blogspot.com/2006/04/assignment-in-ruby-simple-scoped.html
http://www.namikilab.tuat.ac.jp/~sasada/prog/rubynodes/nodes.html
zimbatm ·
@Matt : With ParseTree, I was not able to parse a whole source file. I can only pass existing classes, modules or methods to it.
On the other side, RubyNode doesn't seem to have a Sexp processor included like ParseTree.
zenspider ·
@zimbatm: the latest version of ParseTree will be able to parse whole files. We're releasing that in a couple of days.
Not having a sexp processor architecture is a biggie, IMO. We consider SexpProcessor to be the strongest feature in ParseTree. Not having a processing framework is probably not quite as bad as not having comprehensive tests.
@gene: you should point out that Sean's article is on ParseTree, not nodewrap.