ammar / regexp_parser

A regular expression parser library for Ruby
MIT License
143 stars 22 forks source link

Support ruby 2.4 #30

Closed jaynetics closed 7 years ago

ammar commented 7 years ago

@janosch-x Thanks for this and sorry about the late response.

Can you please point me to information about disallowing back references in ruby 2.4?

The only related information I found in NEWS was about introducing a new Regexp method (#match?) that does not save back references to reduce object allocation. This does not seem to be a global change.

jaynetics commented 7 years ago

@ammar I couldn’t find any information about this myself, but there must have been some kind of change:

irb(main):001:0> RUBY_VERSION
=> "2.3.0"
irb(main):002:0> /(?(1)b|c)/
=> /(?(1)b|c)/

irb(main):001:0> RUBY_VERSION
=> "2.4.0"
irb(main):002:0> /(?(1)b|c)/
SyntaxError: (irb):2: invalid backref number/name: /(?(1)b|c)/
ammar commented 7 years ago

I see. Thanks.

It looks like the new version of Onigmo checks the validity of the backrefs. The following works fine because the referenced backref (1) actually exists:

>> RUBY_VERSION
=> "2.4.0"
>> /(a)(?(1)b|c)/
=> /(a)(?(1)b|c)/

I think it's the tests that are no longer acceptable by the Onigmo version in ruby 2.4.

jaynetics commented 7 years ago

Exactly. Maybe my commit message was a bit misleading there. I didn’t mean to say that backreferences are no longer allowed in Ruby 2.4 - just that invalid (or "void") backreferences are now disallowed.

ammar commented 7 years ago

Got it. I see now that your note was accurate, I misread it.

It looks good. Thanks again!

jaynetics commented 7 years ago

Thanks for merging!

ammar commented 7 years ago

Pushed regexp_parser 0.4.2 to rubygems.org