-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestParser.hpp
125 lines (110 loc) · 3.66 KB
/
TestParser.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <Warp/Common.hpp>
#include <Warp/Utilities.hpp>
#ifndef WARP__TESTING__HEADER__TESTING__TEST__PARSER__HPP
#define WARP__TESTING__HEADER__TESTING__TEST__PARSER__HPP
namespace Warp::Testing
{
using namespace Warp::Utilities;
template<typename ParserParameterType>
struct TestingParser
{
using ParserType = ParserParameterType;
template<auto ReduceToTagParameterConstant>
constexpr const static auto parser = ctpg::parser(
ParserType::template term<ReduceToTagParameterConstant>,
ParserType::terms,
ParserType::non_terminal_terms,
ParserType::rules()
);
template<typename ReduceToParameterType>
constexpr const static auto typed_parser = ctpg::parser(
ParserType::template term<ReduceToParameterType>,
ParserType::terms,
ParserType::non_terminal_terms,
ParserType::rules()
);
};
template<typename ParserParameterType, auto ReduceToTagParameterConstant>
constexpr static const auto parser
= TestingParser<ParserParameterType>::template parser<ReduceToTagParameterConstant>;
template<typename ParserParameterType, typename ReduceToParameterType>
constexpr static const auto typed_parser
= TestingParser<ParserParameterType>::template typed_parser<ReduceToParameterType>;
template<
typename ParserParameterType,
FixedString StringParameterConstant,
auto ReduceToTagParameterConstant
> consteval auto parse() {
return parser<ParserParameterType, ReduceToTagParameterConstant>.parse(
ctpg::buffers::cstring_buffer(StringParameterConstant.string),
std::cerr
);
}
template<
typename ParserParameterType,
FixedString StringParameterConstant,
typename ReduceToParameterType
>
consteval auto typed_parse()
{
return parser<ParserParameterType, ReduceToParameterType>.parse(
ctpg::buffers::cstring_buffer(StringParameterConstant.string),
std::cerr
);
}
template<
typename ParserParameterType,
FixedString StringParameterConstant,
auto ReduceToTagParameterConstant
>
constexpr auto runtime_parse(bool debug = false)
{
return parser<ParserParameterType, ReduceToTagParameterConstant>.parse(
((debug == true) ? ctpg::parse_options{}.set_verbose() : ctpg::parse_options{}),
ctpg::buffers::string_buffer(StringParameterConstant.string),
std::cerr
);
}
template<
typename ParserParameterType,
FixedString StringParameterConstant,
auto ReduceToTagParameterConstant
>
constexpr auto runtime_parse(auto& context, bool debug = false)
{
return parser<ParserParameterType, ReduceToTagParameterConstant>.context_parse(
context,
((debug == true) ? ctpg::parse_options{}.set_verbose() : ctpg::parse_options{}),
ctpg::buffers::string_buffer(StringParameterConstant.string),
std::cerr
);
}
template<
typename ParserParameterType,
FixedString StringParameterConstant,
typename ReduceToParameterType
>
constexpr auto typed_runtime_parse(bool debug = false)
{
return typed_parser<ParserParameterType, ReduceToParameterType>.parse(
((debug == true) ? ctpg::parse_options{}.set_verbose() : ctpg::parse_options{}),
ctpg::buffers::string_buffer(StringParameterConstant.string),
std::cerr
);
}
template<
typename ParserParameterType,
FixedString StringParameterConstant,
typename ReduceToParameterType
>
constexpr auto typed_runtime_parse(auto& context, bool debug = false)
{
return typed_parser<ParserParameterType, ReduceToParameterType>.parse(
context,
((debug == true) ? ctpg::parse_options{}.set_verbose() : ctpg::parse_options{}),
ctpg::buffers::string_buffer(StringParameterConstant.string),
std::cerr
);
}
}
#endif // WARP__TESTING__HEADER__TESTING__TEST__PARSER__HPP