-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparsegen_regex.hpp
116 lines (94 loc) · 2.5 KB
/
parsegen_regex.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
#ifndef PARSEGEN_REGEX_HPP
#define PARSEGEN_REGEX_HPP
#include "parsegen_finite_automaton.hpp"
#include "parsegen_language.hpp"
#include "parsegen_parser.hpp"
#include "parsegen_parser_tables.hpp"
namespace parsegen {
namespace regex {
enum {
PROD_REGEX,
PROD_UNION_DECAY,
PROD_UNION,
PROD_CONCAT_DECAY,
PROD_CONCAT,
PROD_QUAL_DECAY,
PROD_STAR,
PROD_PLUS,
PROD_MAYBE,
PROD_SINGLE_CHAR,
PROD_ANY,
PROD_SINGLE_SET,
PROD_PARENS_UNION,
PROD_SET_POSITIVE,
PROD_SET_NEGATIVE,
PROD_POSITIVE_SET,
PROD_NEGATIVE_SET,
PROD_SET_ITEMS_DECAY,
PROD_SET_ITEMS_ADD,
PROD_SET_ITEM_CHAR,
PROD_SET_ITEM_RANGE,
PROD_RANGE,
};
enum { NPRODS = PROD_RANGE + 1 };
enum {
TOK_CHAR,
TOK_DOT,
TOK_LRANGE,
TOK_RRANGE,
TOK_LPAREN,
TOK_RPAREN,
TOK_UNION,
TOK_RANGE,
TOK_NEGATE,
TOK_STAR,
TOK_PLUS,
TOK_MAYBE,
};
enum { NTOKS = TOK_MAYBE + 1 };
language build_language();
language_ptr ask_language();
finite_automaton build_lexer();
parser_tables_ptr ask_parser_tables();
finite_automaton build_dfa(
std::string const& name, std::string const& regex, int token);
std::any shift_internal(int token, std::string& text);
std::any reduce_internal(int production, std::vector<std::any>& rhs, int result_token);
class parser : public parsegen::parser {
public:
parser(int result_token_in);
parser(parser const&) = default;
virtual ~parser() override = default;
protected:
virtual std::any shift(int token, std::string& text) override;
virtual std::any reduce(int token, std::vector<std::any>& rhs) override;
private:
int result_token;
};
bool matches(std::string const& r, std::string const& t);
std::string from_charset(std::set<char> const& s);
std::string from_automaton(finite_automaton const& fa);
std::string for_first_occurrence_of(std::string const& s);
std::string for_case_insensitive(std::string const& s);
std::string maybe_sign();
std::string leading_digits();
std::string trailing_digits();
std::string unsigned_floating_point_not_integer();
std::string unsigned_integer();
std::string unsigned_floating_point();
std::string signed_integer();
std::string signed_floating_point_not_integer();
std::string signed_floating_point();
std::string whitespace();
std::string newline();
std::string identifier();
std::string C_style_comment();
std::string single_quoted_string();
std::string double_quoted_string();
} // end namespace regex
inline std::string anycase(std::string const& a)
{
return parsegen::regex::for_case_insensitive(a);
}
} // end namespace parsegen
#endif