1
- // Copyright (C) 2020-2022 Jonathan Müller and lexy contributors
1
+ // Copyright (C) 2020-2023 Jonathan Müller and lexy contributors
2
2
// SPDX-License-Identifier: BSL-1.0
3
3
4
4
#ifndef LEXY_ACTION_VALIDATE_HPP_INCLUDED
@@ -180,34 +180,45 @@ class _vh
180
180
public:
181
181
constexpr event_handler (production_info info) : _begin(), _info(info) {}
182
182
183
- constexpr void on (_vh&, parse_events::production_start, iterator pos)
183
+ constexpr void on (_vh& handler , parse_events::production_start, iterator pos)
184
184
{
185
185
_begin = pos;
186
+
187
+ _prev = handler._top ;
188
+ handler._top = this ;
189
+ }
190
+ constexpr void on (_vh& handler, parse_events::production_finish, iterator)
191
+ {
192
+ handler._top = _prev;
193
+ }
194
+ constexpr void on (_vh& handler, parse_events::production_cancel, iterator)
195
+ {
196
+ handler._top = _prev;
186
197
}
187
198
188
199
template <typename Tag>
189
200
constexpr void on (_vh& handler, parse_events::error, const error<Reader, Tag>& error)
190
201
{
191
- handler._cb .generic (handler._cb .sink , _info , handler._cb .input , _begin, error);
202
+ handler._cb .generic (handler._cb .sink , get_info () , handler._cb .input , _begin, error);
192
203
}
193
204
constexpr void on (_vh& handler, parse_events::error, const error<Reader, void >& error)
194
205
{
195
- handler._cb .generic (handler._cb .sink , _info , handler._cb .input , _begin, error);
206
+ handler._cb .generic (handler._cb .sink , get_info () , handler._cb .input , _begin, error);
196
207
}
197
208
constexpr void on (_vh& handler, parse_events::error,
198
209
const error<Reader, expected_literal>& error)
199
210
{
200
- handler._cb .literal (handler._cb .sink , _info , handler._cb .input , _begin, error);
211
+ handler._cb .literal (handler._cb .sink , get_info () , handler._cb .input , _begin, error);
201
212
}
202
213
constexpr void on (_vh& handler, parse_events::error,
203
214
const error<Reader, expected_keyword>& error)
204
215
{
205
- handler._cb .keyword (handler._cb .sink , _info , handler._cb .input , _begin, error);
216
+ handler._cb .keyword (handler._cb .sink , get_info () , handler._cb .input , _begin, error);
206
217
}
207
218
constexpr void on (_vh& handler, parse_events::error,
208
219
const error<Reader, expected_char_class>& error)
209
220
{
210
- handler._cb .char_class (handler._cb .sink , _info , handler._cb .input , _begin, error);
221
+ handler._cb .char_class (handler._cb .sink , get_info () , handler._cb .input , _begin, error);
211
222
}
212
223
213
224
template <typename Event, typename ... Args>
@@ -223,12 +234,16 @@ class _vh
223
234
224
235
constexpr production_info get_info () const
225
236
{
226
- return _info;
237
+ auto cur = this ;
238
+ while (cur->_info .is_transparent && cur->_prev != nullptr )
239
+ cur = cur->_prev ;
240
+ return cur->_info ;
227
241
}
228
242
229
243
private:
230
244
iterator _begin;
231
245
production_info _info;
246
+ event_handler* _prev = nullptr ;
232
247
};
233
248
234
249
template <typename Production, typename State>
@@ -243,6 +258,7 @@ class _vh
243
258
244
259
private:
245
260
_validate_callbacks<Reader> _cb;
261
+ event_handler* _top = nullptr ;
246
262
};
247
263
248
264
template <typename State, typename Input, typename ErrorCallback>
0 commit comments