ruby_parser

A ruby parser written in ruby

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:

1 2 3 4 5 6 
def conditional1(arg1) if arg1 == 0 then return 1 end return 0 end 

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.

Get The Code

If you just want to use ruby_parser, you can install it via RubyGems:
gem install ruby_parser
Fork me on GitHub If you want to hack on ruby_parser, clone it from GitHub:
 $ git clone git://github.com/seattlerb/ruby_parser # or: $ gh repo clone seattlerb/ruby_parser

Latest Activity