Iros
 
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
40 template<concepts::Predicate<c32> Pred>
42 constexpr auto operator()(Pred&& predicate) const {
43 return MatchZeroOrMoreParser<meta::Decay<Pred>> { in_place, util::forward<Pred>(predicate) };
44 }
45 };
46}
47
49}
Definition parser_base.h:5
Definition match_zero_or_more.h:15
constexpr auto parse(Context &context) const -> meta::ParserContextResult< meta::Reconstructed< Context, meta::ContainerIterator< Context >, meta::ContainerIterator< Context > >, Context >
Definition match_zero_or_more.h:21
constexpr MatchZeroOrMoreParser(InPlace, P &&predicate)
Definition match_zero_or_more.h:18
constexpr auto reconstruct
Definition reconstruct.h:75
constexpr auto end
Definition end.h:47
constexpr auto begin
Definition begin.h:44
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 zstring_parser.h:10
Definition zstring_parser.h:9
constexpr auto match_zero_or_more
Definition match_zero_or_more.h:48
Definition vocab.h:96
constexpr auto in_place_type
Definition in_place_type.h:12
constexpr auto in_place
Definition in_place.h:8
Definition match_zero_or_more.h:39
Definition in_place.h:4