Skip to content

Commit c0d2da9

Browse files
author
Hana Dusíková
committed
fixed issues #23 and #24
1 parent ac19dd0 commit c0d2da9

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

include/ctre/pcre.gram

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ block_name2->alphanum_characters,[push_name],<block_name2>|epsilon
6464

6565

6666
character_class->sopen,<set>,[set_make],sclose|sopen,caret,<set>,[set_make_negative],sclose
67+
set->minus,[push_character],[set_start],<set2>
6768
set-><setitem>,[set_start],<set2>
6869
set2-><setitem>,[set_combine],<set2>|epsilon
6970

@@ -121,7 +122,7 @@ backslash->g,copen,<block_name>,cclose,[make_back_reference]
121122

122123
character->other,[push_character] | nonspecial_characters,[push_character] | set_control_chars,[push_character] | dot,[push_character_anything] | backslash,<backslash>|capture_control_chars,[push_character] | \>,[push_character]
123124

124-
character_in_capture->other,[push_character] | nonspecial_characters,[push_character] | set_control_chars,[push_character] | \>,[push_character] | dot,[push_character_anything] | backslash,<backslash>
125+
character_in_capture-><character>
125126

126127
asserts->caret,[push_assert_begin] | dolar,[push_assert_end]
127128

include/ctre/pcre.hpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,11 @@ struct pcre {
168168
static constexpr auto rule(c, ctll::term<'?'>) -> ctll::push<ctll::anything, m>;
169169
static constexpr auto rule(c, ctll::term<'^'>) -> ctll::push<ctll::anything, push_assert_begin, repeat, string2, content2, make_capture, ctll::term<'\x29'>>;
170170
static constexpr auto rule(c, ctll::term<'$'>) -> ctll::push<ctll::anything, push_assert_end, repeat, string2, content2, make_capture, ctll::term<'\x29'>>;
171-
static constexpr auto rule(c, ctll::set<',','-',':','>','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U',']','a','0','V','W','X','Y','Z','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','1','2','3','4','5','6','7','8','9'>) -> ctll::push<ctll::anything, push_character, repeat, string2, content2, make_capture, ctll::term<'\x29'>>;
171+
static constexpr auto rule(c, ctll::set<',','-',':','<','>','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U',']','a','0','V','W','X','Y','Z','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','1','2','3','4','5','6','7','8','9'>) -> ctll::push<ctll::anything, push_character, repeat, string2, content2, make_capture, ctll::term<'\x29'>>;
172172
static constexpr auto rule(c, _others) -> ctll::push<ctll::anything, push_character, repeat, string2, content2, make_capture, ctll::term<'\x29'>>;
173173
static constexpr auto rule(c, ctll::term<'.'>) -> ctll::push<ctll::anything, push_character_anything, repeat, string2, content2, make_capture, ctll::term<'\x29'>>;
174174
static constexpr auto rule(c, ctll::term<'\x29'>) -> ctll::push<push_empty, make_capture, ctll::anything>;
175-
static constexpr auto rule(c, ctll::set<'*','+','<','_','\x7B','|','\x7D'>) -> ctll::reject;
175+
static constexpr auto rule(c, ctll::set<'*','+','_','\x7B','|','\x7D'>) -> ctll::reject;
176176

177177
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>;
178178
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>;
@@ -195,18 +195,19 @@ struct pcre {
195195
static constexpr auto rule(content_in_capture, ctll::term<'['>) -> ctll::push<ctll::anything, d, repeat, string2, content2>;
196196
static constexpr auto rule(content_in_capture, ctll::term<'^'>) -> ctll::push<ctll::anything, push_assert_begin, repeat, string2, content2>;
197197
static constexpr auto rule(content_in_capture, ctll::term<'$'>) -> ctll::push<ctll::anything, push_assert_end, repeat, string2, content2>;
198-
static constexpr auto rule(content_in_capture, ctll::set<',','-',':','>','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U',']','a','0','V','W','X','Y','Z','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','1','2','3','4','5','6','7','8','9'>) -> ctll::push<ctll::anything, push_character, repeat, string2, content2>;
198+
static constexpr auto rule(content_in_capture, ctll::set<',','-',':','<','>','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U',']','a','0','V','W','X','Y','Z','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','1','2','3','4','5','6','7','8','9'>) -> ctll::push<ctll::anything, push_character, repeat, string2, content2>;
199199
static constexpr auto rule(content_in_capture, _others) -> ctll::push<ctll::anything, push_character, repeat, string2, content2>;
200200
static constexpr auto rule(content_in_capture, ctll::term<'.'>) -> ctll::push<ctll::anything, push_character_anything, repeat, string2, content2>;
201201
static constexpr auto rule(content_in_capture, ctll::term<'\x29'>) -> ctll::push<push_empty>;
202-
static constexpr auto rule(content_in_capture, ctll::set<'*','+','<','?','_','\x7B','|','\x7D'>) -> ctll::reject;
202+
static constexpr auto rule(content_in_capture, ctll::set<'*','+','?','_','\x7B','|','\x7D'>) -> ctll::reject;
203203

204204
static constexpr auto rule(d, ctll::term<'['>) -> ctll::push<ctll::anything, ctll::term<':'>, h, range, set_start, set2, set_make, ctll::term<']'>>;
205205
static constexpr auto rule(d, ctll::term<'\\'>) -> ctll::push<ctll::anything, e, set_start, set2, set_make, ctll::term<']'>>;
206206
static constexpr auto rule(d, 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','0','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','1','2','3','4','5','6','7','8','9'>) -> ctll::push<ctll::anything, push_character, range, set_start, set2, set_make, ctll::term<']'>>;
207207
static constexpr auto rule(d, _others) -> ctll::push<ctll::anything, push_character, range, set_start, set2, set_make, ctll::term<']'>>;
208+
static constexpr auto rule(d, ctll::term<'-'>) -> ctll::push<ctll::anything, push_character, set_start, set2, set_make, ctll::term<']'>>;
208209
static constexpr auto rule(d, ctll::term<'^'>) -> ctll::push<ctll::anything, set, set_make_negative, ctll::term<']'>>;
209-
static constexpr auto rule(d, ctll::set<'-','<','>',']','|'>) -> ctll::reject;
210+
static constexpr auto rule(d, ctll::set<'<','>',']','|'>) -> ctll::reject;
210211

211212
static constexpr auto rule(e, ctll::term<'d'>) -> ctll::push<ctll::anything, class_digit>;
212213
static constexpr auto rule(e, ctll::term<'D'>) -> ctll::push<ctll::anything, class_nondigit>;
@@ -312,7 +313,8 @@ struct pcre {
312313
static constexpr auto rule(set, ctll::term<'\\'>) -> ctll::push<ctll::anything, e, set_start, set2>;
313314
static constexpr auto rule(set, 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','0','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','1','2','3','4','5','6','7','8','9'>) -> ctll::push<ctll::anything, push_character, range, set_start, set2>;
314315
static constexpr auto rule(set, _others) -> ctll::push<ctll::anything, push_character, range, set_start, set2>;
315-
static constexpr auto rule(set, ctll::set<'-','<','>',']','^','|'>) -> ctll::reject;
316+
static constexpr auto rule(set, ctll::term<'-'>) -> ctll::push<ctll::anything, push_character, set_start, set2>;
317+
static constexpr auto rule(set, ctll::set<'<','>',']','^','|'>) -> ctll::reject;
316318

317319
static constexpr auto rule(string2, ctll::set<'\x29','|'>) -> ctll::epsilon;
318320
static constexpr auto rule(string2, ctll::epsilon) -> ctll::epsilon;

tests/matching2.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,15 @@ static_assert("[(-)]"_ctre.match(")"));
185185
static_assert("[A-Z_a-z]"_ctre.match("a"));
186186
static_assert("[A-Z_a-z]"_ctre.match("_"));
187187
static_assert("[A-Z_a-z]"_ctre.match("Z"));
188+
static_assert("[-]"_ctre.match("-"));
189+
static_assert("[-x]"_ctre.match("x"));
190+
// FIXME: due current limitation of LL1 grammar parser I can make this work "[x-]" without significant change in grammar
191+
static_assert("<"_ctre.match("<"));
192+
static_assert("(<)"_ctre.match("<"));
193+
static_assert("(<>)"_ctre.match("<>"));
194+
static_assert("(<>?)"_ctre.match("<"));
195+
static_assert("(<?>)"_ctre.match(">"));
196+
188197

189198
static_assert(("[a-z]"_ctre >> "[0-9]"_ctre).match("a9"));
190199
static_assert(("a"_ctre | "b"_ctre).match("a"));

0 commit comments

Comments
 (0)