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