Skip to content

Commit 274202f

Browse files
author
Hana Dusíková
committed
- fix issue #74: lookahead optimizer will no fail always optimize greedy => possessive, but it won't give you false negative error
- remove unnecessory ;
1 parent 42aab39 commit 274202f

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

include/ctre/first.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,14 @@ constexpr auto first(ctll::list<Content...> l, ctll::list<repeat<0, B, Seq...>,
134134

135135
// lookahead_positive
136136
template <typename... Content, typename... Seq, typename... Tail>
137-
constexpr auto first(ctll::list<Content...> l, ctll::list<lookahead_positive<Seq...>, Tail...>) noexcept {
138-
auto out = first(l, ctll::list<Seq..., Tail...>{});
139-
return first(out, ctll::list<Tail...>{});
137+
constexpr auto first(ctll::list<Content...>, ctll::list<lookahead_positive<Seq...>, Tail...>) noexcept {
138+
return ctll::list<can_be_anything>{};
140139
}
141140

142141
// lookahead_negative TODO fixme
143142
template <typename... Content, typename... Seq, typename... Tail>
144143
constexpr auto first(ctll::list<Content...>, ctll::list<lookahead_negative<Seq...>, Tail...>) noexcept {
145-
return can_be_anything{};
144+
return ctll::list<can_be_anything>{};
146145
}
147146

148147
// capture

single-header/ctre.hpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -578,13 +578,13 @@ template <typename T, typename... As> constexpr auto pop_front_and_push_front(T
578578

579579
// match any term
580580
struct anything {
581-
constexpr inline anything() noexcept { };
581+
constexpr inline anything() noexcept { }
582582
template <auto V> constexpr anything(term<V>) noexcept;
583583
};
584584

585585
// match range of term A-B
586586
template <auto A, decltype(A) B> struct range {
587-
constexpr inline range() noexcept { };
587+
constexpr inline range() noexcept { }
588588
//template <auto V> constexpr range(term<V>) noexcept requires (A <= V) && (V <= B);
589589
template <auto V, typename = std::enable_if_t<(A <= V) && (V <= B)>> constexpr inline range(term<V>) noexcept;
590590
};
@@ -597,7 +597,7 @@ template <auto V, auto... Set> struct contains {
597597

598598
// match terms defined in set
599599
template <auto... Def> struct set {
600-
constexpr inline set() noexcept { };
600+
constexpr inline set() noexcept { }
601601
#ifdef __EDG__
602602
template <auto V, typename = std::enable_if_t<contains<V, Def...>::value>> constexpr inline set(term<V>) noexcept;
603603
#else
@@ -607,7 +607,7 @@ template <auto... Def> struct set {
607607

608608
// match terms not defined in set
609609
template <auto... Def> struct neg_set {
610-
constexpr inline neg_set() noexcept { };
610+
constexpr inline neg_set() noexcept { }
611611

612612
#ifdef __EDG__
613613
template <auto V, typename = std::enable_if_t<!contains<V, Def...>::value>> constexpr inline neg_set(term<V>) noexcept;
@@ -2740,15 +2740,14 @@ constexpr auto first(ctll::list<Content...> l, ctll::list<repeat<0, B, Seq...>,
27402740

27412741
// lookahead_positive
27422742
template <typename... Content, typename... Seq, typename... Tail>
2743-
constexpr auto first(ctll::list<Content...> l, ctll::list<lookahead_positive<Seq...>, Tail...>) noexcept {
2744-
auto out = first(l, ctll::list<Seq..., Tail...>{});
2745-
return first(out, ctll::list<Tail...>{});
2743+
constexpr auto first(ctll::list<Content...>, ctll::list<lookahead_positive<Seq...>, Tail...>) noexcept {
2744+
return ctll::list<can_be_anything>{};
27462745
}
27472746

27482747
// lookahead_negative TODO fixme
27492748
template <typename... Content, typename... Seq, typename... Tail>
27502749
constexpr auto first(ctll::list<Content...>, ctll::list<lookahead_negative<Seq...>, Tail...>) noexcept {
2751-
return can_be_anything{};
2750+
return ctll::list<can_be_anything>{};
27522751
}
27532752

27542753
// capture
@@ -3554,8 +3553,8 @@ template <typename RE> struct regular_expression {
35543553
template <typename IteratorBegin, typename IteratorEnd> constexpr CTRE_FORCE_INLINE static auto search_2(IteratorBegin begin, IteratorEnd end) noexcept {
35553554
return search_re(begin, end, RE());
35563555
}
3557-
constexpr CTRE_FORCE_INLINE regular_expression() noexcept { };
3558-
constexpr CTRE_FORCE_INLINE regular_expression(RE) noexcept { };
3556+
constexpr CTRE_FORCE_INLINE regular_expression() noexcept { }
3557+
constexpr CTRE_FORCE_INLINE regular_expression(RE) noexcept { }
35593558
template <typename Iterator> constexpr CTRE_FORCE_INLINE static auto match(Iterator begin, Iterator end) noexcept {
35603559
return match_re(begin, end, RE());
35613560
}

tests/matching3.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,9 @@ TEST_MATCH(111, "^abc$", "abc");
190190

191191
TEST_MATCH(112, "\\[\\]", "[]");
192192

193-
194-
193+
TEST_MATCH(113, "a+(?!b)", "aaaaaa");
194+
TEST_MATCH(114, "a+(?!b).", "aaaaaac");
195+
TEST_MATCH(115, "a+(?=b).", "aaaaaab");
195196

196197

197198

0 commit comments

Comments
 (0)