Skip to content

Commit 047fc2d

Browse files
committed
patch: make atomic sequence work like lookahead / lookbehind
(Appears to be working)
1 parent 6fcc033 commit 047fc2d

File tree

3 files changed

+12
-23
lines changed

3 files changed

+12
-23
lines changed

include/ctre/actions/sequence.inc.hpp

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,16 @@ template <auto V, auto... As, auto B, typename... Ts, typename Parameters> stati
1818
return pcre_context{ctll::push_front(string<B,As...>(), ctll::list<Ts...>()), subject.parameters};
1919
}
2020

21-
// atomic sequence
22-
template <auto V, typename... Content, typename... Ts, typename Parameters>
23-
static constexpr auto apply(pcre::make_atomic_sequence, ctll::term<V>, pcre_context<ctll::list<sequence<Content...>, Ts...>, Parameters> subject) {
24-
//return pcre_context{ ctll::push_front(atomic_sequence<Content...>(), ctll::list<Ts...>()), subject.parameters };
25-
return pcre_context{ ctll::list<atomic_sequence<Content...>,Ts...>(), subject.parameters };
21+
// atomic sequence start
22+
template <auto V, typename... Ts, size_t Counter> static constexpr auto apply(pcre::start_atomic_sequence, ctll::term<V>, pcre_context<ctll::list<Ts...>, pcre_parameters<Counter>>) {
23+
return pcre_context{ ctll::list<atomic_sequence_start<atomic_sequence<>>, Ts...>(), pcre_parameters<Counter>() };
2624
}
27-
28-
/*
29-
// make_atomic_sequence
30-
template <auto V, typename A, typename B, typename... Ts, typename Parameters> static constexpr auto apply(pcre::make_atomic_sequence, ctll::term<V>, pcre_context<ctll::list<B, A, Ts...>, Parameters> subject) {
31-
return pcre_context{ ctll::push_front(atomic_sequence<A,B>(), ctll::list<Ts...>()), subject.parameters };
32-
}
33-
// make_atomic_sequence (concat)
34-
template <auto V, typename... As, typename B, typename... Ts, typename Parameters> static constexpr auto apply(pcre::make_atomic_sequence, ctll::term<V>, pcre_context<ctll::list<atomic_sequence<As...>, B, Ts...>, Parameters> subject) {
35-
return pcre_context{ ctll::push_front(atomic_sequence<B,As...>(), ctll::list<Ts...>()), subject.parameters };
36-
}
37-
// make_atomic_sequence (make string)
38-
template <auto V, auto A, auto B, typename... Ts, typename Parameters> static constexpr auto apply(pcre::make_atomic_sequence, ctll::term<V>, pcre_context<ctll::list<character<B>, character<A>, Ts...>, Parameters> subject) {
39-
return pcre_context{ ctll::push_front(string<A,B>(), ctll::list<Ts...>()), subject.parameters };
25+
// atomic sequence end
26+
template <auto V, typename Atom, typename... Ts, size_t Counter> static constexpr auto apply(pcre::make_atomic_sequence, ctll::term<V>, pcre_context<ctll::list<Atom, atomic_sequence_start<atomic_sequence<>>, Ts...>, pcre_parameters<Counter>>) {
27+
return pcre_context{ ctll::list<lookahead_positive<Atom>, Ts...>(), pcre_parameters<Counter>() };
4028
}
41-
// make_atomic_sequence (concat string)
42-
template <auto V, auto... As, auto B, typename... Ts, typename Parameters> static constexpr auto apply(pcre::make_atomic_sequence, ctll::term<V>, pcre_context<ctll::list<string<As...>, character<B>, Ts...>, Parameters> subject) {
43-
return pcre_context{ ctll::push_front(string<B,As...>(), ctll::list<Ts...>()), subject.parameters };
29+
// atomic sequence end (atomic_sequence)
30+
template <auto V, typename... Atom, typename... Ts, size_t Counter> static constexpr auto apply(pcre::make_atomic_sequence, ctll::term<V>, pcre_context<ctll::list<ctre::atomic_sequence<Atom...>, atomic_sequence_start<atomic_sequence<>>, Ts...>, pcre_parameters<Counter>>) {
31+
return pcre_context{ ctll::list<lookahead_positive<Atom...>, Ts...>(), pcre_parameters<Counter>() };
4432
}
45-
*/
4633
#endif

include/ctre/atoms.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ template <size_t Index> struct back_reference { };
4444
template <typename Name> struct back_reference_with_name { };
4545

4646
template <typename Type> struct look_start { };
47+
template <typename Type> struct atomic_sequence_start {};
4748

4849
template <typename... Content> struct lookahead_positive { };
4950
template <typename... Content> struct lookahead_negative { };

include/ctre/pcre.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ struct pcre {
125125
struct set_start: ctll::action {};
126126
struct start_lookahead_negative: ctll::action {};
127127
struct start_lookahead_positive: ctll::action {};
128+
struct start_atomic_sequence: ctll::action {};
128129

129130
// (q)LL1 function:
130131
using _others = ctll::neg_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','0','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'>;
@@ -246,7 +247,7 @@ struct pcre {
246247
static constexpr auto rule(d, ctll::term<':'>) -> ctll::push<reset_capture, ctll::anything, content_in_capture, ctll::term<'\x29'>>;
247248
static constexpr auto rule(d, ctll::term<'!'>) -> ctll::push<reset_capture, ctll::anything, start_lookahead_negative, content_in_capture, look_finish, ctll::term<'\x29'>>;
248249
static constexpr auto rule(d, ctll::term<'='>) -> ctll::push<reset_capture, ctll::anything, start_lookahead_positive, content_in_capture, look_finish, ctll::term<'\x29'>>;
249-
static constexpr auto rule(d, ctll::term<'>'>) -> ctll::push<reset_capture, ctll::anything, content_in_capture, make_atomic_sequence, ctll::term<'\x29'>>;
250+
static constexpr auto rule(d, ctll::term<'>'>) -> ctll::push<reset_capture, ctll::anything, start_atomic_sequence, content_in_capture, make_atomic_sequence, ctll::term<'\x29'>>;
250251

251252
static constexpr auto rule(e, ctll::term<'d'>) -> ctll::push<ctll::anything, class_digit>;
252253
static constexpr auto rule(e, ctll::term<'h'>) -> ctll::push<ctll::anything, class_horizontal_space>;

0 commit comments

Comments
 (0)