seattlerb / ruby_parser

ruby_parser is a ruby parser written in pure ruby. It outputs s-expressions which can be manipulated and converted back to ruby via the ruby2ruby gem.
http://www.zenspider.com/projects/ruby_parser.html
476 stars 100 forks source link

Set up legacy gem for 1.8/1.9 only #260

Closed presidentbeef closed 5 years ago

presidentbeef commented 6 years ago

Here is a cut at a legacy gem.

I moved the relevant files to lib/ruby_parser/legacy (looks better and avoids require conflicts) and namespaced most things. RubyParserStuff is renamed LegacyRubyParserStuff.

This should work with the regular ruby_parser gem or by itself.

Tested with the https://github.com/zenspider/ruby_parser/tree/drop_legacy branch:

irb
2.5.0 :001 > require 'ruby_parser'
 => true
2.5.0 :002 > RubyParser::VERSIONS
 => [RubyParser::V25, RubyParser::V24, RubyParser::V23, RubyParser::V22, RubyParser::V21, RubyParser::V20]
2.5.0 :003 > require 'ruby_parser/legacy'
 => true
2.5.0 :004 > RubyParser::VERSIONS
 => [RubyParser::V25, RubyParser::V24, RubyParser::V23, RubyParser::V22, RubyParser::V21, RubyParser::V20, RubyParser::V19, RubyParser::V18]

Tests pass.

If there is drift in the main RubyParser class, it could cause problems when the two gems are used together, since the legacy one avoids overwriting it.

Otherwise I think it's fairly clean.

presidentbeef commented 6 years ago

Just realized the parser will get RubyParserStuff::Env instead of LegacyRubyParserStuff::Env if ruby_parser is already loaded :(

zenspider commented 5 years ago

This is next... but not on this minor release.

zenspider commented 5 years ago

DONE! CLOSING!