Skip to content

Commit 68acf26

Browse files
author
Hana Dusíková
committed
lookahead support (part 2)
1 parent 71b59c7 commit 68acf26

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

NOTES.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
* atomic groups
1313
* comments
1414
* options/modes
15-
* lookahead
1615
* subroutines
1716
* conditional patterns
1817
* callouts

include/ctre/evaluation.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,8 @@ constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, c
362362

363363
// end of lookahead
364364
template <typename R, typename Iterator, typename EndIterator, typename... Tail>
365-
constexpr CTRE_FORCE_INLINE R evaluate(const Iterator, Iterator current, const EndIterator, R captures, ctll::list<end_lookahead_mark>) noexcept {
366-
return captures.set_end_mark(current).matched();
365+
constexpr CTRE_FORCE_INLINE R evaluate(const Iterator, Iterator, const EndIterator, R captures, ctll::list<end_lookahead_mark>) noexcept {
366+
return captures.matched();
367367
}
368368

369369
// lookahead positive

include/ctre/find_captures.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,14 @@ template <size_t A, size_t B, typename... Content, typename... Tail, typename Ou
9898

9999

100100

101+
template <typename... Content, typename... Tail, typename Output> constexpr auto find_captures(ctll::list<lookahead_positive<Content...>, Tail...>, Output output) noexcept {
102+
return find_captures(ctll::list<Content..., Tail...>(), output);
103+
}
104+
101105

106+
template <typename... Content, typename... Tail, typename Output> constexpr auto find_captures(ctll::list<lookahead_negative<Content...>, Tail...>, Output output) noexcept {
107+
return find_captures(ctll::list<Content..., Tail...>(), output);
108+
}
102109

103110

104111

tests/generating.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ static_assert(same_f("^(?=.*(a))$"_ctre_gen, ctre::sequence<ctre::assert_begin,
163163

164164
static_assert(same_f("^(?=.*(a).*)$"_ctre_gen, ctre::sequence<ctre::assert_begin, ctre::lookahead_positive<ctre::star<ctre::any>,ctre::capture<1,ctre::character<'a'>>, ctre::star<ctre::any>>, ctre::assert_end>()));
165165

166-
//static_assert(same_f("^(?=.*(a)\\g{1}.*)$"_ctre_gen, ctre::sequence<ctre::assert_begin, ctre::lookahead_positive<ctre::star<ctre::any>,ctre::capture<1,ctre::character<'a'>>, ctre::back_reference<1>, ctre::star<ctre::any>>, ctre::assert_end>()));
166+
static_assert(same_f("^(?=.*(a)\\g{1}.*)$"_ctre_gen, ctre::sequence<ctre::assert_begin, ctre::lookahead_positive<ctre::star<ctre::any>,ctre::capture<1,ctre::character<'a'>>, ctre::back_reference<1>, ctre::star<ctre::any>>, ctre::assert_end>()));
167167

168+
static_assert(same_f("^(?=.*(a)\\g{1}.*)[a-z]$"_ctre_gen, ctre::sequence<ctre::assert_begin, ctre::lookahead_positive<ctre::star<ctre::any>,ctre::capture<1,ctre::character<'a'>>, ctre::back_reference<1>, ctre::star<ctre::any>>, ctre::set<ctre::char_range<'a','z'>>, ctre::assert_end>()));
168169

169-
//static_assert(same_f("^(?=.*(.)\\g{1}+.*)[a-z]+"_ctre_gen, ctre::sequence< ctre::assert_begin, ctre::lookahead_positive<ctre::star<ctre::any>, ctre::capture<1, ctre::any>, ctre::plus<ctre::back_reference<1>> ,ctre::star<ctre::any>>, ctre::plus<ctre::set<ctre::char_range<'a','z'>>> >());
170170

tests/matching2.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,17 @@ static_assert("a(?!3)[0-9]"_ctre.match("a0"sv));
217217
static_assert("a(?!3)[0-9]"_ctre.match("a9"sv));
218218
static_assert(!"a(?!3)[0-9]"_ctre.match("a3"sv));
219219

220-
static_assert(!"^(?=.*(.)\\g{1}+.*)[a-z]+"_ctre.search("abcdefgh"sv));
221-
static_assert("^(?=.*(.)\\g{1}+.*)[a-z]+"_ctre.search("abcddefgh"sv));
220+
static_assert(!".*(.)\\g{1}.*"_ctre.match("abcdefghijk"sv));
221+
static_assert(".*(.)\\g{1}.*"_ctre.match("aabcdefghijk"sv));
222+
static_assert(".*(.)\\g{1}.*"_ctre.match("abcdeffghijk"sv));
223+
224+
static_assert("(?=.*(.)\\g{1})[a-z]+"_ctre.match("abcdeffghijk"sv));
225+
static_assert(!"(?=.*(.)\\g{1}{2})[a-z]+"_ctre.match("abcddeffghijk"sv));
226+
static_assert("(?=.*(.)\\g{1}{2})[a-z]+"_ctre.match("abcdddeffghijk"sv));
227+
228+
static_assert( "(?!.*(.)\\g{1})[a-z]+"_ctre.match("abcdefgh"sv));
229+
static_assert(!"(?!.*(.)\\g{1})[a-z]+"_ctre.match("abcdeefgh"sv));
230+
231+
232+
222233

0 commit comments

Comments
 (0)