Skip to content

Commit 958e5a8

Browse files
author
Hana Dusíková
committed
Merge branch 'master' into cnttp
# Conflicts: # include/ctll/parser.hpp # include/ctre/literals.hpp # tests/generating.cpp # tests/matching2.cpp # tests/simple.cpp
2 parents 0503985 + 7eff180 commit 958e5a8

20 files changed

+245
-165
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ matrix:
4141

4242
- os: osx
4343
osx_image: xcode10
44-
44+
4545
before_install:
4646
- |
4747
if [[ (-x $(which brew)) ]]; then
4848
brew update
49-
brew install pcre2 re2 boost
49+
brew install boost || brew upgrade boost
50+
brew install pcre2 || brew upgrade pcre2
51+
brew install re2 || brew upgrade re2
5052
else
5153
sudo add-apt-repository -y ppa:sergey-dryabzhinsky/packages
5254
sudo apt-get update -qq

Makefile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ benchmark-clean:
4242
clean:
4343
rm -f $(TRUE_TARGETS) $(OBJECTS) $(DEPEDENCY_FILES) mtent12.txt mtent12.zip
4444

45-
grammar: include/ctre/pcre.hpp include/ctre/simple.hpp
45+
grammar: include/ctre/pcre.hpp
4646

4747
regrammar:
4848
@rm -f include/ctre/pcre.hpp
@@ -65,7 +65,3 @@ compare: mtent12.txt
6565
$(CXX) $(CXXFLAGS) -MMD -march=native -DPATTERN="\"(${PATTERN})\"" -c tests/benchmark-range/measurement.cpp -o tests/benchmark-range/measurement.o
6666
$(CXX) tests/benchmark-range/measurement.o -lboost_regex -lpcre2-8 -lre2 -o tests/benchmark-range/measurement
6767
tests/benchmark-range/measurement all mtent12.txt ${REPEAT}
68-
69-
#include/ctre/simple.hpp: include/ctre/simple.gram
70-
# @echo "LL1q $<"
71-
# @$(DESATOMAT) --ll --q --input=include/ctre/simple.gram --output=include/ctre/ --generator=cpp_ctll_v2 --cfg:fname=simple.hpp --cfg:namespace=ctre --cfg:guard=CTRE__SIMPLE__HPP --cfg:grammar_name=simple

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

README.md

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,35 @@ ctre::match<"REGEX">(subject); // C++20
2020
* `std::string`-like object (`std::string_view` or your own string if it's providing `begin`/`end` functions with forward iterators)
2121
* pair of forward iterators
2222

23+
## Supported compilers
24+
25+
* clang 5.0+ (template UDL, C++17 syntax)
26+
* gcc 7.2+ (template UDL, C++17 syntax)
27+
* gcc 9.0+ (C++17 & C++20 cNTTP syntax)
28+
* MSVC 15.8.8+ (C++17 syntax only)
29+
30+
#### Template UDL syntax
31+
32+
Compiler must support N3599 extension (as GNU extension in gcc and clang).
33+
34+
#### C++17 syntax
35+
36+
You can provide pattern as a `constexpr ctll::basic_fixed_string` variable.
37+
38+
```c++
39+
static constexpr auto pattern = ctll::basic_fixed_string{ "h.*" };
40+
41+
constexpr auto match(std::string_view sv) noexcept {
42+
return ctre::re<pattern>().match(sv);
43+
}
44+
```
45+
46+
(this is tested in MSVC 15.8.8)
47+
48+
#### C++20 syntax
49+
50+
Currently only compiler which supports cNTTP syntax `ctre::match<PATTERN>(subject)` is GCC 9+.
51+
2352
## Examples
2453

2554
#### Extracting number from input
@@ -94,25 +123,3 @@ for (auto match: ctre::range(input,"[0-9]++"_ctre)) {
94123
std::cout << std::string_view{match} << "\n";
95124
}
96125
```
97-
98-
## Supported compilers
99-
100-
* clang 5.0+
101-
* gcc 7.2+
102-
* MSVC 15.8.8+ (experimental, without string_literal support)
103-
104-
Compiler must support N3599 extension (as GNU extension in gcc and clang) or C++20 class NTTP (P0732).
105-
106-
### MSVC
107-
108-
Because current MSVC doesn't support custom templated string literals or NTTP, you need to use workaround:
109-
110-
```c++
111-
static constexpr inline auto pattern = ctll::basic_fixed_string{ "h.*" };
112-
113-
constexpr auto match(std::string_view sv) noexcept {
114-
return ctre::re<pattern>().match(sv);
115-
}
116-
```
117-
118-
(this is tested in MSVC 15.8.8)

include/ctre/actions/backreference.inc.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@
22
#define CTRE__ACTIONS__BACKREFERENCE__HPP
33

44
// backreference with name
5-
template <auto... Str, auto V, typename... Ts, size_t Counter> static constexpr auto apply(pcre::make_back_reference, ctll::term<V>, pcre_context<ctll::list<id<Str...>, Ts...>, pcre_parameters<Counter>> subject) {
6-
return pcre_context{ctll::push_front(back_reference_with_name<id<Str...>>(), ctll::list<Ts...>()), subject};
5+
template <auto... Str, auto V, typename... Ts, size_t Counter> static constexpr auto apply(pcre::make_back_reference, ctll::term<V>, pcre_context<ctll::list<id<Str...>, Ts...>, pcre_parameters<Counter>>) {
6+
return pcre_context{ctll::push_front(back_reference_with_name<id<Str...>>(), ctll::list<Ts...>()), pcre_parameters<Counter>()};
77
}
88

99
// with just a number
10-
template <auto V, size_t Id, typename... Ts, size_t Counter> static constexpr auto apply(pcre::make_back_reference, ctll::term<V>, pcre_context<ctll::list<number<Id>, Ts...>, pcre_parameters<Counter>> subject) {
10+
template <auto V, size_t Id, typename... Ts, size_t Counter> static constexpr auto apply(pcre::make_back_reference, ctll::term<V>, pcre_context<ctll::list<number<Id>, Ts...>, pcre_parameters<Counter>>) {
1111
// if we are looking outside of existing list of Ids ... reject input during parsing
1212
if constexpr (Counter < Id) {
1313
return ctll::reject{};
1414
} else {
15-
return pcre_context{ctll::push_front(back_reference<Id>(), ctll::list<Ts...>()), subject};
15+
return pcre_context{ctll::push_front(back_reference<Id>(), ctll::list<Ts...>()), pcre_parameters<Counter>()};
1616
}
1717
}
1818

1919
// relative backreference
20-
template <auto V, size_t Id, typename... Ts, size_t Counter> static constexpr auto apply(pcre::make_relative_back_reference, ctll::term<V>, [[maybe_unused]] pcre_context<ctll::list<number<Id>, Ts...>, pcre_parameters<Counter>> subject) {
20+
template <auto V, size_t Id, typename... Ts, size_t Counter> static constexpr auto apply(pcre::make_relative_back_reference, ctll::term<V>, [[maybe_unused]] pcre_context<ctll::list<number<Id>, Ts...>, pcre_parameters<Counter>>) {
2121
// if we are looking outside of existing list of Ids ... reject input during parsing
2222
if constexpr (Counter < Id) {
2323
return ctll::reject{};
2424
} else {
2525
constexpr size_t absolute_id = (Counter + 1) - Id;
26-
return pcre_context{ctll::push_front(back_reference<absolute_id>(), ctll::list<Ts...>()), subject};
26+
return pcre_context{ctll::push_front(back_reference<absolute_id>(), ctll::list<Ts...>()), pcre_parameters<Counter>()};
2727
}
2828
}
2929

include/ctre/actions/look.inc.hpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#ifndef CTRE__ACTIONS__LOOKAHEAD__HPP
2+
#define CTRE__ACTIONS__LOOKAHEAD__HPP
3+
4+
// lookahead positive start
5+
template <auto V, typename... Ts, size_t Counter> static constexpr auto apply(pcre::start_lookahead_positive, ctll::term<V>, pcre_context<ctll::list<Ts...>, pcre_parameters<Counter>>) {
6+
return pcre_context{ctll::list<look_start<lookahead_positive<>>, Ts...>(), pcre_parameters<Counter>()};
7+
}
8+
9+
// lookahead positive end
10+
template <auto V, typename Look, typename... Ts, size_t Counter> static constexpr auto apply(pcre::look_finish, ctll::term<V>, pcre_context<ctll::list<Look, look_start<lookahead_positive<>>, Ts...>, pcre_parameters<Counter>>) {
11+
return pcre_context{ctll::list<lookahead_positive<Look>, Ts...>(), pcre_parameters<Counter>()};
12+
}
13+
14+
// lookahead positive end (sequence)
15+
template <auto V, typename... Look, typename... Ts, size_t Counter> static constexpr auto apply(pcre::look_finish, ctll::term<V>, pcre_context<ctll::list<ctre::sequence<Look...>, look_start<lookahead_positive<>>, Ts...>, pcre_parameters<Counter>>) {
16+
return pcre_context{ctll::list<lookahead_positive<Look...>, Ts...>(), pcre_parameters<Counter>()};
17+
}
18+
19+
// lookahead negative start
20+
template <auto V, typename... Ts, size_t Counter> static constexpr auto apply(pcre::start_lookahead_negative, ctll::term<V>, pcre_context<ctll::list<Ts...>, pcre_parameters<Counter>>) {
21+
return pcre_context{ctll::list<look_start<lookahead_negative<>>, Ts...>(), pcre_parameters<Counter>()};
22+
}
23+
24+
// lookahead negative end
25+
template <auto V, typename Look, typename... Ts, size_t Counter> static constexpr auto apply(pcre::look_finish, ctll::term<V>, pcre_context<ctll::list<Look, look_start<lookahead_negative<>>, Ts...>, pcre_parameters<Counter>>) {
26+
return pcre_context{ctll::list<lookahead_negative<Look>, Ts...>(), pcre_parameters<Counter>()};
27+
}
28+
29+
// lookahead negative end (sequence)
30+
template <auto V, typename... Look, typename... Ts, size_t Counter> static constexpr auto apply(pcre::look_finish, ctll::term<V>, pcre_context<ctll::list<ctre::sequence<Look...>, look_start<lookahead_negative<>>, Ts...>, pcre_parameters<Counter>>) {
31+
return pcre_context{ctll::list<lookahead_negative<Look...>, Ts...>(), pcre_parameters<Counter>()};
32+
}
33+
34+
#endif

include/ctre/atoms.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ struct accept { };
1010
struct start_mark { };
1111
struct end_mark { };
1212
struct end_cycle_mark { };
13+
struct end_lookahead_mark { };
1314
template <size_t Id> struct numeric_mark { };
1415

1516
// actual AST of regexp
@@ -39,10 +40,14 @@ template <size_t Index, typename Name, typename... Content> struct capture_with_
3940

4041
template <size_t Index> struct back_reference { };
4142
template <typename Name> struct back_reference_with_name { };
42-
43+
44+
template <typename Type> struct look_start { };
45+
46+
template <typename... Content> struct lookahead_positive { };
47+
template <typename... Content> struct lookahead_negative { };
4348

4449
struct assert_begin { };
45-
struct assert_end { };
50+
struct assert_end { };
4651

4752
}
4853

include/ctre/evaluation.hpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, c
145145
} else {
146146
return evaluate(begin, current, end, captures, ctll::list<HeadContent, Tail...>());
147147
}
148-
149148
}
150149

151150
// matching empty in patterns
@@ -361,6 +360,34 @@ constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, c
361360
return not_matched;
362361
}
363362

363+
// end of lookahead
364+
template <typename R, typename Iterator, typename EndIterator, typename... Tail>
365+
constexpr CTRE_FORCE_INLINE R evaluate(const Iterator, Iterator, const EndIterator, R captures, ctll::list<end_lookahead_mark>) noexcept {
366+
return captures.matched();
367+
}
368+
369+
// lookahead positive
370+
template <typename R, typename Iterator, typename EndIterator, typename... Content, typename... Tail>
371+
constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list<lookahead_positive<Content...>, Tail...>) noexcept {
372+
373+
if (auto lookahead_result = evaluate(begin, current, end, captures, ctll::list<sequence<Content...>, end_lookahead_mark>())) {
374+
captures = lookahead_result.unmatch();
375+
return evaluate(begin, current, end, captures, ctll::list<Tail...>());
376+
} else {
377+
return not_matched;
378+
}
379+
}
380+
381+
// lookahead negative
382+
template <typename R, typename Iterator, typename EndIterator, typename... Content, typename... Tail>
383+
constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list<lookahead_negative<Content...>, Tail...>) noexcept {
384+
385+
if (auto lookahead_result = evaluate(begin, current, end, captures, ctll::list<sequence<Content...>, end_lookahead_mark>())) {
386+
return not_matched;
387+
} else {
388+
return evaluate(begin, current, end, captures, ctll::list<Tail...>());
389+
}
390+
}
364391

365392
}
366393

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

include/ctre/functions.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include "../ctll.hpp"
55
#include "pcre_actions.hpp"
6-
#include "simple.hpp"
76
#include "evaluation.hpp"
87
#include "wrapper.hpp"
98
#include "id.hpp"

0 commit comments

Comments
 (0)