-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtomlreader.h
183 lines (139 loc) · 3.31 KB
/
tomlreader.h
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#ifndef _H_TOML_READER
#define _H_TOML_READER
#include <phpcpp.h>
#include "parameter.h"
#include "token8.h"
#include <vector>
#include "ustr_data.h"
#include "pcre8_imp.h"
// globals for TomlReader, shareable, for a static class member.
namespace pun {
class KeyTable;
class Token8Stream;
class ValueList;
class Rex : public Php::Base {
public:
// enums ids, for mixture of regular expressions
// and single characters.
enum {
Bad = 0,
Equal,
Bool,
DateTime,
EOS,
Integer, //5
Quote3,
Quote1,
Apost3,
Apost1,
Newline, // 10
Space,
LSquare, //12
RSquare,
LCurly,
RCurly,
Comma,
Dot,
BareKey, // 18
EscapedChar,
Escape,
NoEscape,
FloatExp,
FloatDot,
Hash,
LitString,
SpacedEqual,
CommentStuff,
HashComment,
AnyValue,
Dig_Dig,
No_0Digit,
Float_E,
AnyChar,
};
Re8map* _re8;
IdList _keyRe;
IdList _valueRe;
IdList _estrRe;
IdList _lstrRe;
IdList _mlstrRe;
CharMap_sp _singles;
Rex();
~Rex();
static Rex* getGlobalRex();
private:
static Rex* _globalRex;
};
/*!
Using Token8Stream and recursive parsing,
parse a TOML document into a
a KeyTable / ValueList hierarchy
*/
class TomlReader : public Php::Base {
public:
static const char* PHP_NAME;
static void setup_ext(Php::Extension& ext);
static Php::Value parseFile(Php::Parameters& param);
static Php::Value getUseVersion();
static Php::Value getTomlVersion();
TomlReader();
~TomlReader();
Php::Value parse(Php::Parameters ¶m);
void setData(Str_ptr& data) { _src = data; }
protected:
Php::Value doParse();
void popExpSet();
void pushExpSet(int id);
void setExpSet(int id);
void syntaxError(const char* msg);
void valueError(const char* msg, const std::string& value);
void syntaxError(const std::string& msg);
void arrayMatchError(pun::Pype spunt, pun::Pype punt);
void parseComment();
void parseKeyValue();
void parseTablePath();
int finishLine();
void parseKeyName(std::string& name);
void parseArray(ValueList* vlist);
void parseInlineTable();
void parseValue(Php::Value& val, pun::Pype& punt);
void parseQString(std::string& sval);
void parseMLQString(std::string& sval);
void parseLitString(std::string& sval);
void parseMLString(std::string& sval);
std::string escString(svx::string_view sv);
void invalidEscChar(char eChar);
void fn_checkFullMatch(const std::string& target, const std::string& cap);
void throw_notFullMatch(const std::string& target, const std::string& cap);
//bool fn_moveLiteralStr(svx::string_view& view);
void parseDateTime(Php::Value& val);
void parseFloat(Php::Value& val, Pcre8_match& matches);
void parseFloatExp(Php::Value& val);
void parseInteger(std::string& val);
int fn_getExpSetId() const { return _expSetId; }
private:
unsigned int checkBOM(const char* sptr, unsigned int slen);
enum {
eKey,
eScaler,
eLString,
eMLString,
eBString
};
Rex* _myrex;
Str_ptr _src;
KeyTable* _table;
Token8 _token;
KeyTable* _root;
Php::Value _v_root;
Token8Stream* _ts;
Php::Value _v_ts;
int _stackTop;
int _expSetId;
IdList _expStack;
std::string _valueBuf;
svx::string_view _valueText;
Re8map_share _remap;
};
};
#endif