Iros
 
Loading...
Searching...
No Matches
match_exactly.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 MatchExactly : public ParserBase<MatchExactly<Pred>> {
16 public:
17 template<typename P>
18 constexpr explicit MatchExactly(InPlace, P&& predicate, usize count)
19 : m_predicate(util::forward<P>(predicate)), m_count(count) {}
20
21 template<concepts::ParserContext Context>
22 constexpr auto parse(Context& context) const -> meta::ParserContextResult<
24 auto start = container::begin(context);
25 auto sent = container::end(context);
26
27 auto remaining = m_count;
28 auto it = start;
29 while (it != sent && m_predicate(*it) && remaining > 0) {
30 ++it;
31 --remaining;
32 }
33
34 if (remaining > 0) {
35 return Unexpected(context.make_error());
36 }
37
38 context.advance(it);
40 }
41
42 private:
43 Pred m_predicate;
44 usize m_count { 0 };
45 };
46
48 template<concepts::Predicate<c32> Pred>
50 constexpr auto operator()(Pred&& predicate, usize count) const {
51 return MatchExactly<meta::Decay<Pred>> { in_place, util::forward<Pred>(predicate), count };
52 }
53 };
54}
55
57}
Definition parser_base.h:5
Definition match_exactly.h:15
constexpr auto parse(Context &context) const -> meta::ParserContextResult< meta::Reconstructed< Context, meta::ContainerIterator< Context >, meta::ContainerIterator< Context > >, Context >
Definition match_exactly.h:22
constexpr MatchExactly(InPlace, P &&predicate, usize count)
Definition match_exactly.h:18
Definition unexpected.h:14
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_exactly
Definition match_exactly.h:56
size_t usize
Definition integers.h:33
Definition vocab.h:96
constexpr auto in_place_type
Definition in_place_type.h:12
constexpr auto in_place
Definition in_place.h:8
constexpr auto count
Definition count.h:37
Definition match_exactly.h:47
Definition in_place.h:4