hanickadot / compile-time-regular-expressions

Compile Time Regular Expression in C++
https://twitter.com/hankadusikova
Apache License 2.0
3.22k stars 177 forks source link

Missing support for atomic groups #289

Closed burnpanck closed 11 months ago

burnpanck commented 11 months ago

When trying to compile a pattern that includes a non-capturing group (>?...) that is optional, the compilation fails with error: no matching function for call to 'first' (on clang, similar on gcc).

See https://godbolt.org/z/494Mdcea3

hanickadot commented 11 months ago

there are two problems: a) non-capturing groups are (?: ) and not the > and if you want the group to be optional then (?: )? b) first-follow optimizer for some reason is angry about >

hanickadot commented 11 months ago

ok, you are not using non-capturing group, but atomic group which is not yet implemented, I made the error message a bit better, not sure if I know how to implement it for now

burnpanck commented 11 months ago

Aha! I know (?:...) from python, but have very little experience with PCRE regexes. On regex101 (?>...) was indeed described as "Atomic group (non-capturing)", and I didn't look any further. Interestingly, it appears that (?>...) does (did?) compile with ctre, at least on it's own without quantifier.

hanickadot commented 11 months ago

It compiled but it always returned false.

iulian-rusu commented 11 months ago

ok, you are not using non-capturing group, but atomic group which is not yet implemented, I made the error message a bit better, not sure if I know how to implement it for now

I know this library supports possessive quantifiers, isn't (?:x){1}+ equivalent to (?>x)?

hanickadot commented 11 months ago

@iulian-rusu right, I implemented it now as such transformation, thanks you :)