hanickadot / compile-time-regular-expressions

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

Syntax error on valid regex #263

Closed rolandjitsu closed 2 years ago

rolandjitsu commented 2 years ago

I was trying to match a semver string using:

"^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|"
"\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$"

See https://regex101.com/r/vkijKf/1/.

But it comes back with a syntax error:

/home/roland/.conan/data/ctre/3.7/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/ctre/wrapper.hpp: In instantiation of ‘struct ctre::regex_builder<ctll::fixed_string<137>{char32_t [137]{94, 40, 48, 124, 91, 49, 45, 57, 93, 92, 100, 42, 41, 92, 46, 40, 48, 124, 91, 49, 45, 57, 93, 92, 100, 42, 41, 92, 46, 40, 48, 124, 91, 49, 45, 57, 93, 92, 100, 42, 41, 40, 63, 58, 45, 40, 40, 63, 58, 48, 124, 91, 49, 45, 57, 93, 92, 100, 42, 124, 92, 100, 42, 91, 97, 45, 122, 65, 45, 90, 45, 93, 91, 48, 45, 57, 97, 45, 122, 65, 45, 90, 45, 93, 42, 41, 40, 63, 58, 92, 46, 40, 63, 58, 48, 124, 91, 49, 45, 57, 93, 92, 100, 42, 124, 92, 100, 42, 91, 97, 45, 122, 65, 45, 90, 45, 93, 91, 48, 45, 57, 97, 45, 122, 65, 45, 90, 45, 93, 42, 41, 41, 42, 41, 41, 63, 36}, 137, true}>’:
/home/roland/.conan/data/ctre/3.7/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/ctre/wrapper.hpp:306:100:   required from ‘constexpr const auto ctre::match<ctll::fixed_string<137>{char32_t [137]{94, 40, 48, 124, 91, 49, 45, 57, 93, 92, 100, 42, 41, 92, 46, 40, 48, 124, 91, 49, 45, 57, 93, 92, 100, 42, 41, 92, 46, 40, 48, 124, 91, 49, 45, 57, 93, 92, 100, 42, 41, 40, 63, 58, 45, 40, 40, 63, 58, 48, 124, 91, 49, 45, 57, 93, 92, 100, 42, 124, 92, 100, 42, 91, 97, 45, 122, 65, 45, 90, 45, 93, 91, 48, 45, 57, 97, 45, 122, 65, 45, 90, 45, 93, 42, 41, 40, 63, 58, 92, 46, 40, 63, 58, 48, 124, 91, 49, 45, 57, 93, 92, 100, 42, 124, 92, 100, 42, 91, 97, 45, 122, 65, 45, 90, 45, 93, 91, 48, 45, 57, 97, 45, 122, 65, 45, 90, 45, 93, 42, 41, 41, 42, 41, 41, 63, 36}, 137, true}>’
/home/roland/work/ctre-test/src/swu.cc:37:15:   required from here
/home/roland/.conan/data/ctre/3.7/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/ctre/wrapper.hpp:299:42: error: invalid use of incomplete type ‘struct ctre::problem_at_position<70>’
  299 |         static_assert(result::is_correct && problem_at_position<n>{}, "Regular Expression contains syntax error.");
      |                               ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/roland/.conan/data/ctre/3.7/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/ctre/wrapper.hpp:277:26: note: declaration of ‘struct ctre::problem_at_position<70>’
  277 | template <size_t> struct problem_at_position; // do not define!
      |                          ^~~~~~~~~~~~~~~~~~~
ninja: build stopped: subcommand failed.

I narrowed it down to:

"^\\d*[a-zA-Z-][0-9a-zA-Z-]*$"

Not quite sure what it doesn't like about it (position 11).

Alcaro commented 2 years ago

Easy to narrow down to [a-z-]. Apparently CTRE doesn't like character ranges that try to match literal dashes.

Not sure what you're supposed to do instead, though.

hanickadot commented 2 years ago

it's because how the parsing is done, just escape it: [a-z\-]

rolandjitsu commented 2 years ago

it's because how the parsing is done, just escape it: [a-z\-]

Got it. Thanks.