Skip to content

Commit 3f519b6

Browse files
author
Hana Dusíková
committed
cleaning
1 parent 5d0f97a commit 3f519b6

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

include/ctll/actions.hpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,28 @@
22
#define CTLL__ACTIONS__HPP
33

44
namespace ctll {
5+
struct empty_subject { };
6+
57
struct empty_actions {
68
// dummy operator so using Actions::operator() later will not give error
79
template <typename Action, typename InputSymbol, typename Subject> static constexpr auto apply(Action, InputSymbol, Subject subject) {
810
return subject;
911
}
1012
};
1113

14+
template <typename Actions> struct identity: public Actions {
15+
using Actions::apply;
16+
// allow empty_subject to exists
17+
template <typename Action, auto V> constexpr static auto apply(Action, term<V>, empty_subject) -> empty_subject { return {}; }
18+
template <typename Action> constexpr static auto apply(Action, epsilon, empty_subject) -> empty_subject { return {}; }
19+
};
1220

13-
template <bool IgnoreUnknown, typename Actions> struct augment_actions: public Actions {
21+
template <typename Actions> struct ignore_unknown: public Actions {
1422
using Actions::apply;
1523
// allow flow thru unknown actions
1624
template <typename Action, auto V, typename Subject> constexpr static auto apply(Action, term<V>, Subject) -> Subject { return {}; }
1725
template <typename Action, typename Subject> constexpr static auto apply(Action, epsilon, Subject) -> Subject { return {}; }
1826
};
19-
20-
template <typename Actions> struct augment_actions<false, Actions>: public Actions {
21-
using Actions::apply;
22-
// will fail if unknown action is called
23-
constexpr static auto apply(...) = delete;
24-
};
2527
}
2628

2729
#endif

include/ctll/parser.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
#include "actions.hpp"
88

99
namespace ctll {
10-
11-
struct empty_subject { };
10+
1211

1312
enum class decision {
1413
reject,
@@ -17,12 +16,12 @@ enum class decision {
1716
};
1817

1918
#if !__cpp_nontype_template_parameter_class
20-
template <typename Grammar, const auto & input, typename ActionSelector = empty_actions, bool IngoreUnknownActions = false> struct parser {
19+
template <typename Grammar, const auto & input, typename ActionSelector = empty_actions, bool IgnoreUnknownActions = false> struct parser {
2120
#else
22-
template <typename Grammar, basic_fixed_string input, typename ActionSelector = empty_actions, bool IngoreUnknownActions = true> struct parser { // in c++20
21+
template <typename Grammar, basic_fixed_string input, typename ActionSelector = empty_actions, bool IgnoreUnknownActions = true> struct parser { // in c++20
2322
#endif
23+
using Actions = ctll::conditional<IgnoreUnknownActions, ignore_unknown<ActionSelector>, identity<ActionSelector>>;
2424
static inline constexpr auto grammar = augment_grammar<Grammar>();
25-
static inline constexpr auto select_action = augment_actions<IngoreUnknownActions, ActionSelector>();
2625

2726
template <size_t Pos, typename Stack = void, typename Subject = void, decision Decision = decision::undecided> struct seed;
2827

@@ -92,7 +91,7 @@ template <typename Grammar, basic_fixed_string input, typename ActionSelector =
9291

9392
// in case top_symbol is action type (apply it on previous subject and get new one)
9493
if constexpr (std::is_base_of_v<ctll::action, decltype(top_symbol)>) {
95-
auto subject = select_action.apply(top_symbol, get_previous_term<Pos>(), previous_subject);
94+
auto subject = Actions::apply(top_symbol, get_previous_term<Pos>(), previous_subject);
9695

9796
// in case that semantic action is error => reject input
9897
if constexpr (std::is_same_v<ctll::reject, decltype(subject)>) {

include/ctre/return_type.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ template <size_t Id, typename Name = void> struct captured_content {
5252
}
5353

5454
constexpr CTRE_FORCE_INLINE auto to_view() const noexcept {
55-
return std::basic_string_view{_begin, static_cast<size_t>(std::distance(_begin, _end))};
55+
return std::string_view{_begin, static_cast<size_t>(std::distance(_begin, _end))};
5656
}
5757

5858
constexpr operator std::string_view() const noexcept {
@@ -163,15 +163,15 @@ template <typename Iterator, typename... Captures> struct regex_results {
163163
constexpr CTRE_FORCE_INLINE operator bool() const noexcept {
164164
return bool(_captures.template select<0>());
165165
}
166-
167-
using string_view_type = decltype(_captures.template select<0>().to_view());
168-
166+
169167
constexpr operator std::string_view() const noexcept {
170168
return to_view();
171169
}
170+
172171
constexpr auto to_view() const noexcept {
173172
return _captures.template select<0>().to_view();
174173
}
174+
175175
constexpr CTRE_FORCE_INLINE regex_results & set_start_mark(Iterator pos) noexcept {
176176
_captures.template select<0>().set_start(pos);
177177
return *this;

include/ctre/wrapper.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ template <typename RE> struct regular_expression {
3131
template <typename IteratorBegin, typename IteratorEnd> constexpr CTRE_FORCE_INLINE static auto search_2(IteratorBegin begin, IteratorEnd end) noexcept {
3232
return search_re(begin, end, RE());
3333
}
34+
constexpr CTRE_FORCE_INLINE regular_expression() noexcept { };
3435
constexpr CTRE_FORCE_INLINE regular_expression(RE) noexcept { };
3536
template <typename Iterator> constexpr CTRE_FORCE_INLINE static auto match(Iterator begin, Iterator end) noexcept {
3637
return match_re(begin, end, RE());

0 commit comments

Comments
 (0)