nitely / nim-regex

Pure Nim regex engine. Guarantees linear time matching
https://nitely.github.io/nim-regex/
MIT License
228 stars 21 forks source link

Pass flags as set of enum, rather than string #3

Closed euantorano closed 8 months ago

euantorano commented 6 years ago

The documentation suggests that currently flags are passed as characters in a string. In my opinion, it's much cleaner and easier to read to pass a set[Flag] where Flag is an enum of possible flags to either the template to create the regex or the procs to execute a regex.

Obviously this wouldn't work for per-group flags, but for full expression flags only.

nitely commented 6 years ago

This can be easily implemented without even touching the parsing. Just convert the flags into their string representation and prepend them to the regex.

The question is, you find this re(r"regex", {flagMultiLine}) easier to read than re"(?m)regex" ?

Note that both are compiled at compile-time, so flags can't be passed at runtime (although, there's a runtime version) in case someone would want that.

euantorano commented 6 years ago

Yeah, I find names much more readable personally. Remembering that ?m makes the regex multi-line becomes difficult when you use multiple languages (or it does for me at least).

nitely commented 6 years ago

Remembering that ?m makes the regex multi-line becomes difficult when you use multiple languages (or it does for me at least).

That should not be a problem with PCRE compatible regex engines. Even in JS the letters mean the same thing. However, I think I'll add this feature. If you have time to implement it yourself I'll gladly merge the PR.