seattlerb/ruby_parser

Parse Error on Ruby 2.5

marocchino opened this issue ยท 4 comments

Successfully installed ruby_parser-3.11.0
1 gem installed
[justin@bigblue brakeman (master)]$ irb
2.5.0 :001 > require 'ruby_parser'
R => true 
2.5.0 :002 > RubyParser.new.parse <<-RUBY
2.5.0 :003">     def save_models
2.5.0 :004">       models_with_index do |model, index|
2.5.0 :005">         model.save!
2.5.0 :006">       rescue StandardError => err
2.5.0 :007">         error(model, index, err)
2.5.0 :008">       end
2.5.0 :009">     end
2.5.0 :010"> RUBY
Traceback (most recent call last):
       16: from /home/justin/.rvm/rubies/ruby-2.5.0/bin/irb:11:in `<main>'
       15: from (irb):2
       14: from /home/justin/.rvm/gems/ruby-2.5.0@test/gems/ruby_parser-3.11.0/lib/ruby_parser.rb:28:in `process'
       13: from /home/justin/.rvm/gems/ruby-2.5.0@test/gems/ruby_parser-3.11.0/lib/ruby_parser.rb:28:in `each'
       12: from /home/justin/.rvm/gems/ruby-2.5.0@test/gems/ruby_parser-3.11.0/lib/ruby_parser.rb:31:in `block in process'
       11: from /home/justin/.rvm/gems/ruby-2.5.0@test/gems/ruby_parser-3.11.0/lib/ruby_parser_extras.rb:1070:in `process'
       10: from /home/justin/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/timeout.rb:108:in `timeout'
        9: from /home/justin/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/timeout.rb:33:in `catch'
        8: from /home/justin/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/timeout.rb:33:in `catch'
        7: from /home/justin/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/timeout.rb:33:in `block in catch'
        6: from /home/justin/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/timeout.rb:93:in `block in timeout'
        5: from /home/justin/.rvm/gems/ruby-2.5.0@test/gems/ruby_parser-3.11.0/lib/ruby_parser_extras.rb:1082:in `block in process'
        4: from /home/justin/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/racc/parser.rb:259:in `do_parse'
        3: from /home/justin/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/racc/parser.rb:259:in `_racc_do_parse_c'
        2: from /home/justin/.rvm/gems/ruby-2.5.0@test/gems/ruby_parser-3.11.0/lib/ruby_parser_extras.rb:1175:in `on_error'
        1: from /home/justin/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/racc/parser.rb:528:in `on_error'
Racc::ParseError ((string):4 :: parse error on value ["rescue", 4] (kRESCUE))

As mentioned in the linked brakeman issue, it would seem that rubocop is specifically pushing users towards this particular syntax. I'd expect an increasing number of people to be affected as people update their rubocop.yml TargetRubyVersions.

For us, the specific "cop" rule that triggered this was Style/RedundantBegin

This should be fixed by #264.

it seems it's merged to the master but it didn't add to new version yet :S @zenspider

@zenspider any idea when this could be released as a new version? If a new release isn't coming soon could you provide instructions for compiling it ourselves? I'm inevitably stuck on rp_extensions.rb:66:in class:Sexp': undefined method <<' for class Sexp' (NameError)`