Skip to content
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

Fix automatic delimiters detection #55

Closed
danon opened this issue Nov 1, 2019 · 3 comments
Closed

Fix automatic delimiters detection #55

danon opened this issue Nov 1, 2019 · 3 comments
Labels

Comments

@danon
Copy link
Member

danon commented Nov 1, 2019

Currently, pattern()/Pattern::of()/new Pattern(), each "guess" whether a pattern is delimited (with flags) or not.

This is ambiguous, for example:

  • is /abc/m delimited? Of course
  • is _abc_m delimited? pattern() would say yes
  • is ,(word),x delimited? pattern() would see ,(word), and x flag.
  • is ,(word),xF delimited? suddenly, xF are not valid flags so pattern() would see ,(word),xF with no flags.
  • is //s an empty pattern with s flag? Or //s pattern? pattern() would choose the first

So:

  • we must remove automatic delimiter detection, because it causes too much ambiguity
  • pattern()/Pattern::of() will now treat each pattern as undelimited by default. Validation will be performed, whether we have enough delimiters to delimit it properly. If we don't, the other method will have to be used.
  • New method will have to be added Pattern::pcre(), which will only accept a delimited pattern, that is:
    • Having a delimiters at the start and end of a string (+ additional flags).
    • No validation of pattern used with the new method should be done, in hope that PCRE by itself will validate it.

New method name, perhaps:

  • Pattern::standard() - standard pattern for PCRE, not so much for T-Regx
  • Pattern::basic()
  • Pattern::pcre() - unintuitive
  • Pattern::undelimited() - too long
  • Pattern::raw() - too crude
@danon danon added the bug label Nov 1, 2019
@danon

This comment has been minimized.

@danon
Copy link
Member Author

danon commented Nov 4, 2019

But now problem arises:

  • You can't now pass an arbitrary string and validate it pattern('/hello?/')->is()->valid() :/
  • Possible solutions:
    • two methods? Like Pattern::of()/Pattern:pcre(), but for pattern()?
    • Improve pattern guessing:
      • Only allow for guessing of certain, unambiguous delimiters (/, #)
      • Parse flags
      • Restore is() method

@danon
Copy link
Member Author

danon commented Feb 18, 2020

Basically, to throw an arbitrary string, go

Pattern::pcre('/hello?/m')->valid();

To validate T-Regx style patterns, go:

pattern('hello?', 'm')->valid();
Pattern::of('hello?', 'm')->valid();

@danon danon closed this as completed Feb 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant