Skip to content

Commit af40cb7

Browse files
author
Hana Dusíková
committed
#60 disabling special case for [-], if you wan't to use minus in character class use escaping
1 parent d943142 commit af40cb7

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

include/ctre/pcre.gram

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ block_name2->alphanum_characters,[push_name],<block_name2>|epsilon
7272

7373

7474
character_class->sopen,<set>,[set_make],sclose|sopen,caret,<set2a>,[set_make_negative],sclose
75-
set->minus,[push_character],[set_start],<set2b>
7675
set-><setitem>,[set_start],<set2b>
7776
set2a-><setitem2>,[set_start],<set2b>|epsilon
7877
set2b-><setitem2>,[set_combine],<set2b>|epsilon

include/ctre/pcre.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,8 @@ struct pcre {
202202
static constexpr auto rule(c, ctll::term<'\\'>) -> ctll::push<ctll::anything, e, set_start, set2b, set_make, ctll::term<']'>>;
203203
static constexpr auto rule(c, ctll::set<'!','$','\x28','\x29','*','+',',','.',':','<','=','>','?','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','0','s','t','u','v','w','x','y','z','\x7B','\x7D','1','2','3','4','5','6','7','8','9'>) -> ctll::push<ctll::anything, push_character, range, set_start, set2b, set_make, ctll::term<']'>>;
204204
static constexpr auto rule(c, _others) -> ctll::push<ctll::anything, push_character, range, set_start, set2b, set_make, ctll::term<']'>>;
205-
static constexpr auto rule(c, ctll::term<'-'>) -> ctll::push<ctll::anything, push_character, set_start, set2b, set_make, ctll::term<']'>>;
206205
static constexpr auto rule(c, ctll::term<'^'>) -> ctll::push<ctll::anything, set2a, set_make_negative, ctll::term<']'>>;
207-
static constexpr auto rule(c, ctll::set<']','|'>) -> ctll::reject;
206+
static constexpr auto rule(c, ctll::set<'-',']','|'>) -> ctll::reject;
208207

209208
static constexpr auto rule(class_named_name, ctll::term<'x'>) -> ctll::push<ctll::anything, ctll::term<'d'>, ctll::term<'i'>, ctll::term<'g'>, ctll::term<'i'>, ctll::term<'t'>, class_named_xdigit>;
210209
static constexpr auto rule(class_named_name, ctll::term<'d'>) -> ctll::push<ctll::anything, ctll::term<'i'>, ctll::term<'g'>, ctll::term<'i'>, ctll::term<'t'>, class_named_digit>;

tests/matching2-msvc-greedy.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,9 @@ static_assert(CTRE_CREATE("[(-)]").match(")"));
220220
static_assert(CTRE_CREATE("[A-Z_a-z]").match("a"));
221221
static_assert(CTRE_CREATE("[A-Z_a-z]").match("_"));
222222
static_assert(CTRE_CREATE("[A-Z_a-z]").match("Z"));
223-
static_assert(CTRE_CREATE("[-]").match("-"));
224-
static_assert(CTRE_CREATE("[-x]").match("x"));
223+
// FIXME: maybe in future I will allow this again
224+
// static_assert(CTRE_CREATE("[-]").match("-"));
225+
// static_assert(CTRE_CREATE("[-x]").match("x"));
225226
// FIXME: due current limitation of LL1 grammar parser I can make this work "[x-]" without significant change in grammar
226227
static_assert(CTRE_CREATE("<").match("<"));
227228
static_assert(CTRE_CREATE("(<)").match("<"));
@@ -272,7 +273,6 @@ static_assert(CTRE_CREATE("(<[a-z]+>)\\g{1}").match("<aloha><aloha>"sv));
272273
static_assert(CTRE_CREATE("[^\\^]").match("a"sv));
273274
static_assert(CTRE_CREATE("[^^]").match("a"sv));
274275
static_assert(CTRE_CREATE("[\\-]").match("-"sv));
275-
static_assert(CTRE_CREATE("[-]").match("-"sv));
276276
static_assert(CTRE_CREATE("[\\--\\-]").match("-"sv));
277277

278278
// msvc

tests/matching2.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ static_assert(CTRE_CREATE("[(-)]").match(")"));
218218
static_assert(CTRE_CREATE("[A-Z_a-z]").match("a"));
219219
static_assert(CTRE_CREATE("[A-Z_a-z]").match("_"));
220220
static_assert(CTRE_CREATE("[A-Z_a-z]").match("Z"));
221-
static_assert(CTRE_CREATE("[-]").match("-"));
222-
static_assert(CTRE_CREATE("[-x]").match("x"));
221+
// static_assert(CTRE_CREATE("[-]").match("-"));
222+
// static_assert(CTRE_CREATE("[-x]").match("x"));
223223
// FIXME: due current limitation of LL1 grammar parser I can make this work "[x-]" without significant change in grammar
224224
static_assert(CTRE_CREATE("<").match("<"));
225225
static_assert(CTRE_CREATE("(<)").match("<"));
@@ -270,5 +270,5 @@ static_assert(CTRE_CREATE("(<[a-z]+>)\\g{1}").match("<aloha><aloha>"sv));
270270
static_assert(CTRE_CREATE("[^\\^]").match("a"sv));
271271
static_assert(CTRE_CREATE("[^^]").match("a"sv));
272272
static_assert(CTRE_CREATE("[\\-]").match("-"sv));
273-
static_assert(CTRE_CREATE("[-]").match("-"sv));
273+
//static_assert(CTRE_CREATE("[-]").match("-"sv));
274274
static_assert(CTRE_CREATE("[\\--\\-]").match("-"sv));

0 commit comments

Comments
 (0)