ammar / regexp_parser

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

Fails to parse lone opening brace #59

Closed mvz closed 5 years ago

mvz commented 5 years ago

Attempting to parse /{/ results in an error:

Regexp::Parser.parse '{'
# Regexp::Scanner::PrematureEndError (Premature end of pattern at {)

However, for MRI this is perfectly fine (although it's equivalent to /\{/).

/{/
#=> /{/
jaynetics commented 5 years ago

Hi @mvz and thanks for reporting.

May I ask, did you encounter this in a "real-life" scenario or were you testing for edge cases?

So far, the policy for this gem has been not to support these "quirky" metachar/literal edge cases, as described in #15, particularly in this comment and the following ones.

If these quirks turn out to be commonly depended upon, we might have to reconsider, though.

MRI behavior is quite inconsistent here looking at other metachar pairs, but at least it hasn't changed since Ruby 1.9.3.

/{/ # => /{/
/}/ # => /}/
/[/ # => SyntaxError (premature end of char-class: /[/)
/]/ # => /]/
/(/ # => SyntaxError (end pattern with unmatched parenthesis: /(/)
/)/ # => SyntaxError (unmatched close parenthesis: /)/)
mvz commented 5 years ago

This was a real-life scenario: I was running mutant against the code of my ripper_ruby_parser gem.

However, after reading through #15, I think maybe the best fix is for mutant to catch this error and handle it.

jaynetics commented 5 years ago

the error is now being caught by mutant, so i'll close this issue.