4 #ifndef LEXY_DSL_CHOICE_HPP_INCLUDED
5 #define LEXY_DSL_CHOICE_HPP_INCLUDED
17 return "exhausted choice";
24 template <
typename... R>
29 : std::conditional_t<(lexy::is_unconditional_branch_rule<R> || ...), rule_base, branch_base>
35 template <
typename Reader, std::size_t... Idx>
38 template <
typename Rule>
44 template <
typename ControlBlock>
45 constexpr
auto try_parse(
const ControlBlock* cb,
const Reader& reader)
46 -> std::conditional_t<_any_unconditional, std::true_type, bool>
48 auto try_r = [&](std::size_t idx,
auto& parser) {
49 if (!parser.try_parse(cb, reader))
57 auto found_branch = (try_r(Idx, r_parsers.template get<Idx>()) || ...);
61 "it is unconditional, but we still haven't found a rule?!");
70 template <
typename Context>
71 constexpr
void cancel(Context& context)
74 (r_parsers.template get<Idx>().cancel(context), ...);
77 template <
typename NextParser,
typename Context,
typename... Args>
82 (
void)((Idx == branch_idx
84 = r_parsers.template get<Idx>()
85 .template finish<NextParser>(context, reader,
LEXY_FWD(args)...),
87 : (r_parsers.template get<Idx>().cancel(context),
false))
93 template <
typename NextParser>
96 template <
typename Context,
typename Reader,
typename... Args>
100 auto try_r = [&](
auto&& parser) {
101 if (!parser.try_parse(context.control_block, reader))
103 parser.cancel(context);
108 result = parser.template finish<NextParser>(context, reader,
109 static_cast<Args&&
>(args)...);
118 "it is unconditional, but we still haven't found a rule?!");
134 template <
typename R,
typename S>
137 static_assert(lexy::is_branch_rule<R>,
"choice requires a branch condition");
138 static_assert(lexy::is_branch_rule<S>,
"choice requires a branch condition");
141 template <
typename... R,
typename S>
144 static_assert(lexy::is_branch_rule<S>,
"choice requires a branch condition");
145 return _chc<R..., S>{};
147 template <
typename R,
typename... S>
150 static_assert(lexy::is_branch_rule<R>,
"choice requires a branch condition");
151 return _chc<R, S...>{};
153 template <
typename... R,
typename... S>
156 return _chc<R..., S...>{};
160 #endif // LEXY_DSL_CHOICE_HPP_INCLUDED