di 0.1.0
Loading...
Searching...
No Matches
match_zero_or_more.h
Go to the documentation of this file.
1#pragma once
2
5#include "di/meta/relation.h"
11
12namespace di::parser {
13namespace detail {
14 template<concepts::Predicate<c32> Pred>
15 class MatchZeroOrMoreParser : public ParserBase<MatchZeroOrMoreParser<Pred>> {
16 public:
17 template<typename P>
18 constexpr explicit MatchZeroOrMoreParser(InPlace, P&& predicate) : m_predicate(util::forward<P>(predicate)) {}
19
20 template<concepts::ParserContext Context>
21 constexpr auto parse(Context& context) const -> meta::ParserContextResult<
23 auto start = container::begin(context);
24 auto sent = container::end(context);
25
26 auto it = start;
27 while (it != sent && m_predicate(*it)) {
28 ++it;
29 }
30
31 context.advance(it);
33 }
34
35 private:
36 Pred m_predicate;
37 };
38
39 struct MatchZeroOrMoreFunction {
40 template<concepts::Predicate<c32> Pred>
41 requires(concepts::DecayConstructible<Pred>)
42 constexpr auto operator()(Pred&& predicate) const {
43 return MatchZeroOrMoreParser<meta::Decay<Pred>> { in_place, util::forward<Pred>(predicate) };
44 }
45 };
46}
47
48constexpr inline auto match_zero_or_more = detail::MatchZeroOrMoreFunction {};
49}
constexpr auto reconstruct
Definition reconstruct.h:75
constexpr auto end
Definition end.h:55
constexpr auto begin
Definition begin.h:52
constexpr auto start
Definition start.h:20
decltype(container::reconstruct(in_place_type< T >, util::declval< It >(), util::declval< Sent >())) Reconstructed
Definition reconstructed.h:11
vocab::Expected< T, meta::ParserContextError< Context > > ParserContextResult
Definition parser_context_result.h:8
decltype(container::begin(util::declval< T & >())) ContainerIterator
Definition container_iterator.h:8
Definition code_point_parser.h:10
constexpr auto match_zero_or_more
Definition match_zero_or_more.h:48
constexpr auto parse
Definition parse.h:23
constexpr auto in_place_type
Definition in_place_type.h:12
constexpr auto in_place
Definition in_place.h:8