Skip to content

Commit 7d951a4

Browse files
author
Hana Dusíková
committed
cleaning
1 parent 3667ddf commit 7d951a4

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

include/ctll/parser.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,27 +116,30 @@ template <typename Grammar, basic_fixed_string input, typename ActionSelector =
116116
using output_type = Subject;
117117

118118
static constexpr auto parse() noexcept {
119+
// push current position to decide function with current stack and subject
119120
return decide<Pos>(Stack{}, Subject{});
120121
}
121122

122123
template <size_t RPos> constexpr auto operator+(placeholder<RPos>) const noexcept {
123-
if constexpr (Decision == decision::reject) {
124-
return *this;
125-
} else if constexpr (Decision == decision::accept) {
126-
return *this;
127-
} else {
124+
if constexpr (Decision == decision::undecided) {
125+
// parse for current char (RPos) with previous stack and subject :)
128126
return decltype(seed<RPos, Stack, Subject, Decision>::parse()){};
127+
} else {
128+
// if there is decision already => just push it to the end of fold expression
129+
return *this;
129130
}
130131
}
131132
};
132133

133134
// trampolines with folded expression
134135
template <typename Subject, size_t... Pos> static constexpr auto trampoline_decide(Subject default_subject, std::index_sequence<Pos...>) noexcept {
136+
// parse everything for first char and than for next and next ...
135137
// Pos+1 is needed as we want to finish calculation with epsilons on stack
136138
return (seed<0, decltype(grammar.start_stack), Subject, decision::undecided>::parse() + ... + placeholder<Pos+1>());
137139
}
138140

139141
template <typename Subject = empty_subject> static constexpr auto trampoline_decide(Subject subject = {}) noexcept {
142+
// there will be no recursion, just sequence long as the input
140143
return trampoline_decide(subject, std::make_index_sequence<input.size()>());
141144
}
142145

tests/trampoline.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include "ctre.hpp"
22

3-
static constexpr inline auto pattern = ctll::basic_fixed_string{"h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[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o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)h(e[ll]+o)"};
3+
static constexpr inline auto pattern = ctll::basic_fixed_string{"(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((x)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))"};
44

5-
static constexpr inline auto a = ctll::parser<ctre::pcre, pattern>::trampoline_decide();
5+
static constexpr inline auto a = ctre::re<pattern>();
66

77
template <typename T> void identify(T) { }
88

0 commit comments

Comments
 (0)