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