@@ -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
0 commit comments