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

suggestion : use macro when constant expression #2

Open
wighawag opened this issue Jan 6, 2016 · 4 comments
Open

suggestion : use macro when constant expression #2

wighawag opened this issue Jan 6, 2016 · 4 comments

Comments

@wighawag
Copy link

wighawag commented Jan 6, 2016

Hi, this looks like a cool idea,
Since in many situation regular expression use constant strings a macro could generate the regular expression at compile time.
I guess it is already possible to do on top of your library but just thinking it could be a good adition to it too.

@markknol
Copy link
Collaborator

markknol commented Jan 6, 2016

Yes I have been thinking of this too, it would be awesome. But I'm not sure how to do this exactly yet. Ideas?

@wighawag
Copy link
Author

wighawag commented Jan 6, 2016

Did not have much a thought, and it might not be trivial. My first thought would be to chain a serie of macro static function with the same name (startOfline, then...) which will return a regexp expression

var regExpr = VerbalMacro.regexp().startOfLine()
   .then()
  .maybe("s")
  .then("://")
  .maybe("www.")
  .anythingBut(" ")
  .endOfLine();

then with the use static extension the generated regexp could be augmented with the function you use

regExpr.isMatch(url)

@markknol
Copy link
Collaborator

markknol commented Jan 7, 2016

@Simn suggested this: https://gist.github.com/Simn/01748a98af07128ee166
Ill look into this soon.

@wighawag
Copy link
Author

wighawag commented Jan 8, 2016

Looks great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants