diff --git a/include/ctre/pcre.gram b/include/ctre/pcre.gram index f86efdf4..9ea6819b 100644 --- a/include/ctre/pcre.gram +++ b/include/ctre/pcre.gram @@ -87,7 +87,7 @@ mode_switch->s,[mode_singleline], mode_switch->m,[mode_multiline], mode_switch2->close | -character_class->sopen,,[set_make],sclose|sopen,caret,,[set_make_negative],sclose +character_class->sopen,,[set_make],sclose|sopen,minus,,[set_make],sclose|sopen,caret,,[set_make_negative],sclose set->,[set_start], set2a->,[set_start],|epsilon,[set_empty] set2b->,[set_combine],|epsilon diff --git a/include/ctre/pcre.hpp b/include/ctre/pcre.hpp index 70ee7314..d00fdf49 100644 --- a/include/ctre/pcre.hpp +++ b/include/ctre/pcre.hpp @@ -234,7 +234,8 @@ struct pcre { static constexpr auto rule(c, ctll::set<'!','$','\x28','\x29','*','+',',','.','/','0','1','2','3','4','5','6','7','8','9',':','<','=','>','?','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','\"','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','\x7B','|','\x7D'>) -> ctll::push>; static constexpr auto rule(c, _others) -> ctll::push>; static constexpr auto rule(c, ctll::term<'^'>) -> ctll::push>; - static constexpr auto rule(c, ctll::set<'-',']'>) -> ctll::reject; + static constexpr auto rule(c, ctll::term<'-'>) -> ctll::push>; + static constexpr auto rule(c, ctll::term<']'>) -> ctll::reject; static constexpr auto rule(class_named_name, ctll::term<'x'>) -> ctll::push, ctll::term<'i'>, ctll::term<'g'>, ctll::term<'i'>, ctll::term<'t'>, class_named_xdigit>; static constexpr auto rule(class_named_name, ctll::term<'d'>) -> ctll::push, ctll::term<'g'>, ctll::term<'i'>, ctll::term<'t'>, class_named_digit>; diff --git a/single-header/ctre.hpp b/single-header/ctre.hpp index 41796262..e54ceb5a 100644 --- a/single-header/ctre.hpp +++ b/single-header/ctre.hpp @@ -1176,7 +1176,8 @@ struct pcre { static constexpr auto rule(c, ctll::set<'!','$','\x28','\x29','*','+',',','.','/','0','1','2','3','4','5','6','7','8','9',':','<','=','>','?','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','\"','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','\x7B','|','\x7D'>) -> ctll::push>; static constexpr auto rule(c, _others) -> ctll::push>; static constexpr auto rule(c, ctll::term<'^'>) -> ctll::push>; - static constexpr auto rule(c, ctll::set<'-',']'>) -> ctll::reject; + static constexpr auto rule(c, ctll::term<'-'>) -> ctll::push>; + static constexpr auto rule(c, ctll::term<']'>) -> ctll::reject; static constexpr auto rule(class_named_name, ctll::term<'x'>) -> ctll::push, ctll::term<'i'>, ctll::term<'g'>, ctll::term<'i'>, ctll::term<'t'>, class_named_xdigit>; static constexpr auto rule(class_named_name, ctll::term<'d'>) -> ctll::push, ctll::term<'g'>, ctll::term<'i'>, ctll::term<'t'>, class_named_digit>; diff --git a/tests/matching3.cpp b/tests/matching3.cpp index e123634b..c8ccc916 100644 --- a/tests/matching3.cpp +++ b/tests/matching3.cpp @@ -246,3 +246,7 @@ TEST_NOT_MATCH(233, "[^]", ""); TEST_MATCH(234, "[^]+", "x"); TEST_MATCH(235, "[^]?", ""); +// issue #346 +TEST_MATCH(236, "[-A-Z]?", "Hello-World"); +TEST_NOT_MATCH(237, "[A-Z]?", "Hello-World"); +TEST_MATCH(238, "[\\-A-Z]?", "Hello-World");