14 struct AlternationParserMarker {};
16 template<
typename... Parsers>
17 class AlternationParser
18 :
public ParserBase<AlternationParser<Parsers...>>
19 ,
public AlternationParserMarker {
21 template<
typename... Ps>
22 constexpr explicit AlternationParser(InPlace, Ps&&... parsers) : m_parsers(util::forward<Ps>(parsers)...) {}
24 template<concepts::ParserContext Context>
25 requires(concepts::Parser<Parsers, Context> && ...)
26 constexpr auto parse(Context& context)
const {
27 constexpr bool should_be_void = (concepts::LanguageVoid<meta::ParserValue<Context, Parsers>> && ...);
31 Variant<meta::Conditional<concepts::LanguageVoid<meta::ParserValue<Context, Parsers>>,
36 if constexpr (index >=
sizeof...(Parsers)) {
45 if constexpr (should_be_void) {
47 }
else if constexpr (concepts::LanguageVoid<Value>) {
58 Tuple<Parsers...> m_parsers;
61 struct AlternationFunction {
62 template<concepts::DecayConstructible... Parsers>
63 constexpr auto operator()(Parsers&&... parsers)
const {
64 return AlternationParser<meta::Decay<Parsers>...>(
in_place, util::forward<Parsers>(parsers)...);
69constexpr inline auto alternation = detail::AlternationFunction {};
71template<concepts::DecayConstructible Left, concepts::DecayConstructible Right>
73constexpr auto operator|(Left&& left, Right&& right) {
74 return alternation(util::forward<Left>(left), util::forward<Right>(right));
77template<concepts::DecayConstructible Left, concepts::DecayConstructible Right>
81constexpr auto operator|(Left&& left, Right&& right) {
83 [&]<
typename... Rs>(Rs&&... rs) {
84 return alternation(util::forward<Left>(left), util::forward<Rs>(rs)...);
86 util::forward<Right>(right).m_parsers);
89template<concepts::DecayConstructible Left, concepts::DecayConstructible Right>
93constexpr auto operator|(Left&& left, Right&& right) {
95 [&]<
typename... Ls>(Ls&&... ls) {
96 return alternation(util::forward<Ls>(ls)..., util::forward<Right>(right));
98 util::forward<Left>(left).m_parsers);
101template<concepts::DecayConstructible Left, concepts::DecayConstructible Right>
105constexpr auto operator|(Left&& left, Right&& right) {
107 [&]<
typename... Ls>(Ls&&... ls) {
109 [&]<
typename... Rs>(Rs&&... rs) {
110 return alternation(util::forward<Ls>(ls)..., util::forward<Rs>(rs)...);
112 util::forward<Right>(right).m_parsers);
114 util::forward<Left>(left).m_parsers);
Definition operations.h:114
constexpr auto ycombinator
Definition ycombinator.h:63
constexpr auto value
Definition value.h:34
Definition code_point_parser.h:10
constexpr auto alternation
Definition alternation.h:69
constexpr auto parse
Definition parse.h:23
constexpr auto get(T &&value) -> decltype(auto)
Definition get.h:8
auto declval() -> meta::AddRValueReference< T >
Definition declval.h:8
constexpr auto apply(F &&f, Tup &&tuple) -> decltype(detail::apply_impl(meta::MakeIndexSequence< meta::TupleSize< Tup > > {}, util::forward< F >(f), util::forward< Tup >(tuple)))
Definition apply.h:22
Expected< T, Error > Result
Definition result.h:8
Tuple(Types...) -> Tuple< Types... >
Unexpected(E &&) -> Unexpected< meta::UnwrapRefDecay< E > >
constexpr auto c_
A value of type Constexpr<val>.
Definition constexpr.h:252
constexpr auto in_place
Definition in_place.h:8