ruby_parser version 3.20.3 has been released!
Published 2023-07-11 @ 20:05
ruby_parser (RP) is a ruby parser written in pure ruby (utilizing racc–which does by default use a C extension). It outputs s-expressions which can be manipulated and converted back to ruby via the ruby2ruby gem.
As an example:
def conditional1 arg1
return 1 if arg1 == 0
return 0
end
becomes:
s(:defn, :conditional1, s(:args, :arg1),
s(:if,
s(:call, s(:lvar, :arg1), :==, s(:lit, 0)),
s(:return, s(:lit, 1)),
nil),
s(:return, s(:lit, 0)))
Tested against 801,039 files from the latest of all rubygems (as of 2013-05):
- 1.8 parser is at 99.9739% accuracy, 3.651 sigma
- 1.9 parser is at 99.9940% accuracy, 4.013 sigma
- 2.0 parser is at 99.9939% accuracy, 4.008 sigma
- 2.6 parser is at 99.9972% accuracy, 4.191 sigma
- 3.0 parser has a 100% parse rate.
- Tested against 2,672,412 unique ruby files across 167k gems.
- As do all the others now, basically.
Changes:
3.20.3 / 2023-07-11
-
2 minor enhancements:
- Added Parser#in_argdef and integrated into 3.x parsers.
- Improved tools/munge.rb to handler MRI 3.2 output
-
2 bug fixes:
- Fixed process_dots to properly deal with paren-less forward_args. (eric1234)
- Fixed tools/ripper.rb to properly print ripper sexp at the end
- home: https://github.com/seattlerb/ruby_parser
- bugs: https://github.com/seattlerb/ruby_parser/issues
- rdoc: http://docs.seattlerb.org/ruby_parser