di 0.1.0
Loading...
Searching...
No Matches
parse_impl.h
Go to the documentation of this file.
1#pragma once
2
4#include "di/meta/core.h"
7#include "di/parser/prelude.h"
12
13namespace di::parser::detail {
14template<concepts::SameAs<types::Tag<parser::create_parser_in_place>> Tag = types::Tag<parser::create_parser_in_place>,
15 concepts::ReflectableToEnumerators T>
16constexpr auto tag_invoke(Tag, InPlaceType<T>) {
17 auto valid_code_point = [](c32 code_point) {
18 constexpr auto valid_char_table = [] {
19 auto table = vocab::Array<bool, 256> {};
21 [&](auto enumerator) {
22 for (auto ch : enumerator.name) {
23 table[ch] = true;
24 }
25 if constexpr (concepts::BitwiseEnum<T>) {
26 table['|'] = true;
27 }
28 },
30 return table;
31 }();
32
33 return code_point < 256 && valid_char_table[code_point];
34 };
35
36 return parser::match_one_or_more(valid_code_point) <<
37 []<typename Context>(Context& context,
38 concepts::CopyConstructible auto results) -> meta::ParserContextResult<T, Context> {
39 if constexpr (!concepts::BitwiseEnum<T>) {
40 auto result = vocab::Optional<T> {};
42 [&](auto enumerator) {
43 if (container::equal(results, enumerator.name)) {
44 result = enumerator.value;
45 }
46 },
48
49 if (!result) {
51 }
52 return *result;
53 } else {
54 auto result = T(0);
55 for (auto substring : split(results, U'|')) {
56 auto found = false;
58 [&](auto enumerator) {
59 if (container::equal(substring, enumerator.name)) {
60 result |= enumerator.value;
61 found = true;
62 }
63 },
65 if (!found) {
67 }
68 }
69 return result;
70 }
71 };
72}
73}
constexpr auto split
Definition split.h:35
constexpr auto equal
Definition equal.h:46
vocab::Expected< T, meta::ParserContextError< Context > > ParserContextResult
Definition parser_context_result.h:8
constexpr auto code_point
Definition code_point_parser.h:35
constexpr auto make_error
Definition make_error.h:19
constexpr auto match_one_or_more
Definition match_one_or_more.h:32
constexpr auto reflect
Definition reflect.h:47
char32_t c32
Definition char.h:6
di::meta::Decay< decltype(T)> Tag
Definition tag_invoke.h:28
Array(T, U...) -> Array< T, 1+sizeof...(U)>
constexpr void tuple_for_each(F &&function, Tup &&tuple)
Definition tuple_for_each.h:22
Unexpected(E &&) -> Unexpected< meta::UnwrapRefDecay< E > >
constexpr tag_invoke_detail::TagInvokeFn tag_invoke
Definition tag_invoke.h:22
constexpr auto enumerator
Definition enumerator.h:40
constexpr auto in_place_type
Definition in_place_type.h:12