@loaders.gl/json 3.1.0-alpha.4 → 3.1.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +1839 -0
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/geojson-loader.js +29 -143
- package/dist/es5/geojson-loader.js.map +1 -1
- package/dist/es5/index.js +6 -6
- package/dist/es5/json-loader.js +18 -44
- package/dist/es5/json-loader.js.map +1 -1
- package/dist/es5/lib/clarinet/clarinet.js +406 -481
- package/dist/es5/lib/clarinet/clarinet.js.map +1 -1
- package/dist/es5/lib/jsonpath/jsonpath.js +54 -101
- package/dist/es5/lib/jsonpath/jsonpath.js.map +1 -1
- package/dist/es5/lib/parse-json-in-batches.js +78 -237
- package/dist/es5/lib/parse-json-in-batches.js.map +1 -1
- package/dist/es5/lib/parse-json.js +4 -9
- package/dist/es5/lib/parse-json.js.map +1 -1
- package/dist/es5/lib/parse-ndjson-in-batches.js +31 -143
- package/dist/es5/lib/parse-ndjson-in-batches.js.map +1 -1
- package/dist/es5/lib/parse-ndjson.js +2 -2
- package/dist/es5/lib/parse-ndjson.js.map +1 -1
- package/dist/es5/lib/parser/json-parser.js +114 -137
- package/dist/es5/lib/parser/json-parser.js.map +1 -1
- package/dist/es5/lib/parser/streaming-json-parser.js +63 -128
- package/dist/es5/lib/parser/streaming-json-parser.js.map +1 -1
- package/dist/es5/ndjson-loader.js +11 -30
- package/dist/es5/ndjson-loader.js.map +1 -1
- package/dist/esm/geojson-loader.js +1 -1
- package/dist/esm/geojson-loader.js.map +1 -1
- package/dist/esm/json-loader.js +1 -1
- package/dist/esm/json-loader.js.map +1 -1
- package/dist/esm/lib/clarinet/clarinet.js +222 -260
- package/dist/esm/lib/clarinet/clarinet.js.map +1 -1
- package/dist/esm/lib/parse-ndjson-in-batches.js +1 -1
- package/dist/esm/lib/parse-ndjson-in-batches.js.map +1 -1
- package/dist/esm/lib/parse-ndjson.js +1 -1
- package/dist/esm/lib/parse-ndjson.js.map +1 -1
- package/dist/esm/lib/parser/json-parser.js +48 -47
- package/dist/esm/lib/parser/json-parser.js.map +1 -1
- package/dist/esm/lib/parser/streaming-json-parser.js +29 -34
- package/dist/esm/lib/parser/streaming-json-parser.js.map +1 -1
- package/dist/esm/ndjson-loader.js +3 -1
- package/dist/esm/ndjson-loader.js.map +1 -1
- package/dist/geojson-loader.d.ts +16 -0
- package/dist/geojson-loader.d.ts.map +1 -0
- package/dist/geojson-loader.js +78 -0
- package/dist/geojson-worker.js +1702 -2
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/json-loader.d.ts +14 -0
- package/dist/json-loader.d.ts.map +1 -0
- package/dist/json-loader.js +57 -0
- package/dist/jsonl-loader.d.ts +1 -0
- package/dist/jsonl-loader.d.ts.map +1 -0
- package/dist/jsonl-loader.js +54 -0
- package/dist/lib/clarinet/clarinet.d.ts +74 -0
- package/dist/lib/clarinet/clarinet.d.ts.map +1 -0
- package/dist/lib/clarinet/clarinet.js +535 -0
- package/dist/lib/jsonpath/jsonpath.d.ts +32 -0
- package/dist/lib/jsonpath/jsonpath.d.ts.map +1 -0
- package/dist/lib/jsonpath/jsonpath.js +89 -0
- package/dist/lib/parse-json-in-batches.d.ts +4 -0
- package/dist/lib/parse-json-in-batches.d.ts.map +1 -0
- package/dist/lib/parse-json-in-batches.js +80 -0
- package/dist/lib/parse-json.d.ts +3 -0
- package/dist/lib/parse-json.d.ts.map +1 -0
- package/dist/lib/parse-json.js +29 -0
- package/dist/lib/parse-ndjson-in-batches.d.ts +4 -0
- package/dist/lib/parse-ndjson-in-batches.d.ts.map +1 -0
- package/dist/lib/parse-ndjson-in-batches.js +35 -0
- package/dist/lib/parse-ndjson.d.ts +2 -0
- package/dist/lib/parse-ndjson.d.ts.map +1 -0
- package/dist/lib/parse-ndjson.js +14 -0
- package/dist/lib/parser/json-parser.d.ts +22 -0
- package/dist/lib/parser/json-parser.d.ts.map +1 -0
- package/dist/lib/parser/json-parser.js +98 -0
- package/dist/lib/parser/streaming-json-parser.d.ts +37 -0
- package/dist/lib/parser/streaming-json-parser.d.ts.map +1 -0
- package/dist/lib/parser/streaming-json-parser.js +100 -0
- package/dist/ndjson-loader.d.ts +22 -0
- package/dist/ndjson-loader.d.ts.map +1 -0
- package/dist/ndjson-loader.js +35 -0
- package/dist/workers/geojson-worker.d.ts +2 -0
- package/dist/workers/geojson-worker.d.ts.map +1 -0
- package/dist/workers/geojson-worker.js +5 -0
- package/package.json +8 -8
- package/src/lib/clarinet/clarinet.ts +539 -0
- package/src/lib/parser/json-parser.ts +52 -55
- package/src/lib/parser/streaming-json-parser.ts +28 -32
- package/src/ndjson-loader.ts +3 -1
- package/dist/dist.min.js +0 -2
- package/dist/dist.min.js.map +0 -1
- package/dist/geojson-worker.js.map +0 -1
- package/src/lib/clarinet/clarinet.js +0 -578
|
@@ -5,55 +5,41 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.default =
|
|
9
|
-
|
|
10
|
-
var
|
|
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
|
-
FALSE4: S++,
|
|
44
|
-
NULL: S++,
|
|
45
|
-
NULL2: S++,
|
|
46
|
-
NULL3: S++,
|
|
47
|
-
NUMBER_DECIMAL_POINT: S++,
|
|
48
|
-
NUMBER_DIGIT: S++
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
for (var s_ in STATE) {
|
|
52
|
-
STATE[STATE[s_]] = s_;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
S = STATE;
|
|
56
|
-
var Char = {
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
const MAX_BUFFER_LENGTH = Number.MAX_SAFE_INTEGER;
|
|
13
|
+
var STATE;
|
|
14
|
+
|
|
15
|
+
(function (STATE) {
|
|
16
|
+
STATE[STATE["BEGIN"] = 0] = "BEGIN";
|
|
17
|
+
STATE[STATE["VALUE"] = 1] = "VALUE";
|
|
18
|
+
STATE[STATE["OPEN_OBJECT"] = 2] = "OPEN_OBJECT";
|
|
19
|
+
STATE[STATE["CLOSE_OBJECT"] = 3] = "CLOSE_OBJECT";
|
|
20
|
+
STATE[STATE["OPEN_ARRAY"] = 4] = "OPEN_ARRAY";
|
|
21
|
+
STATE[STATE["CLOSE_ARRAY"] = 5] = "CLOSE_ARRAY";
|
|
22
|
+
STATE[STATE["TEXT_ESCAPE"] = 6] = "TEXT_ESCAPE";
|
|
23
|
+
STATE[STATE["STRING"] = 7] = "STRING";
|
|
24
|
+
STATE[STATE["BACKSLASH"] = 8] = "BACKSLASH";
|
|
25
|
+
STATE[STATE["END"] = 9] = "END";
|
|
26
|
+
STATE[STATE["OPEN_KEY"] = 10] = "OPEN_KEY";
|
|
27
|
+
STATE[STATE["CLOSE_KEY"] = 11] = "CLOSE_KEY";
|
|
28
|
+
STATE[STATE["TRUE"] = 12] = "TRUE";
|
|
29
|
+
STATE[STATE["TRUE2"] = 13] = "TRUE2";
|
|
30
|
+
STATE[STATE["TRUE3"] = 14] = "TRUE3";
|
|
31
|
+
STATE[STATE["FALSE"] = 15] = "FALSE";
|
|
32
|
+
STATE[STATE["FALSE2"] = 16] = "FALSE2";
|
|
33
|
+
STATE[STATE["FALSE3"] = 17] = "FALSE3";
|
|
34
|
+
STATE[STATE["FALSE4"] = 18] = "FALSE4";
|
|
35
|
+
STATE[STATE["NULL"] = 19] = "NULL";
|
|
36
|
+
STATE[STATE["NULL2"] = 20] = "NULL2";
|
|
37
|
+
STATE[STATE["NULL3"] = 21] = "NULL3";
|
|
38
|
+
STATE[STATE["NUMBER_DECIMAL_POINT"] = 22] = "NUMBER_DECIMAL_POINT";
|
|
39
|
+
STATE[STATE["NUMBER_DIGIT"] = 23] = "NUMBER_DIGIT";
|
|
40
|
+
})(STATE || (STATE = {}));
|
|
41
|
+
|
|
42
|
+
const Char = {
|
|
57
43
|
tab: 0x09,
|
|
58
44
|
lineFeed: 0x0a,
|
|
59
45
|
carriageReturn: 0x0d,
|
|
@@ -83,504 +69,443 @@ var Char = {
|
|
|
83
69
|
openBrace: 0x7b,
|
|
84
70
|
closeBrace: 0x7d
|
|
85
71
|
};
|
|
72
|
+
const stringTokenPattern = /[\\"\n]/g;
|
|
73
|
+
const DEFAULT_OPTIONS = {
|
|
74
|
+
onready: () => {},
|
|
75
|
+
onopenobject: () => {},
|
|
76
|
+
onkey: () => {},
|
|
77
|
+
oncloseobject: () => {},
|
|
78
|
+
onopenarray: () => {},
|
|
79
|
+
onclosearray: () => {},
|
|
80
|
+
onvalue: () => {},
|
|
81
|
+
onerror: () => {},
|
|
82
|
+
onend: () => {},
|
|
83
|
+
onchunkparsed: () => {}
|
|
84
|
+
};
|
|
86
85
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
86
|
+
class ClarinetParser {
|
|
87
|
+
constructor(options = {}) {
|
|
88
|
+
(0, _defineProperty2.default)(this, "options", DEFAULT_OPTIONS);
|
|
89
|
+
(0, _defineProperty2.default)(this, "bufferCheckPosition", MAX_BUFFER_LENGTH);
|
|
90
|
+
(0, _defineProperty2.default)(this, "q", '');
|
|
91
|
+
(0, _defineProperty2.default)(this, "c", '');
|
|
92
|
+
(0, _defineProperty2.default)(this, "p", '');
|
|
93
|
+
(0, _defineProperty2.default)(this, "closed", false);
|
|
94
|
+
(0, _defineProperty2.default)(this, "closedRoot", false);
|
|
95
|
+
(0, _defineProperty2.default)(this, "sawRoot", false);
|
|
96
|
+
(0, _defineProperty2.default)(this, "error", null);
|
|
97
|
+
(0, _defineProperty2.default)(this, "state", STATE.BEGIN);
|
|
98
|
+
(0, _defineProperty2.default)(this, "stack", []);
|
|
99
|
+
(0, _defineProperty2.default)(this, "position", 0);
|
|
100
|
+
(0, _defineProperty2.default)(this, "column", 0);
|
|
101
|
+
(0, _defineProperty2.default)(this, "line", 1);
|
|
102
|
+
(0, _defineProperty2.default)(this, "slashed", false);
|
|
103
|
+
(0, _defineProperty2.default)(this, "unicodeI", 0);
|
|
104
|
+
(0, _defineProperty2.default)(this, "unicodeS", null);
|
|
105
|
+
(0, _defineProperty2.default)(this, "depth", 0);
|
|
106
|
+
(0, _defineProperty2.default)(this, "textNode", void 0);
|
|
107
|
+
(0, _defineProperty2.default)(this, "numberNode", void 0);
|
|
108
|
+
this.options = { ...DEFAULT_OPTIONS,
|
|
109
|
+
...options
|
|
110
|
+
};
|
|
111
|
+
this.textNode = undefined;
|
|
112
|
+
this.numberNode = '';
|
|
113
|
+
this.emit('onready');
|
|
106
114
|
}
|
|
107
115
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
var stringTokenPattern = /[\\"\n]/g;
|
|
116
|
+
end() {
|
|
117
|
+
if (this.state !== STATE.VALUE || this.depth !== 0) this._error('Unexpected end');
|
|
112
118
|
|
|
113
|
-
|
|
114
|
-
function ClarinetParser() {
|
|
115
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
116
|
-
(0, _classCallCheck2.default)(this, ClarinetParser);
|
|
119
|
+
this._closeValue();
|
|
117
120
|
|
|
118
|
-
this.
|
|
121
|
+
this.c = '';
|
|
122
|
+
this.closed = true;
|
|
123
|
+
this.emit('onend');
|
|
124
|
+
return this;
|
|
119
125
|
}
|
|
120
126
|
|
|
121
|
-
(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
this.bufferCheckPosition = MAX_BUFFER_LENGTH;
|
|
127
|
-
this.q = '';
|
|
128
|
-
this.c = '';
|
|
129
|
-
this.p = '';
|
|
130
|
-
this.options = options || {};
|
|
131
|
-
this.closed = false;
|
|
132
|
-
this.closedRoot = false;
|
|
133
|
-
this.sawRoot = false;
|
|
134
|
-
this.tag = null;
|
|
135
|
-
this.error = null;
|
|
136
|
-
this.state = S.BEGIN;
|
|
137
|
-
this.stack = new Array();
|
|
138
|
-
this.position = this.column = 0;
|
|
139
|
-
this.line = 1;
|
|
140
|
-
this.slashed = false;
|
|
141
|
-
this.unicodeI = 0;
|
|
142
|
-
this.unicodeS = null;
|
|
143
|
-
this.depth = 0;
|
|
144
|
-
|
|
145
|
-
if ('onready' in options) {
|
|
146
|
-
this.onready = options.onready;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if ('onopenobject' in options) {
|
|
150
|
-
this.onopenobject = options.onopenobject;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if ('onkey' in options) {
|
|
154
|
-
this.onkey = options.onkey;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if ('oncloseobject' in options) {
|
|
158
|
-
this.oncloseobject = options.oncloseobject;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if ('onopenarray' in options) {
|
|
162
|
-
this.onopenarray = options.onopenarray;
|
|
163
|
-
}
|
|
127
|
+
resume() {
|
|
128
|
+
this.error = null;
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
164
131
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
132
|
+
close() {
|
|
133
|
+
return this.write(null);
|
|
134
|
+
}
|
|
168
135
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
136
|
+
emit(event, data) {
|
|
137
|
+
var _this$options$event, _this$options;
|
|
172
138
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
139
|
+
(_this$options$event = (_this$options = this.options)[event]) === null || _this$options$event === void 0 ? void 0 : _this$options$event.call(_this$options, data, this);
|
|
140
|
+
}
|
|
176
141
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
142
|
+
emitNode(event, data) {
|
|
143
|
+
this._closeValue();
|
|
180
144
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
145
|
+
this.emit(event, data);
|
|
146
|
+
}
|
|
184
147
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
key: "_clearBuffers",
|
|
189
|
-
value: function _clearBuffers() {
|
|
190
|
-
for (var buffer in buffers) {
|
|
191
|
-
this[buffer] = buffers[buffer];
|
|
192
|
-
}
|
|
148
|
+
write(chunk) {
|
|
149
|
+
if (this.error) {
|
|
150
|
+
throw this.error;
|
|
193
151
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
if (this.state !== S.VALUE || this.depth !== 0) error(this, 'Unexpected end');
|
|
198
|
-
closeValue(this);
|
|
199
|
-
this.c = '';
|
|
200
|
-
this.closed = true;
|
|
201
|
-
emit(this, 'onend');
|
|
202
|
-
|
|
203
|
-
this._initialize(this.options);
|
|
204
|
-
|
|
205
|
-
return this;
|
|
206
|
-
}
|
|
207
|
-
}, {
|
|
208
|
-
key: "resume",
|
|
209
|
-
value: function resume() {
|
|
210
|
-
this.error = null;
|
|
211
|
-
return this;
|
|
152
|
+
|
|
153
|
+
if (this.closed) {
|
|
154
|
+
return this._error('Cannot write after close. Assign an onready handler.');
|
|
212
155
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
return this.write(null);
|
|
156
|
+
|
|
157
|
+
if (chunk === null) {
|
|
158
|
+
return this.end();
|
|
217
159
|
}
|
|
218
|
-
}, {
|
|
219
|
-
key: "write",
|
|
220
|
-
value: function write(chunk) {
|
|
221
|
-
if (this.error) {
|
|
222
|
-
throw this.error;
|
|
223
|
-
}
|
|
224
160
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
161
|
+
let i = 0;
|
|
162
|
+
let c = chunk.charCodeAt(0);
|
|
163
|
+
let p = this.p;
|
|
228
164
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
165
|
+
while (c) {
|
|
166
|
+
p = c;
|
|
167
|
+
this.c = c = chunk.charCodeAt(i++);
|
|
232
168
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
while (c) {
|
|
239
|
-
p = c;
|
|
240
|
-
this.c = c = chunk.charCodeAt(i++);
|
|
241
|
-
|
|
242
|
-
if (p !== c) {
|
|
243
|
-
this.p = p;
|
|
244
|
-
} else {
|
|
245
|
-
p = this.p;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
if (!c) break;
|
|
249
|
-
if (DEBUG) console.log(i, c, STATE[this.state]);
|
|
250
|
-
this.position++;
|
|
251
|
-
|
|
252
|
-
if (c === Char.lineFeed) {
|
|
253
|
-
this.line++;
|
|
254
|
-
this.column = 0;
|
|
255
|
-
} else this.column++;
|
|
256
|
-
|
|
257
|
-
switch (this.state) {
|
|
258
|
-
case S.BEGIN:
|
|
259
|
-
if (c === Char.openBrace) this.state = S.OPEN_OBJECT;else if (c === Char.openBracket) this.state = S.OPEN_ARRAY;else if (!isWhitespace(c)) {
|
|
260
|
-
error(this, 'Non-whitespace before {[.');
|
|
261
|
-
}
|
|
262
|
-
continue;
|
|
169
|
+
if (p !== c) {
|
|
170
|
+
this.p = p;
|
|
171
|
+
} else {
|
|
172
|
+
p = this.p;
|
|
173
|
+
}
|
|
263
174
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
175
|
+
if (!c) break;
|
|
176
|
+
this.position++;
|
|
177
|
+
|
|
178
|
+
if (c === Char.lineFeed) {
|
|
179
|
+
this.line++;
|
|
180
|
+
this.column = 0;
|
|
181
|
+
} else this.column++;
|
|
182
|
+
|
|
183
|
+
switch (this.state) {
|
|
184
|
+
case STATE.BEGIN:
|
|
185
|
+
if (c === Char.openBrace) this.state = STATE.OPEN_OBJECT;else if (c === Char.openBracket) this.state = STATE.OPEN_ARRAY;else if (!isWhitespace(c)) {
|
|
186
|
+
this._error('Non-whitespace before {[.');
|
|
187
|
+
}
|
|
188
|
+
continue;
|
|
189
|
+
|
|
190
|
+
case STATE.OPEN_KEY:
|
|
191
|
+
case STATE.OPEN_OBJECT:
|
|
192
|
+
if (isWhitespace(c)) continue;
|
|
193
|
+
if (this.state === STATE.OPEN_KEY) this.stack.push(STATE.CLOSE_KEY);else if (c === Char.closeBrace) {
|
|
194
|
+
this.emit('onopenobject');
|
|
195
|
+
this.depth++;
|
|
196
|
+
this.emit('oncloseobject');
|
|
197
|
+
this.depth--;
|
|
198
|
+
this.state = this.stack.pop() || STATE.VALUE;
|
|
278
199
|
continue;
|
|
200
|
+
} else this.stack.push(STATE.CLOSE_OBJECT);
|
|
201
|
+
if (c === Char.doubleQuote) this.state = STATE.STRING;else this._error('Malformed object key should start with "');
|
|
202
|
+
continue;
|
|
279
203
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
var event = this.state === S.CLOSE_KEY ? 'key' : 'object';
|
|
284
|
-
|
|
285
|
-
if (c === Char.colon) {
|
|
286
|
-
if (this.state === S.CLOSE_OBJECT) {
|
|
287
|
-
this.stack.push(S.CLOSE_OBJECT);
|
|
288
|
-
closeValue(this, 'onopenobject');
|
|
289
|
-
this.depth++;
|
|
290
|
-
} else closeValue(this, 'onkey');
|
|
291
|
-
|
|
292
|
-
this.state = S.VALUE;
|
|
293
|
-
} else if (c === Char.closeBrace) {
|
|
294
|
-
emitNode(this, 'oncloseobject');
|
|
295
|
-
this.depth--;
|
|
296
|
-
this.state = this.stack.pop() || S.VALUE;
|
|
297
|
-
} else if (c === Char.comma) {
|
|
298
|
-
if (this.state === S.CLOSE_OBJECT) this.stack.push(S.CLOSE_OBJECT);
|
|
299
|
-
closeValue(this);
|
|
300
|
-
this.state = S.OPEN_KEY;
|
|
301
|
-
} else error(this, 'Bad object');
|
|
204
|
+
case STATE.CLOSE_KEY:
|
|
205
|
+
case STATE.CLOSE_OBJECT:
|
|
206
|
+
if (isWhitespace(c)) continue;
|
|
302
207
|
|
|
303
|
-
|
|
208
|
+
if (c === Char.colon) {
|
|
209
|
+
if (this.state === STATE.CLOSE_OBJECT) {
|
|
210
|
+
this.stack.push(STATE.CLOSE_OBJECT);
|
|
304
211
|
|
|
305
|
-
|
|
306
|
-
case S.VALUE:
|
|
307
|
-
if (isWhitespace(c)) continue;
|
|
212
|
+
this._closeValue('onopenobject');
|
|
308
213
|
|
|
309
|
-
if (this.state === S.OPEN_ARRAY) {
|
|
310
|
-
emit(this, 'onopenarray');
|
|
311
214
|
this.depth++;
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
if (c === Char.closeBracket) {
|
|
315
|
-
emit(this, 'onclosearray');
|
|
316
|
-
this.depth--;
|
|
317
|
-
this.state = this.stack.pop() || S.VALUE;
|
|
318
|
-
continue;
|
|
319
|
-
} else {
|
|
320
|
-
this.stack.push(S.CLOSE_ARRAY);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
if (c === Char.doubleQuote) this.state = S.STRING;else if (c === Char.openBrace) this.state = S.OPEN_OBJECT;else if (c === Char.openBracket) this.state = S.OPEN_ARRAY;else if (c === Char.t) this.state = S.TRUE;else if (c === Char.f) this.state = S.FALSE;else if (c === Char.n) this.state = S.NULL;else if (c === Char.minus) {
|
|
325
|
-
this.numberNode += '-';
|
|
326
|
-
} else if (Char._0 <= c && c <= Char._9) {
|
|
327
|
-
this.numberNode += String.fromCharCode(c);
|
|
328
|
-
this.state = S.NUMBER_DIGIT;
|
|
329
|
-
} else error(this, 'Bad value');
|
|
330
|
-
continue;
|
|
215
|
+
} else this._closeValue('onkey');
|
|
331
216
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
this.depth--;
|
|
340
|
-
this.state = this.stack.pop() || S.VALUE;
|
|
341
|
-
} else if (isWhitespace(c)) continue;else error(this, 'Bad array');
|
|
342
|
-
|
|
343
|
-
continue;
|
|
344
|
-
|
|
345
|
-
case S.STRING:
|
|
346
|
-
if (this.textNode === undefined) {
|
|
347
|
-
this.textNode = '';
|
|
348
|
-
}
|
|
217
|
+
this.state = STATE.VALUE;
|
|
218
|
+
} else if (c === Char.closeBrace) {
|
|
219
|
+
this.emitNode('oncloseobject');
|
|
220
|
+
this.depth--;
|
|
221
|
+
this.state = this.stack.pop() || STATE.VALUE;
|
|
222
|
+
} else if (c === Char.comma) {
|
|
223
|
+
if (this.state === STATE.CLOSE_OBJECT) this.stack.push(STATE.CLOSE_OBJECT);
|
|
349
224
|
|
|
350
|
-
|
|
351
|
-
slashed = this.slashed,
|
|
352
|
-
unicodeI = this.unicodeI;
|
|
225
|
+
this._closeValue();
|
|
353
226
|
|
|
354
|
-
|
|
355
|
-
|
|
227
|
+
this.state = STATE.OPEN_KEY;
|
|
228
|
+
} else this._error('Bad object');
|
|
356
229
|
|
|
357
|
-
|
|
358
|
-
this.unicodeS += String.fromCharCode(c);
|
|
359
|
-
c = chunk.charCodeAt(i++);
|
|
360
|
-
this.position++;
|
|
230
|
+
continue;
|
|
361
231
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
starti = i - 1;
|
|
366
|
-
} else {
|
|
367
|
-
unicodeI++;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
if (!c) break STRING_BIGLOOP;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
if (c === Char.doubleQuote && !slashed) {
|
|
374
|
-
this.state = this.stack.pop() || S.VALUE;
|
|
375
|
-
this.textNode += chunk.substring(starti, i - 1);
|
|
376
|
-
this.position += i - 1 - starti;
|
|
377
|
-
break;
|
|
378
|
-
}
|
|
232
|
+
case STATE.OPEN_ARRAY:
|
|
233
|
+
case STATE.VALUE:
|
|
234
|
+
if (isWhitespace(c)) continue;
|
|
379
235
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
c = chunk.charCodeAt(i++);
|
|
385
|
-
this.position++;
|
|
386
|
-
if (!c) break;
|
|
387
|
-
}
|
|
236
|
+
if (this.state === STATE.OPEN_ARRAY) {
|
|
237
|
+
this.emit('onopenarray');
|
|
238
|
+
this.depth++;
|
|
239
|
+
this.state = STATE.VALUE;
|
|
388
240
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
241
|
+
if (c === Char.closeBracket) {
|
|
242
|
+
this.emit('onclosearray');
|
|
243
|
+
this.depth--;
|
|
244
|
+
this.state = this.stack.pop() || STATE.VALUE;
|
|
245
|
+
continue;
|
|
246
|
+
} else {
|
|
247
|
+
this.stack.push(STATE.CLOSE_ARRAY);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (c === Char.doubleQuote) this.state = STATE.STRING;else if (c === Char.openBrace) this.state = STATE.OPEN_OBJECT;else if (c === Char.openBracket) this.state = STATE.OPEN_ARRAY;else if (c === Char.t) this.state = STATE.TRUE;else if (c === Char.f) this.state = STATE.FALSE;else if (c === Char.n) this.state = STATE.NULL;else if (c === Char.minus) {
|
|
252
|
+
this.numberNode += '-';
|
|
253
|
+
} else if (Char._0 <= c && c <= Char._9) {
|
|
254
|
+
this.numberNode += String.fromCharCode(c);
|
|
255
|
+
this.state = STATE.NUMBER_DIGIT;
|
|
256
|
+
} else this._error('Bad value');
|
|
257
|
+
continue;
|
|
258
|
+
|
|
259
|
+
case STATE.CLOSE_ARRAY:
|
|
260
|
+
if (c === Char.comma) {
|
|
261
|
+
this.stack.push(STATE.CLOSE_ARRAY);
|
|
262
|
+
|
|
263
|
+
this._closeValue('onvalue');
|
|
264
|
+
|
|
265
|
+
this.state = STATE.VALUE;
|
|
266
|
+
} else if (c === Char.closeBracket) {
|
|
267
|
+
this.emitNode('onclosearray');
|
|
268
|
+
this.depth--;
|
|
269
|
+
this.state = this.stack.pop() || STATE.VALUE;
|
|
270
|
+
} else if (isWhitespace(c)) continue;else this._error('Bad array');
|
|
271
|
+
|
|
272
|
+
continue;
|
|
273
|
+
|
|
274
|
+
case STATE.STRING:
|
|
275
|
+
if (this.textNode === undefined) {
|
|
276
|
+
this.textNode = '';
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
let starti = i - 1;
|
|
280
|
+
let slashed = this.slashed;
|
|
281
|
+
let unicodeI = this.unicodeI;
|
|
282
|
+
|
|
283
|
+
STRING_BIGLOOP: while (true) {
|
|
284
|
+
while (unicodeI > 0) {
|
|
285
|
+
this.unicodeS += String.fromCharCode(c);
|
|
286
|
+
c = chunk.charCodeAt(i++);
|
|
287
|
+
this.position++;
|
|
288
|
+
|
|
289
|
+
if (unicodeI === 4) {
|
|
290
|
+
this.textNode += String.fromCharCode(parseInt(this.unicodeS, 16));
|
|
291
|
+
unicodeI = 0;
|
|
411
292
|
starti = i - 1;
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
stringTokenPattern.lastIndex = i;
|
|
416
|
-
var reResult = stringTokenPattern.exec(chunk);
|
|
417
|
-
|
|
418
|
-
if (reResult === null) {
|
|
419
|
-
i = chunk.length + 1;
|
|
420
|
-
this.textNode += chunk.substring(starti, i - 1);
|
|
421
|
-
this.position += i - 1 - starti;
|
|
422
|
-
break;
|
|
293
|
+
} else {
|
|
294
|
+
unicodeI++;
|
|
423
295
|
}
|
|
424
296
|
|
|
425
|
-
|
|
426
|
-
c = chunk.charCodeAt(reResult.index);
|
|
427
|
-
|
|
428
|
-
if (!c) {
|
|
429
|
-
this.textNode += chunk.substring(starti, i - 1);
|
|
430
|
-
this.position += i - 1 - starti;
|
|
431
|
-
break;
|
|
432
|
-
}
|
|
297
|
+
if (!c) break STRING_BIGLOOP;
|
|
433
298
|
}
|
|
434
299
|
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
continue;
|
|
442
|
-
|
|
443
|
-
case S.TRUE2:
|
|
444
|
-
if (c === Char.u) this.state = S.TRUE3;else error(this, 'Invalid true started with tr' + c);
|
|
445
|
-
continue;
|
|
446
|
-
|
|
447
|
-
case S.TRUE3:
|
|
448
|
-
if (c === Char.e) {
|
|
449
|
-
emit(this, 'onvalue', true);
|
|
450
|
-
this.state = this.stack.pop() || S.VALUE;
|
|
451
|
-
} else error(this, 'Invalid true started with tru' + c);
|
|
452
|
-
|
|
453
|
-
continue;
|
|
454
|
-
|
|
455
|
-
case S.FALSE:
|
|
456
|
-
if (c === Char.a) this.state = S.FALSE2;else error(this, 'Invalid false started with f' + c);
|
|
457
|
-
continue;
|
|
458
|
-
|
|
459
|
-
case S.FALSE2:
|
|
460
|
-
if (c === Char.l) this.state = S.FALSE3;else error(this, 'Invalid false started with fa' + c);
|
|
461
|
-
continue;
|
|
462
|
-
|
|
463
|
-
case S.FALSE3:
|
|
464
|
-
if (c === Char.s) this.state = S.FALSE4;else error(this, 'Invalid false started with fal' + c);
|
|
465
|
-
continue;
|
|
466
|
-
|
|
467
|
-
case S.FALSE4:
|
|
468
|
-
if (c === Char.e) {
|
|
469
|
-
emit(this, 'onvalue', false);
|
|
470
|
-
this.state = this.stack.pop() || S.VALUE;
|
|
471
|
-
} else error(this, 'Invalid false started with fals' + c);
|
|
472
|
-
|
|
473
|
-
continue;
|
|
300
|
+
if (c === Char.doubleQuote && !slashed) {
|
|
301
|
+
this.state = this.stack.pop() || STATE.VALUE;
|
|
302
|
+
this.textNode += chunk.substring(starti, i - 1);
|
|
303
|
+
this.position += i - 1 - starti;
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
474
306
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
307
|
+
if (c === Char.backslash && !slashed) {
|
|
308
|
+
slashed = true;
|
|
309
|
+
this.textNode += chunk.substring(starti, i - 1);
|
|
310
|
+
this.position += i - 1 - starti;
|
|
311
|
+
c = chunk.charCodeAt(i++);
|
|
312
|
+
this.position++;
|
|
313
|
+
if (!c) break;
|
|
314
|
+
}
|
|
478
315
|
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
316
|
+
if (slashed) {
|
|
317
|
+
slashed = false;
|
|
318
|
+
|
|
319
|
+
if (c === Char.n) {
|
|
320
|
+
this.textNode += '\n';
|
|
321
|
+
} else if (c === Char.r) {
|
|
322
|
+
this.textNode += '\r';
|
|
323
|
+
} else if (c === Char.t) {
|
|
324
|
+
this.textNode += '\t';
|
|
325
|
+
} else if (c === Char.f) {
|
|
326
|
+
this.textNode += '\f';
|
|
327
|
+
} else if (c === Char.b) {
|
|
328
|
+
this.textNode += '\b';
|
|
329
|
+
} else if (c === Char.u) {
|
|
330
|
+
unicodeI = 1;
|
|
331
|
+
this.unicodeS = '';
|
|
332
|
+
} else {
|
|
333
|
+
this.textNode += String.fromCharCode(c);
|
|
334
|
+
}
|
|
482
335
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
}
|
|
336
|
+
c = chunk.charCodeAt(i++);
|
|
337
|
+
this.position++;
|
|
338
|
+
starti = i - 1;
|
|
339
|
+
if (!c) break;else continue;
|
|
340
|
+
}
|
|
488
341
|
|
|
489
|
-
|
|
342
|
+
stringTokenPattern.lastIndex = i;
|
|
343
|
+
const reResult = stringTokenPattern.exec(chunk);
|
|
490
344
|
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
this.
|
|
494
|
-
this.
|
|
495
|
-
|
|
345
|
+
if (reResult === null) {
|
|
346
|
+
i = chunk.length + 1;
|
|
347
|
+
this.textNode += chunk.substring(starti, i - 1);
|
|
348
|
+
this.position += i - 1 - starti;
|
|
349
|
+
break;
|
|
350
|
+
}
|
|
496
351
|
|
|
497
|
-
|
|
352
|
+
i = reResult.index + 1;
|
|
353
|
+
c = chunk.charCodeAt(reResult.index);
|
|
498
354
|
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
} else if (c === Char.e || c === Char.E) {
|
|
504
|
-
if (this.numberNode.indexOf('e') !== -1 || this.numberNode.indexOf('E') !== -1) error(this, 'Invalid number has two exponential');
|
|
505
|
-
this.numberNode += 'e';
|
|
506
|
-
} else if (c === Char.plus || c === Char.minus) {
|
|
507
|
-
if (!(p === Char.e || p === Char.E)) error(this, 'Invalid symbol in number');
|
|
508
|
-
this.numberNode += String.fromCharCode(c);
|
|
509
|
-
} else {
|
|
510
|
-
closeNumber(this);
|
|
511
|
-
i--;
|
|
512
|
-
this.state = this.stack.pop() || S.VALUE;
|
|
355
|
+
if (!c) {
|
|
356
|
+
this.textNode += chunk.substring(starti, i - 1);
|
|
357
|
+
this.position += i - 1 - starti;
|
|
358
|
+
break;
|
|
513
359
|
}
|
|
514
|
-
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
this.slashed = slashed;
|
|
363
|
+
this.unicodeI = unicodeI;
|
|
364
|
+
continue;
|
|
365
|
+
|
|
366
|
+
case STATE.TRUE:
|
|
367
|
+
if (c === Char.r) this.state = STATE.TRUE2;else this._error("Invalid true started with t".concat(c));
|
|
368
|
+
continue;
|
|
369
|
+
|
|
370
|
+
case STATE.TRUE2:
|
|
371
|
+
if (c === Char.u) this.state = STATE.TRUE3;else this._error("Invalid true started with tr".concat(c));
|
|
372
|
+
continue;
|
|
373
|
+
|
|
374
|
+
case STATE.TRUE3:
|
|
375
|
+
if (c === Char.e) {
|
|
376
|
+
this.emit('onvalue', true);
|
|
377
|
+
this.state = this.stack.pop() || STATE.VALUE;
|
|
378
|
+
} else this._error("Invalid true started with tru".concat(c));
|
|
379
|
+
|
|
380
|
+
continue;
|
|
381
|
+
|
|
382
|
+
case STATE.FALSE:
|
|
383
|
+
if (c === Char.a) this.state = STATE.FALSE2;else this._error("Invalid false started with f".concat(c));
|
|
384
|
+
continue;
|
|
385
|
+
|
|
386
|
+
case STATE.FALSE2:
|
|
387
|
+
if (c === Char.l) this.state = STATE.FALSE3;else this._error("Invalid false started with fa".concat(c));
|
|
388
|
+
continue;
|
|
389
|
+
|
|
390
|
+
case STATE.FALSE3:
|
|
391
|
+
if (c === Char.s) this.state = STATE.FALSE4;else this._error("Invalid false started with fal".concat(c));
|
|
392
|
+
continue;
|
|
393
|
+
|
|
394
|
+
case STATE.FALSE4:
|
|
395
|
+
if (c === Char.e) {
|
|
396
|
+
this.emit('onvalue', false);
|
|
397
|
+
this.state = this.stack.pop() || STATE.VALUE;
|
|
398
|
+
} else this._error("Invalid false started with fals".concat(c));
|
|
399
|
+
|
|
400
|
+
continue;
|
|
401
|
+
|
|
402
|
+
case STATE.NULL:
|
|
403
|
+
if (c === Char.u) this.state = STATE.NULL2;else this._error("Invalid null started with n".concat(c));
|
|
404
|
+
continue;
|
|
405
|
+
|
|
406
|
+
case STATE.NULL2:
|
|
407
|
+
if (c === Char.l) this.state = STATE.NULL3;else this._error("Invalid null started with nu".concat(c));
|
|
408
|
+
continue;
|
|
409
|
+
|
|
410
|
+
case STATE.NULL3:
|
|
411
|
+
if (c === Char.l) {
|
|
412
|
+
this.emit('onvalue', null);
|
|
413
|
+
this.state = this.stack.pop() || STATE.VALUE;
|
|
414
|
+
} else this._error("Invalid null started with nul".concat(c));
|
|
415
|
+
|
|
416
|
+
continue;
|
|
417
|
+
|
|
418
|
+
case STATE.NUMBER_DECIMAL_POINT:
|
|
419
|
+
if (c === Char.period) {
|
|
420
|
+
this.numberNode += '.';
|
|
421
|
+
this.state = STATE.NUMBER_DIGIT;
|
|
422
|
+
} else this._error('Leading zero not followed by .');
|
|
423
|
+
|
|
424
|
+
continue;
|
|
425
|
+
|
|
426
|
+
case STATE.NUMBER_DIGIT:
|
|
427
|
+
if (Char._0 <= c && c <= Char._9) this.numberNode += String.fromCharCode(c);else if (c === Char.period) {
|
|
428
|
+
if (this.numberNode.indexOf('.') !== -1) this._error('Invalid number has two dots');
|
|
429
|
+
this.numberNode += '.';
|
|
430
|
+
} else if (c === Char.e || c === Char.E) {
|
|
431
|
+
if (this.numberNode.indexOf('e') !== -1 || this.numberNode.indexOf('E') !== -1) this._error('Invalid number has two exponential');
|
|
432
|
+
this.numberNode += 'e';
|
|
433
|
+
} else if (c === Char.plus || c === Char.minus) {
|
|
434
|
+
if (!(p === Char.e || p === Char.E)) this._error('Invalid symbol in number');
|
|
435
|
+
this.numberNode += String.fromCharCode(c);
|
|
436
|
+
} else {
|
|
437
|
+
this._closeNumber();
|
|
438
|
+
|
|
439
|
+
i--;
|
|
440
|
+
this.state = this.stack.pop() || STATE.VALUE;
|
|
441
|
+
}
|
|
442
|
+
continue;
|
|
515
443
|
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
}
|
|
519
|
-
}
|
|
444
|
+
default:
|
|
445
|
+
this._error("Unknown state: ".concat(this.state));
|
|
520
446
|
|
|
521
|
-
if (this.position >= this.bufferCheckPosition) {
|
|
522
|
-
checkBufferLength(this);
|
|
523
447
|
}
|
|
524
|
-
|
|
525
|
-
emit(this, 'onchunkparsed');
|
|
526
|
-
return this;
|
|
527
448
|
}
|
|
528
|
-
}]);
|
|
529
|
-
return ClarinetParser;
|
|
530
|
-
}();
|
|
531
449
|
|
|
532
|
-
|
|
450
|
+
if (this.position >= this.bufferCheckPosition) {
|
|
451
|
+
checkBufferLength(this);
|
|
452
|
+
}
|
|
533
453
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
console.log('-- emit', event, data);
|
|
454
|
+
this.emit('onchunkparsed');
|
|
455
|
+
return this;
|
|
537
456
|
}
|
|
538
457
|
|
|
539
|
-
|
|
540
|
-
|
|
458
|
+
_closeValue(event = 'onvalue') {
|
|
459
|
+
if (this.textNode !== undefined) {
|
|
460
|
+
this.emit(event, this.textNode);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
this.textNode = undefined;
|
|
541
464
|
}
|
|
542
|
-
}
|
|
543
465
|
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
}
|
|
466
|
+
_closeNumber() {
|
|
467
|
+
if (this.numberNode) this.emit('onvalue', parseFloat(this.numberNode));
|
|
468
|
+
this.numberNode = '';
|
|
469
|
+
}
|
|
548
470
|
|
|
549
|
-
|
|
550
|
-
|
|
471
|
+
_error(message = '') {
|
|
472
|
+
this._closeValue();
|
|
551
473
|
|
|
552
|
-
|
|
553
|
-
|
|
474
|
+
message += "\nLine: ".concat(this.line, "\nColumn: ").concat(this.column, "\nChar: ").concat(this.c);
|
|
475
|
+
const error = new Error(message);
|
|
476
|
+
this.error = error;
|
|
477
|
+
this.emit('onerror', error);
|
|
554
478
|
}
|
|
555
479
|
|
|
556
|
-
parser.textNode = undefined;
|
|
557
480
|
}
|
|
558
481
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
482
|
+
exports.default = ClarinetParser;
|
|
483
|
+
|
|
484
|
+
function isWhitespace(c) {
|
|
485
|
+
return c === Char.carriageReturn || c === Char.lineFeed || c === Char.space || c === Char.tab;
|
|
562
486
|
}
|
|
563
487
|
|
|
564
|
-
function
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
}
|
|
488
|
+
function checkBufferLength(parser) {
|
|
489
|
+
const maxAllowed = Math.max(MAX_BUFFER_LENGTH, 10);
|
|
490
|
+
let maxActual = 0;
|
|
568
491
|
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
return text;
|
|
572
|
-
}
|
|
492
|
+
for (const buffer of ['textNode', 'numberNode']) {
|
|
493
|
+
const len = parser[buffer] === undefined ? 0 : parser[buffer].length;
|
|
573
494
|
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
parser.error = er;
|
|
579
|
-
emit(parser, 'onerror', er);
|
|
580
|
-
return parser;
|
|
581
|
-
}
|
|
495
|
+
if (len > maxAllowed) {
|
|
496
|
+
switch (buffer) {
|
|
497
|
+
case 'text':
|
|
498
|
+
break;
|
|
582
499
|
|
|
583
|
-
|
|
584
|
-
|
|
500
|
+
default:
|
|
501
|
+
parser._error("Max buffer length exceeded: ".concat(buffer));
|
|
502
|
+
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
maxActual = Math.max(maxActual, len);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
parser.bufferCheckPosition = MAX_BUFFER_LENGTH - maxActual + parser.position;
|
|
585
510
|
}
|
|
586
511
|
//# sourceMappingURL=clarinet.js.map
|