Skip to content

Commit d0f3778

Browse files
authored
Merge pull request #135 from hanickadot/multiline
multiline support + new asserts
2 parents a947f4f + e3d95c7 commit d0f3778

28 files changed

+2322
-1941
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*.o
22
*.d
3+
**/*.tmp
34
test
45
result
56
tests/benchmark-exec/*

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ ctre::match<"REGEX">(subject); // C++20
1919
* Searching (`search` or `starts_with`)
2020
* Capturing content (named captures are supported too)
2121
* Back-Reference (\g{N} syntax, and \1...\9 syntax too)
22+
* Multiline support (with `multi_`) functions
23+
* Unicode properties and UTF-8 support
2224

2325
The library is implementing most of the PCRE syntax with a few exceptions:
2426

2527
* atomic groups
26-
* boundaries other than `^$`
2728
* callouts
2829
* comments
2930
* conditional patterns

include/ctll/fixed_string.hpp.orig

-218
This file was deleted.

include/ctre/actions/asserts.inc.hpp

+17-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,27 @@
33

44
// push_assert_begin
55
template <auto V, typename... Ts, typename Parameters> static constexpr auto apply(pcre::push_assert_begin, ctll::term<V>, pcre_context<ctll::list<Ts...>, Parameters> subject) {
6-
return pcre_context{ctll::push_front(assert_begin(), subject.stack), subject.parameters};
6+
return pcre_context{ctll::push_front(assert_line_begin(), subject.stack), subject.parameters};
77
}
88

99
// push_assert_end
1010
template <auto V, typename... Ts, typename Parameters> static constexpr auto apply(pcre::push_assert_end, ctll::term<V>, pcre_context<ctll::list<Ts...>, Parameters> subject) {
11-
return pcre_context{ctll::push_front(assert_end(), subject.stack), subject.parameters};
11+
return pcre_context{ctll::push_front(assert_line_end(), subject.stack), subject.parameters};
12+
}
13+
14+
// push_assert_begin
15+
template <auto V, typename... Ts, typename Parameters> static constexpr auto apply(pcre::push_assert_subject_begin, ctll::term<V>, pcre_context<ctll::list<Ts...>, Parameters> subject) {
16+
return pcre_context{ctll::push_front(assert_subject_begin(), subject.stack), subject.parameters};
17+
}
18+
19+
// push_assert_subject_end
20+
template <auto V, typename... Ts, typename Parameters> static constexpr auto apply(pcre::push_assert_subject_end, ctll::term<V>, pcre_context<ctll::list<Ts...>, Parameters> subject) {
21+
return pcre_context{ctll::push_front(assert_subject_end(), subject.stack), subject.parameters};
22+
}
23+
24+
// push_assert_subject_end_with_lineend
25+
template <auto V, typename... Ts, typename Parameters> static constexpr auto apply(pcre::push_assert_subject_end_with_lineend, ctll::term<V>, pcre_context<ctll::list<Ts...>, Parameters> subject) {
26+
return pcre_context{ctll::push_front(assert_subject_end_line(), subject.stack), subject.parameters};
1227
}
1328

1429
#endif
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef CTRE__ACTIONS__BOUNDARIES__HPP
2+
#define CTRE__ACTIONS__BOUNDARIES__HPP
3+
4+
// push_word_boundary
5+
template <auto V, typename... Ts, typename Parameters> static constexpr auto apply(pcre::push_word_boundary, ctll::term<V>, pcre_context<ctll::list<Ts...>, Parameters> subject) {
6+
return pcre_context{ctll::push_front(boundary<word_chars>(), subject.stack), subject.parameters};
7+
}
8+
9+
// push_not_word_boundary
10+
template <auto V, typename... Ts, typename Parameters> static constexpr auto apply(pcre::push_not_word_boundary, ctll::term<V>, pcre_context<ctll::list<Ts...>, Parameters> subject) {
11+
return pcre_context{ctll::push_front(boundary<negative_set<word_chars>>(), subject.stack), subject.parameters};
12+
}
13+
14+
#endif

include/ctre/atoms.hpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef CTRE__ATOMS__HPP
22
#define CTRE__ATOMS__HPP
33

4+
#include "atoms_characters.hpp"
45
#include <cstdint>
56

67
namespace ctre {
@@ -14,6 +15,8 @@ struct end_cycle_mark { };
1415
struct end_lookahead_mark { };
1516
template <size_t Id> struct numeric_mark { };
1617

18+
struct any { };
19+
1720
// actual AST of regexp
1821
template <auto... Str> struct string { };
1922
template <typename... Opts> struct select { };
@@ -51,9 +54,17 @@ struct atomic_start { };
5154

5255
template <typename... Content> struct atomic_group { };
5356

54-
struct assert_begin { };
55-
struct assert_end { };
57+
template <typename... Content> struct boundary { };
58+
template <typename... Content> struct not_boundary { };
59+
60+
using word_boundary = boundary<word_chars>;
61+
using not_word_boundary = not_boundary<word_chars>;
5662

63+
struct assert_subject_begin { };
64+
struct assert_subject_end { };
65+
struct assert_subject_end_line{ };
66+
struct assert_line_begin { };
67+
struct assert_line_end { };
5768

5869
}
5970

include/ctre/atoms_characters.hpp

+3-7
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,22 @@ template <auto V> struct character {
2323
}
2424
};
2525

26-
struct any {
27-
template <typename CharT> CTRE_FORCE_INLINE static constexpr bool match_char(CharT) noexcept { return true; }
28-
};
29-
3026
template <typename... Content> struct negative_set {
31-
template <typename CharT> inline static constexpr bool match_char(CharT value) noexcept {
27+
template <typename CharT> CTRE_FORCE_INLINE static constexpr bool match_char(CharT value) noexcept {
3228
return !(Content::match_char(value) || ... || false);
3329
}
3430
};
3531

3632
template <typename... Content> struct set {
37-
template <typename CharT> inline static constexpr bool match_char(CharT value) noexcept {
33+
template <typename CharT> CTRE_FORCE_INLINE static constexpr bool match_char(CharT value) noexcept {
3834
return (Content::match_char(value) || ... || false);
3935
}
4036
};
4137

4238
template <auto... Cs> struct enumeration : set<character<Cs>...> { };
4339

4440
template <typename... Content> struct negate {
45-
template <typename CharT> inline static constexpr bool match_char(CharT value) noexcept {
41+
template <typename CharT> CTRE_FORCE_INLINE static constexpr bool match_char(CharT value) noexcept {
4642
return !(Content::match_char(value) || ... || false);
4743
}
4844
};

0 commit comments

Comments
 (0)