/
parser_special_node.hpp
64 lines (50 loc) · 1.4 KB
/
parser_special_node.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
#pragma once
#include "include.hpp"
namespace myparser {
using ErrorId = MP_STR("Illegal identifier");
using ErrorLiteral = MP_STR("Illegal literal");
template <class E>
class NodeId: public NodeTextOrError<E> {
private:
/* const */ bool succeed;
public:
inline NodeId(
const Input &input, const Input &end
): NodeTextOrError<E>(input, end) {
static const std::set<std::string> keywords = {
"div", "mod", "shl", "shr", "ushr", "rol", "ror",
"or", "xor", "and", "not", "is", "in", "out", "var"
};
succeed = keywords.find(std::string(input, end)) == keywords.cend();
}
// virtual ~NodeId() {}
virtual bool accepted() const {
return succeed;
}
};
// specialization
template <>
class NodeBaseText<MP_STR("id")> {
public:
template <class TX = void> // actually not a template
using Type = NodeId<ErrorId>;
};
template <>
class NodeBaseText<MP_STR("int")> {
public:
template <class TX = void> // actually not a template
using Type = NodeData<lb_int_t, ErrorLiteral>;
};
template <>
class NodeBaseText<MP_STR("real")> {
public:
template <class TX = void> // actually not a template
using Type = NodeData<lb_real_t, ErrorLiteral>;
};
template <>
class NodeBaseText<MP_STR("str")> {
public:
template <class TX = void> // actually not a template
using Type = NodeString<1, 1, '\\', ErrorLiteral>;
};
}