codex
Loading...
Searching...
No Matches
gen.hpp
Go to the documentation of this file.
1#ifndef CODEX_LUA_GEN_H
2#define CODEX_LUA_GEN_H
3
4#include "lua.hpp"
5#include "utils.hpp"
6
8struct number_base {};
9struct string_base {};
10
11template<fixed_string_view s>
13
14template<fixed_string_view s>
15struct number : number_base, constant<s> {};
16
17template<fixed_string_view s>
18struct string : string_base, constant<s> {};
19
20struct table_begin {};
21struct table_key {};
22struct table_value {};
23struct table_end {};
24
25template<auto parser_, std::size_t pos_ = 0, typename Output = types<>>
26struct generator {
27 struct type {
28 using output = Output;
29 static constexpr auto parser = parser_;
30 static constexpr auto pos = pos_;
31 };
32};
33
34template<auto parser, std::size_t pos, typename Output>
35requires(pos < MAX)
37 template<typename T>
38 static constexpr auto push(void)
40 static constexpr auto next(void) {
41 constexpr auto i = parser.output.v[pos];
42 constexpr std::string_view input = parser.input;
43 constexpr auto name = i.name(input);
44 constexpr auto name_ = fixed_string_view<
46 static_cast<std::size_t>(std::distance(begin(input), begin(name))),
47 static_cast<std::size_t>(std::distance(begin(input), end(name)))>{};
48 if constexpr(i.n == node::identifier)
49 return decltype(generator::push<identifier<name_>>()){};
50 else if constexpr(i.n == node::number)
51 return decltype(generator::push<number<name_>>()){};
52 else if constexpr(i.n == node::string)
53 return decltype(generator::push<string<name_>>()){};
54 else if constexpr(i.n == node::table_begin)
55 return decltype(generator::push<table_begin>()){};
56 else if constexpr(i.n == node::table_key)
57 return decltype(generator::push<table_key>()){};
58 else if constexpr(i.n == node::table_value)
59 return decltype(generator::push<table_value>()){};
60 else if constexpr(i.n == node::table_end)
61 return decltype(generator::push<table_end>()){};
62 else
64 }
65 using type = decltype(generator::next())::type;
66};
67
68#endif
Definition utils.hpp:62
Definition gen.hpp:27
static constexpr auto pos
Definition gen.hpp:30
Output output
Definition gen.hpp:28
static constexpr auto next(void)
Definition gen.hpp:40
decltype(generator::next())::type type
Definition gen.hpp:65
static constexpr auto push(void) -> generator< parser, pos+1, typename Output::push_back< T > >
Definition gen.hpp:26
Definition gen.hpp:7
Definition gen.hpp:12
Definition gen.hpp:8
Definition gen.hpp:15
std::array< state::item, MAX > v
Definition parser.hpp:144
Definition parser.hpp:140
struct parser::output output
static constexpr auto input
Definition parser.hpp:141
Definition gen.hpp:9
Definition gen.hpp:18
Definition gen.hpp:20
Definition gen.hpp:23
Definition gen.hpp:21
Definition gen.hpp:22
#define MAX(x, y)
Definition table.c:8
std::integral_constant< decltype(x), x > constant
Definition utils.hpp:72