hanickadot / compile-time-regular-expressions

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

CTRE incorrectly cannot find any or two letter quantifier with repeat #176

Open danlark1 opened 3 years ago

danlark1 commented 3 years ago

Does not compile:

static_assert("\\A((.|QM){1}\\Z)"_ctre.search("QM"));
static_assert("\\A((.|(QM)){1}\\Z)"_ctre.search("QM"));

Compiles:

static_assert("\\A((.|QM)\\Z)"_ctre.search("QM"));
static_assert("\\A((.|Q){1}\\Z)"_ctre.search("Q"));
static_assert("\\A((QM){1}\\Z)"_ctre.search("QM"));
static_assert("((.|QM){1}\\Z)"_ctre.search("QM"));
static_assert("(\\A(.|QM){1})"_ctre.search("QM"));

https://gcc.godbolt.org/z/rfsP6d

Andersama commented 3 years ago

This pattern's a general issue w/ the library atm, I'd guess that when dynamic allocation is allowed at compile time that this would get worked on, without being about to allocate currently there's no real good way to backtrack to solve that pattern. In short if you really need a pattern like this, expect it to not quite work the way it should.

hanickadot commented 3 years ago

No, you don't need to allocation for this, it's a bit tricky thing to solve for repeats. I have almost done the solution, but it's not ready yet and I don't have any time to work on it right now.

Andersama commented 3 years ago

You mentioned this before somewhere, I'm curious how you'd do this without allocating. I guess preallocating is an option to a certain limit. Not sure is generally solvable without memory. I don't think dfa's necessarily handle all cases here, that's about the only approach that doesn't involve allocation, is that what you're working on?