HaxeVerbalExpressions icon indicating copy to clipboard operation
HaxeVerbalExpressions copied to clipboard

suggestion : use macro when constant expression

Open wighawag opened this issue 10 years ago • 4 comments

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.

wighawag avatar Jan 06 '16 09:01 wighawag

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

markknol avatar Jan 06 '16 10:01 markknol

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)

wighawag avatar Jan 06 '16 11:01 wighawag

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

markknol avatar Jan 07 '16 17:01 markknol

Looks great.

wighawag avatar Jan 08 '16 14:01 wighawag