4 #ifndef LEXY_DSL_LIST_HPP_INCLUDED
5 #define LEXY_DSL_LIST_HPP_INCLUDED
14 template <
typename Item,
typename Sep>
17 template <
typename Context,
typename Reader,
typename Sink>
23 [[maybe_unused]]
auto sep_begin = reader.position();
24 if constexpr (!std::is_void_v<Sep>)
27 if (!
sep.try_parse(context.control_block, reader))
34 if (!
sep.template finish<lexy::sink_parser>(context, reader, sink))
37 [[maybe_unused]]
auto sep_end = reader.position();
40 if constexpr (lexy::is_branch_rule<Item>)
44 if (!item.try_parse(context.control_block, reader))
49 if constexpr (!std::is_void_v<Sep>)
50 Sep::report_trailing_error(context, reader, sep_begin, sep_end);
55 if (!item.template finish<lexy::sink_parser>(context, reader, sink))
69 template <
typename NextParser>
72 template <
typename Context,
typename Reader,
typename... Args>
76 auto sink = context.value_callback().sink();
83 if (!
_loop(context, reader, sink))
92 template <
typename Reader>
97 template <
typename ControlBlock>
98 constexpr
bool try_parse(
const ControlBlock* cb,
const Reader& reader)
101 return item.try_parse(cb, reader);
104 template <
typename Context>
107 return item.cancel(context);
110 template <
typename NextParser,
typename Context,
typename... Args>
114 auto sink = context.value_callback().sink();
117 if (!
item.template finish<lexy::sink_parser>(context, reader, sink))
121 if (!
_loop(context, reader, sink))
132 template <
typename Item>
140 template <
typename Item,
typename Sep,
typename Tag>
147 template <
typename Item,
typename Sep>
154 template <
typename Item,
typename Sep>
157 static_assert(lexy::_detail::error<Item, Sep>,
158 "list() does not support `dsl::ignore_trailing_sep()`");
165 template <
typename Term,
typename Item,
typename Sep,
typename Recover>
185 template <
typename TermParser,
typename Context,
typename Reader,
typename Sink>
187 Reader& reader, Sink& sink)
189 auto state = initial_state;
191 [[maybe_unused]]
auto sep_pos = reader.position();
197 if (term.try_parse(context.control_block, reader))
200 term.cancel(context);
207 if constexpr (!std::is_void_v<Sep>)
209 sep_pos = reader.position();
218 else if (sep_pos == reader.position())
223 if constexpr (lexy::is_branch_rule<Item>)
226 if (item.try_parse(context.control_block, reader)
227 && item.template finish<lexy::sink_parser>(context, reader, sink))
236 item.cancel(context);
268 if constexpr (!std::is_void_v<Sep>)
272 if (term.try_parse(context.control_block, reader))
276 Sep::report_trailing_error(context, reader, sep_pos, reader.position());
303 auto recovery_begin = reader.position();
308 if constexpr (!std::is_void_v<Sep>)
310 sep_pos = reader.position();
313 if (
sep.try_parse(context.control_block, reader))
315 auto recovery_end = reader.position();
320 if (
sep.template finish<lexy::sink_parser>(context, reader, sink))
344 else if constexpr (lexy::is_branch_rule<Item>)
347 if (item.try_parse(context.control_block, reader))
349 auto recovery_end = reader.position();
354 if (item.template finish<lexy::sink_parser>(context, reader, sink))
369 item.cancel(context);
375 if (term.try_parse(context.control_block, reader))
378 auto recovery_end = reader.position();
386 term.cancel(context);
391 using limit_rule = decltype(Recover{}.get_limit());
396 auto recovery_end = reader.position();
414 template <
typename NextParser>
417 template <
typename Context,
typename Reader,
typename... Args>
421 auto sink = context.value_callback().sink();
432 if constexpr (std::is_same_v<
typename decltype(sink)::return_type,
void>)
435 return term.template finish<NextParser>(context, reader,
LEXY_FWD(args)...);
439 return term.template finish<NextParser>(context, reader,
LEXY_FWD(args)...,
447 #endif // LEXY_DSL_LIST_HPP_INCLUDED