Skip to content

Commit 76c3465

Browse files
author
Hana Dusíková
committed
Merge branch 'master' of github.com:hanickadot/compile-time-regular-expressions
2 parents 9626809 + 04db9f9 commit 76c3465

File tree

12 files changed

+1072
-66
lines changed

12 files changed

+1072
-66
lines changed

.travis.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,6 @@ matrix:
3939
- os: osx
4040
osx_image: xcode10
4141

42-
before_install:
43-
- |
44-
if [[ (-x $(which brew)) ]]; then
45-
brew update
46-
brew install boost || brew upgrade boost
47-
brew install pcre2 || brew upgrade pcre2
48-
brew install re2 || brew upgrade re2
49-
else
50-
sudo add-apt-repository -y ppa:sergey-dryabzhinsky/packages
51-
sudo apt-get update -qq
52-
sudo apt-get install -qq libpcre2-dev libre2-dev libboost-all-dev
53-
fi
54-
5542
install:
5643
- if [[ "${COMPILER}" != "" ]]; then export CXX=${COMPILER}; fi
5744
- uname -a

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ DESATOMAT := /www/root/desatomat/console/desatomat.php
1010
CPP_STANDARD := $(shell ./cpp-20-check.sh $(CXX))
1111

1212
override CXXFLAGS := $(CXXFLAGS) $(CPP_STANDARD) -Iinclude -O3 -pedantic -Wall -Wextra
13-
LDFLAGS := -lre2 -lboost_regex -lpcre2-8
13+
LDFLAGS :=
1414

1515
TESTS := $(wildcard tests/*.cpp) $(wildcard tests/benchmark/*.cpp)
1616
TRUE_TARGETS := $(TARGETS:%.cpp=%)

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ More documentation on [pcre.org](https://www.pcre.org/current/doc/html/pcre2synt
4343

4444
## Supported compilers
4545

46-
* clang 5.0+ (template UDL, C++17 syntax)
47-
* gcc 7.2+ (template UDL, C++17 syntax)
46+
* clang 6.0+ (template UDL, C++17 syntax)
47+
* xcode clang 10.0+ (template UDL, C++17 syntax)
48+
* gcc 7.4+ (template UDL, C++17 syntax)
4849
* gcc 9.0+ (C++17 & C++20 cNTTP syntax)
4950
* MSVC 15.8.8+ (C++17 syntax only)
5051

include/ctll/fixed_string.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <utility>
55
#include <cstddef>
66
#include <string_view>
7+
#include <cstdint>
78

89
namespace ctll {
910

include/ctre/evaluation.hpp

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "utility.hpp"
88
#include "return_type.hpp"
99
#include "find_captures.hpp"
10+
#include "first.hpp"
1011

1112
namespace ctre {
1213

@@ -219,23 +220,15 @@ constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, c
219220
// possessive repeat
220221
template <typename R, typename Iterator, typename EndIterator, size_t A, size_t B, typename... Content, typename... Tail>
221222
constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list<possessive_repeat<A,B,Content...>, Tail...>) noexcept {
222-
// A..B
223-
size_t i{0};
224-
for (; i < A && (A != 0); ++i) {
225-
if (auto inner_result = evaluate(begin, current, end, captures, ctll::list<sequence<Content...>, end_cycle_mark>())) {
226-
captures = inner_result.unmatch();
227-
current = inner_result.get_end_position();
228-
} else {
229-
return not_matched;
230-
}
231-
}
232-
233-
for (; (i < B) || (B == 0); ++i) {
223+
224+
for (size_t i{0}; (i < B) || (B == 0); ++i) {
234225
// try as many of inner as possible and then try outer once
235226
if (auto inner_result = evaluate(begin, current, end, captures, ctll::list<sequence<Content...>, end_cycle_mark>())) {
227+
captures = inner_result.unmatch();
236228
current = inner_result.get_end_position();
237229
} else {
238-
return evaluate(begin, current, end, captures, ctll::list<Tail...>());
230+
if (i < A && (A != 0)) return not_matched;
231+
else return evaluate(begin, current, end, captures, ctll::list<Tail...>());
239232
}
240233
}
241234

@@ -263,20 +256,43 @@ constexpr inline R evaluate_recursive(size_t i, const Iterator begin, Iterator c
263256
return evaluate(begin, current, end, captures, ctll::list<Tail...>());
264257
}
265258

259+
260+
// (gready) repeat optimization
261+
// basic one, if you are at the end of RE, just change it into possessive
262+
// TODO do the same if there is no collision with rest of the RE
266263
template <typename R, typename Iterator, typename EndIterator, size_t A, size_t B, typename... Content, typename... Tail>
267-
constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list<repeat<A,B,Content...>, Tail...> stack) {
268-
// A..B
269-
size_t i{0};
270-
for (; i < A && (A != 0); ++i) {
271-
if (auto inner_result = evaluate(begin, current, end, captures, ctll::list<sequence<Content...>, end_cycle_mark>())) {
272-
captures = inner_result.unmatch();
273-
current = inner_result.get_end_position();
274-
} else {
275-
return not_matched;
264+
constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list<repeat<A,B,Content...>,assert_end, Tail...>) {
265+
return evaluate(begin, current, end, captures, ctll::list<possessive_repeat<A,B,Content...>, assert_end, Tail...>());
266+
}
267+
268+
template <typename... T> struct identify_type;
269+
270+
// (greedy) repeat
271+
template <typename R, typename Iterator, typename EndIterator, size_t A, size_t B, typename... Content, typename... Tail>
272+
constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, R captures, [[maybe_unused]] ctll::list<repeat<A,B,Content...>, Tail...> stack) {
273+
// check if it can be optimized
274+
#ifndef CTRE_DISABLE_GREEDY_OPT
275+
if constexpr (collides(calculate_first(Content{}...), calculate_first(Tail{}...))) {
276+
#endif
277+
// A..B
278+
size_t i{0};
279+
for (; i < A && (A != 0); ++i) {
280+
if (auto inner_result = evaluate(begin, current, end, captures, ctll::list<sequence<Content...>, end_cycle_mark>())) {
281+
captures = inner_result.unmatch();
282+
current = inner_result.get_end_position();
283+
} else {
284+
return not_matched;
285+
}
276286
}
277-
}
278287

279-
return evaluate_recursive(i, begin, current, end, captures, stack);
288+
return evaluate_recursive(i, begin, current, end, captures, stack);
289+
#ifndef CTRE_DISABLE_GREEDY_OPT
290+
} else {
291+
// if there is no collision we can go possessive
292+
return evaluate(begin, current, end, captures, ctll::list<possessive_repeat<A,B,Content...>, Tail...>());
293+
}
294+
#endif
295+
280296
}
281297

282298
// repeat lazy_star

0 commit comments

Comments
 (0)