@@ -15,6 +15,10 @@ enum class decision {
1515 undecided
1616};
1717
18+ template <typename T> void id (T);
19+
20+ struct placeholder { };
21+
1822#if !__cpp_nontype_template_parameter_class
1923template <typename Grammar, const auto & input, typename ActionSelector = empty_actions, bool IgnoreUnknownActions = false > struct parser {
2024#else
@@ -25,8 +29,6 @@ template <typename Grammar, basic_fixed_string input, typename ActionSelector =
2529
2630 template <size_t Pos, typename Stack = void , typename Subject = void , decision Decision = decision::undecided> struct seed ;
2731
28- template <size_t Pos> struct placeholder { };
29-
3032 template <size_t Pos> static constexpr auto get_current_term () noexcept {
3133 if constexpr (Pos < input.size ()) {
3234 return term<input[Pos]>{};
@@ -107,6 +109,7 @@ template <typename Grammar, basic_fixed_string input, typename ActionSelector =
107109 }
108110 }
109111 // helper type for trampoline
112+
110113 template <size_t Pos, typename Stack, typename Subject, decision Decision> struct seed {
111114 constexpr inline CTLL_FORCE_INLINE operator bool () const noexcept {
112115 return Decision == decision::accept;
@@ -119,22 +122,26 @@ template <typename Grammar, basic_fixed_string input, typename ActionSelector =
119122 return decide<Pos>(Stack{}, Subject{});
120123 }
121124
122- template < size_t RPos> constexpr auto operator +(placeholder<RPos> ) const noexcept {
125+ constexpr auto operator +(placeholder) const noexcept {
123126 if constexpr (Decision == decision::undecided) {
124127 // parse for current char (RPos) with previous stack and subject :)
125- return decltype (seed<RPos , Stack, Subject, Decision>::parse ()){};
128+ return decltype (seed<Pos , Stack, Subject, Decision>::parse ()){};
126129 } else {
127130 // if there is decision already => just push it to the end of fold expression
128131 return *this ;
129132 }
130133 }
131134 };
132135
136+ template <size_t > using index_placeholder = placeholder;
137+
133138 // trampolines with folded expression
134139 template <typename Subject, size_t ... Pos> static constexpr auto trampoline_decide (Subject, std::index_sequence<Pos...>) noexcept {
135140 // parse everything for first char and than for next and next ...
136141 // Pos+1 is needed as we want to finish calculation with epsilons on stack
137- return (seed<0 , decltype (grammar.start_stack ), Subject, decision::undecided>::parse () + ... + placeholder<Pos+1 >());
142+ auto v = (seed<0 , decltype (grammar.start_stack ), Subject, decision::undecided>::parse () + ... + index_placeholder<Pos+1 >());
143+ // id(v);
144+ return v;
138145 }
139146
140147 template <typename Subject = empty_subject> static constexpr auto trampoline_decide (Subject subject = {}) noexcept {
0 commit comments