ruby_parser (RP) is a parser for ruby written in pure ruby (utilizing racc–which does by default use a C extension). RP’s output is s-expressions using ruby’s arrays and base types.
As an example:
becomes:
1 2 3 4 5 6 7 8 9 |
s(:defn, :conditional1, s(:args, :arg1), s(:scope, s(:block, s(:if, s(:call, s(:lvar, :arg1), :==, s(:arglist, s(:lit, 0))), s(:return, s(:lit, 1)), nil), s(:return, s(:lit, 0))))) |
You can then use projects like sexp_processor and ruby2ruby to do freakin’ awesome things with the sexp.
gem install ruby_parser
git clone git://github.com/seattlerb/ruby_parser