New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't ENCLOSE_OPTION be allowed in look-behind? #17

Merged
merged 1 commit into from May 29, 2013

Conversation

Projects
None yet
2 participants
@knu
Contributor

knu commented May 27, 2013

Currently Onigmo (or Oniguruma) does not allow option enclosures (like (?i)) in look-behind, but isn't it possible to allow them?

Taking Ruby as example, this restriction prevents a pattern from being interpolated within a look-behind construct of another.

pattern1 = /foo/  # stringified as "(?-mix:foo)"
pattern2 = /(?<=#{pattern1})/
#=> RegexpError: invalid pattern in look-behind: /(?<=(?-mix:foo))/

This pull request is an unconfirmed attempt to fix the problem.
Thanks for your consideration.

@knu

This comment has been minimized.

Show comment
Hide comment
@knu

knu May 28, 2013

Contributor

On second thought, (?i) may lead a subpattern to variable-length in Unicode case fold semantics. Is that right?
Is there any other option that affects a pattern length? We need to case out those if that is the case.

Contributor

knu commented May 28, 2013

On second thought, (?i) may lead a subpattern to variable-length in Unicode case fold semantics. Is that right?
Is there any other option that affects a pattern length? We need to case out those if that is the case.

@knu

This comment has been minimized.

Show comment
Hide comment
@knu

knu May 28, 2013

Contributor

It doesn't seem like it. In Onigmo/Oniguruma, look-behind does not take Unicode case-folding into account in the first place.

Below is taken from an irb session on ruby 2.0.

>> /(?:\u{149})a/ui =~ "[\u{2bc}na]"  # Unicode case-folding match is in effect.
=> 1
>> /(?<=\u{149})a/ui =~ "[\u{2bc}na]"  # But look-behind does not take account of it.
=> nil

This looks like a bug.

Contributor

knu commented May 28, 2013

It doesn't seem like it. In Onigmo/Oniguruma, look-behind does not take Unicode case-folding into account in the first place.

Below is taken from an irb session on ruby 2.0.

>> /(?:\u{149})a/ui =~ "[\u{2bc}na]"  # Unicode case-folding match is in effect.
=> 1
>> /(?<=\u{149})a/ui =~ "[\u{2bc}na]"  # But look-behind does not take account of it.
=> nil

This looks like a bug.

k-takata added a commit that referenced this pull request May 29, 2013

[dist] update testpy.py
Add tests for the Issue #17.

k-takata added a commit that referenced this pull request May 29, 2013

Merge pull request #17 from knu/allow_options_in_lb
Can't ENCLOSE_OPTION be allowed in look-behind?

@k-takata k-takata merged commit 36102fb into k-takata:master May 29, 2013

@k-takata

This comment has been minimized.

Show comment
Hide comment
@k-takata

k-takata May 29, 2013

Owner

Thank you for the pull request. I also added tests for this.

Owner

k-takata commented May 29, 2013

Thank you for the pull request. I also added tests for this.

HonoreDB pushed a commit to HonoreDB/ruby that referenced this pull request Nov 12, 2013

* test/ruby/test_regexp.rb
  (TestRegexp#test_options_in_look_behind)
  (TestRegexp#assert_match_at): Add tests for another problem
  fixed in Onigmo 5.13.5.  Previously Onigmo did not allow option
  enclosures in look-behind, which makes it impossible to
  interpolate a regexp into another in the middle of a look-behind
  pattern.  cf. k-takata/Onigmo#17

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41792 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

tenderlove pushed a commit to tenderlove/ruby that referenced this pull request Jan 24, 2014

* test/ruby/test_regexp.rb
  (TestRegexp#test_options_in_look_behind)
  (TestRegexp#assert_match_at): Add tests for another problem
  fixed in Onigmo 5.13.5.  Previously Onigmo did not allow option
  enclosures in look-behind, which makes it impossible to
  interpolate a regexp into another in the middle of a look-behind
  pattern.  cf. k-takata/Onigmo#17

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41792 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment