Skip to content

Commit

Permalink
Merge pull request #135 from hanickadot/multiline
Browse files Browse the repository at this point in the history
multiline support + new asserts
  • Loading branch information
hanickadot authored Nov 12, 2020
2 parents a947f4f + e3d95c7 commit d0f3778
Show file tree
Hide file tree
Showing 28 changed files with 2,322 additions and 1,941 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.o
*.d
**/*.tmp
test
result
tests/benchmark-exec/*
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ ctre::match<"REGEX">(subject); // C++20
* Searching (`search` or `starts_with`)
* Capturing content (named captures are supported too)
* Back-Reference (\g{N} syntax, and \1...\9 syntax too)
* Multiline support (with `multi_`) functions
* Unicode properties and UTF-8 support

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

* atomic groups
* boundaries other than `^$`
* callouts
* comments
* conditional patterns
Expand Down
218 changes: 0 additions & 218 deletions include/ctll/fixed_string.hpp.orig

This file was deleted.

19 changes: 17 additions & 2 deletions include/ctre/actions/asserts.inc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,27 @@

// push_assert_begin
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) {
return pcre_context{ctll::push_front(assert_begin(), subject.stack), subject.parameters};
return pcre_context{ctll::push_front(assert_line_begin(), subject.stack), subject.parameters};
}

// push_assert_end
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) {
return pcre_context{ctll::push_front(assert_end(), subject.stack), subject.parameters};
return pcre_context{ctll::push_front(assert_line_end(), subject.stack), subject.parameters};
}

// push_assert_begin
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) {
return pcre_context{ctll::push_front(assert_subject_begin(), subject.stack), subject.parameters};
}

// push_assert_subject_end
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) {
return pcre_context{ctll::push_front(assert_subject_end(), subject.stack), subject.parameters};
}

// push_assert_subject_end_with_lineend
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) {
return pcre_context{ctll::push_front(assert_subject_end_line(), subject.stack), subject.parameters};
}

#endif
14 changes: 14 additions & 0 deletions include/ctre/actions/boundaries.inc.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef CTRE__ACTIONS__BOUNDARIES__HPP
#define CTRE__ACTIONS__BOUNDARIES__HPP

// push_word_boundary
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) {
return pcre_context{ctll::push_front(boundary<word_chars>(), subject.stack), subject.parameters};
}

// push_not_word_boundary
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) {
return pcre_context{ctll::push_front(boundary<negative_set<word_chars>>(), subject.stack), subject.parameters};
}

#endif
15 changes: 13 additions & 2 deletions include/ctre/atoms.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef CTRE__ATOMS__HPP
#define CTRE__ATOMS__HPP

#include "atoms_characters.hpp"
#include <cstdint>

namespace ctre {
Expand All @@ -14,6 +15,8 @@ struct end_cycle_mark { };
struct end_lookahead_mark { };
template <size_t Id> struct numeric_mark { };

struct any { };

// actual AST of regexp
template <auto... Str> struct string { };
template <typename... Opts> struct select { };
Expand Down Expand Up @@ -51,9 +54,17 @@ struct atomic_start { };

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

struct assert_begin { };
struct assert_end { };
template <typename... Content> struct boundary { };
template <typename... Content> struct not_boundary { };

using word_boundary = boundary<word_chars>;
using not_word_boundary = not_boundary<word_chars>;

struct assert_subject_begin { };
struct assert_subject_end { };
struct assert_subject_end_line{ };
struct assert_line_begin { };
struct assert_line_end { };

}

Expand Down
10 changes: 3 additions & 7 deletions include/ctre/atoms_characters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,22 @@ template <auto V> struct character {
}
};

struct any {
template <typename CharT> CTRE_FORCE_INLINE static constexpr bool match_char(CharT) noexcept { return true; }
};

template <typename... Content> struct negative_set {
template <typename CharT> inline static constexpr bool match_char(CharT value) noexcept {
template <typename CharT> CTRE_FORCE_INLINE static constexpr bool match_char(CharT value) noexcept {
return !(Content::match_char(value) || ... || false);
}
};

template <typename... Content> struct set {
template <typename CharT> inline static constexpr bool match_char(CharT value) noexcept {
template <typename CharT> CTRE_FORCE_INLINE static constexpr bool match_char(CharT value) noexcept {
return (Content::match_char(value) || ... || false);
}
};

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

template <typename... Content> struct negate {
template <typename CharT> inline static constexpr bool match_char(CharT value) noexcept {
template <typename CharT> CTRE_FORCE_INLINE static constexpr bool match_char(CharT value) noexcept {
return !(Content::match_char(value) || ... || false);
}
};
Expand Down
Loading

0 comments on commit d0f3778

Please sign in to comment.