Go to the documentation of this file.
4 #ifndef LEXY_DSL_RECOVER_HPP_INCLUDED
5 #define LEXY_DSL_RECOVER_HPP_INCLUDED
19 template <
typename Rule>
22 template <
typename NextParser>
27 template <
typename Context,
typename Reader,
typename... Args>
29 bool& recovery_finished, Args&&... args)
31 recovery_finished =
true;
37 template <
typename Context,
typename Reader,
typename... Args>
41 auto recovery_finished =
false;
47 if (!recovery_finished)
56 template <
typename NextParser>
63 template <
typename Token,
typename Limit>
66 template <
typename NextParser>
69 template <
typename Context,
typename Reader,
typename... Args>
74 constexpr
const auto& trie
78 auto begin = reader.position();
82 auto end = reader.current();
83 auto result = matcher::try_match(reader);
111 template <
typename... Literals>
114 static_assert(
sizeof...(Literals) > 0);
117 return _find<Token, decltype(l)>{};
122 if constexpr (std::is_void_v<Limit>)
130 template <
typename... Literals>
133 static_assert(
sizeof...(Literals) > 0);
136 return _find<decltype(needle),
void>{};
142 template <
typename Limit,
typename... R>
145 template <
typename NextParser>
148 template <
typename Context,
typename Reader,
typename... Args>
151 auto begin = reader.position();
156 while (!recovery.try_parse(context.control_block, reader))
158 recovery.cancel(context);
164 auto end = reader.position();
176 auto end = reader.position();
181 return recovery.template finish<NextParser>(context, reader,
LEXY_FWD(args)...);
187 template <
typename... Literals>
190 static_assert(
sizeof...(Literals) > 0);
193 return _reco<decltype(l), R...>{};
198 if constexpr (std::is_void_v<Limit>)
206 template <
typename... Branches>
209 static_assert(
sizeof...(Branches) > 0);
217 template <
typename Terminator,
typename Rule,
typename Recover>
220 template <
typename NextParser>
223 template <
typename Context,
typename Reader,
typename... Args>
225 bool& continuation_reached, Args&&... args)
227 continuation_reached =
true;
230 if constexpr (std::is_void_v<Terminator>)
237 template <
typename Context,
typename Reader,
typename... Args>
240 if constexpr (std::is_void_v<Recover>)
246 else if constexpr (std::is_base_of_v<_recovery_base, Recover>)
248 using recovery_rule = Recover;
261 template <
typename NextParser>
264 template <
typename Context,
typename Reader,
typename... Args>
270 auto continuation_reached =
false;
272 if (continuation_reached)
277 LEXY_ASSERT(!result,
"we've failed without reaching the continuation?!");
283 template <
typename Rule,
typename Recover>
288 template <
typename Reader>
293 template <
typename ControlBlock>
294 constexpr
auto try_parse(
const ControlBlock* cb,
const Reader& reader)
296 return rule.try_parse(cb, reader);
299 template <
typename Context>
302 rule.cancel(context);
305 template <
typename NextParser,
typename Context,
typename... Args>
309 using continuation =
typename impl::template _pc<NextParser>;
310 auto continuation_reached =
false;
311 auto result =
rule.template finish<continuation>(context, reader, continuation_reached,
313 if (continuation_reached)
318 LEXY_ASSERT(!result,
"we've failed without reaching the continuation?!");
323 template <
typename NextParser>
329 template <
typename Rule>
336 template <
typename Rule,
typename Recover>
337 constexpr
auto try_(Rule, Recover)
343 #endif // LEXY_DSL_RECOVER_HPP_INCLUDED
constexpr auto try_parse(const ControlBlock *cb, const Reader &reader)
typename BranchRule::template bp< Reader > branch_parser_for
constexpr auto recover(Branches...)
Discards input until one of the branches matches to recover from an error.
static constexpr auto get_limit()
constexpr auto end(const C &c) -> decltype(c.end())
#define LEXY_REQUIRE_BRANCH_RULE(Rule, Name)
static constexpr auto _look_trie
constexpr auto try_(Rule)
Parses Rule, if that fails, continues immediately.
static LEXY_PARSER_FUNC bool recover(Context &context, Reader &reader, Args &&... args)
constexpr auto parse(const Input &input, const ErrorCallback &callback)
Parses the production into a value, invoking the callback on error.
static constexpr auto get_limit()
static LEXY_PARSER_FUNC bool parse(Context &context, Reader &reader, bool &continuation_reached, Args &&... args)
static LEXY_PARSER_FUNC bool parse(Context &context, Reader &reader, bool &recovery_finished, Args &&... args)
constexpr void cancel(Context &context)
static LEXY_PARSER_FUNC bool parse(Context &context, Reader &reader, Args &&... args)
constexpr auto limit(Literals... literals) const
Fail error recovery if limiting literal tokens is found first.
static LEXY_PARSER_FUNC bool parse(Context &context, Reader &reader, Args &&... args)
lexy::branch_parser_for< Rule, Reader > rule
constexpr auto begin(const C &c) -> decltype(c.begin())
constexpr auto limit(Literals... literals) const
Fail error recovery if limiting literal tokens is found first.
static LEXY_PARSER_FUNC bool parse(Context &context, Reader &reader, Args &&... args)
typename Rule::template p< NextParser > parser_for
constexpr auto literal_set(Literals...)
Matches one of the specified literals.
LEXY_PARSER_FUNC bool finish(Context &context, Reader &reader, Args &&... args)
static LEXY_PARSER_FUNC bool parse(Context &context, Reader &reader, Args &&... args)
typename TokenRule::template tp< Reader > token_parser_for
constexpr auto eof
Matches EOF.
#define LEXY_ASSERT(Expr, Msg)
constexpr auto find(Literals... literals)
Recovers once it finds one of the given literal tokens (without consuming them).
decltype(_copy_base_impl< Rule >()) _copy_base