RubyNode – Like ‘.inspect’ but for code instead of data
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]}]
June 19, 2006 at 3:01 pm
Any idea how this compares with Ryan Davis & Eric Hodel's work with ParseTree?
June 20, 2006 at 11:54 am
Unfortunately, no, as I haven't looked at that yet. Thanks for the reference though!
June 30, 2006 at 1:08 pm
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
July 6, 2006 at 3:03 pm
@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.
August 1, 2006 at 8:02 pm
@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.