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
|
%option batch
%option c++
%option noyywrap
%option 8bit
%option stack
%option yylineno
%option yyclass="json::jsonParser"
%option prefix="jsonBase"
%{
#include <string>
#include <utility>
class jsonBaseFlexLexer;
#include "jsonParse.h"
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
#ifdef __clang__
#pragma clang diagnostic ignored "-Wnull-conversion"
#endif
[[maybe_unused]]static constexpr auto x=getpid;
%}
beginobj "{"
endobj "}"
beginarray "["
endarray "]"
beginstr "\""
endstr "\""
true "true"
false "false"
null "null"
number [-+]?[0-9]+(\.[0-9]+)?
colon ":"
separator ","
escape "\\"
text [^\\\"]*
%x OBJECT_ITEM
%x OBJECT_ITEM_OR_END
%x OBJECT_NEXT
%x ARRAY_ITEM
%x ARRAY_NEXT
%x COLON
%x TEXT
%x STRING
%x ESCAPE
%%
<ARRAY_ITEM,INITIAL>{true} {
pushBoolean(true);
yy_pop_state();
}
<ARRAY_ITEM,INITIAL>{false} {
pushBoolean(false);
yy_pop_state();
}
<ARRAY_ITEM,INITIAL>{number} {
pushNumber(std::strtof(YYText(), NULL));
yy_pop_state();
}
<ARRAY_ITEM,INITIAL>{null} {
pushNull();
yy_pop_state();
}
<ARRAY_ITEM,INITIAL,OBJECT_ITEM,OBJECT_ITEM_OR_END>{beginstr} {
yy_push_state(STRING);
}
<ARRAY_ITEM,INITIAL>{beginobj} {
beginObject();
BEGIN(OBJECT_ITEM_OR_END);
}
<ARRAY_ITEM,INITIAL>{beginarray} {
beginArray();
BEGIN(ARRAY_NEXT);
yy_push_state(ARRAY_ITEM);
}
<STRING>{endstr} {
yy_pop_state();
switch (YY_START) {
case ARRAY_ITEM:
case INITIAL:
pushText(std::move(buf));
yy_pop_state();
break;
case OBJECT_ITEM:
case OBJECT_ITEM_OR_END:
pushKey(std::move(buf));
BEGIN(COLON);
break;
}
buf.clear();
}
<OBJECT_NEXT,OBJECT_ITEM_OR_END>{endobj} {
endObject();
yy_pop_state();
}
<ARRAY_ITEM>{endarray} {
endArray();
yy_pop_state();
yy_pop_state();
}
<ARRAY_NEXT>{endarray} {
endArray();
yy_pop_state();
}
<COLON>{colon} {
BEGIN(OBJECT_NEXT);
yy_push_state(INITIAL);
}
<OBJECT_NEXT>{separator} {
BEGIN(OBJECT_ITEM);
}
<ARRAY_NEXT>{separator} {
yy_push_state(INITIAL);
}
<STRING>{escape} {
yy_push_state(ESCAPE);
}
<ESCAPE>"\"" { buf += "\""; yy_pop_state(); }
<ESCAPE>"\\" { buf += "\\"; yy_pop_state(); }
<ESCAPE>"/" { buf += "/"; yy_pop_state(); }
<ESCAPE>"b" { buf += "\b"; yy_pop_state(); }
<ESCAPE>"f" { buf += "\f"; yy_pop_state(); }
<ESCAPE>"n" { buf += "\n"; yy_pop_state(); }
<ESCAPE>"r" { buf += "\r"; yy_pop_state(); }
<ESCAPE>"t" { buf += "\t"; yy_pop_state(); }
<ESCAPE>"u"[0-9a-fA-Z]{4} {
appendEscape(YYText(), buf);
yy_pop_state();
}
<STRING>{text} {
buf += YYText();
}
<*>[ \t\r\n\f] {
}
<*>. {
LexerError("Unexpected input");
}
|