@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.
@@ -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
- 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'];
7
+ const env = {};
8
+ const EVENTS = ['value', 'string', 'key', 'openobject', 'closeobject', 'openarray', 'closearray', 'error', 'end', 'ready'];
16
9
  exports.EVENTS = EVENTS;
17
- var MAX_BUFFER_LENGTH = Number.MAX_SAFE_INTEGER;
18
- var DEBUG = env.CDEBUG === 'debug';
19
- var buffers = {
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
- var S = 0;
24
- var STATE = {
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
- var Char = {
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
- var maxAllowed = Math.max(MAX_BUFFER_LENGTH, 10);
89
- var maxActual = 0;
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
- var ClarinetParser = function () {
114
- function ClarinetParser() {
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
- (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
- }
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
- key: "_clearBuffers",
189
- value: function _clearBuffers() {
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
- 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;
138
+
139
+ if ('onkey' in options) {
140
+ this.onkey = options.onkey;
206
141
  }
207
- }, {
208
- key: "resume",
209
- value: function resume() {
210
- this.error = null;
211
- return this;
142
+
143
+ if ('oncloseobject' in options) {
144
+ this.oncloseobject = options.oncloseobject;
212
145
  }
213
- }, {
214
- key: "close",
215
- value: function close() {
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
- if (this.closed) {
226
- return error(this, 'Cannot write after close. Assign an onready handler.');
227
- }
151
+ if ('onclosearray' in options) {
152
+ this.onclosearray = options.onclosearray;
153
+ }
228
154
 
229
- if (chunk === null) {
230
- return this.end();
231
- }
155
+ if ('onvalue' in options) {
156
+ this.onvalue = options.onvalue;
157
+ }
232
158
 
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');
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
- continue;
163
+ if ('onend' in options) {
164
+ this.onend = options.onend;
165
+ }
304
166
 
305
- case S.OPEN_ARRAY:
306
- case S.VALUE:
307
- if (isWhitespace(c)) continue;
167
+ if ('onchunkparsed' in options) {
168
+ this.onchunkparsed = options.onchunkparsed;
169
+ }
308
170
 
309
- if (this.state === S.OPEN_ARRAY) {
310
- emit(this, 'onopenarray');
311
- this.depth++;
312
- this.state = S.VALUE;
171
+ emit(this, 'onready');
172
+ }
313
173
 
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
- }
174
+ _clearBuffers() {
175
+ for (var buffer in buffers) {
176
+ this[buffer] = buffers[buffer];
177
+ }
178
+ }
323
179
 
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;
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
- 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');
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
- continue;
189
+ return this;
190
+ }
344
191
 
345
- case S.STRING:
346
- if (this.textNode === undefined) {
347
- this.textNode = '';
348
- }
192
+ resume() {
193
+ this.error = null;
194
+ return this;
195
+ }
349
196
 
350
- var starti = i - 1,
351
- slashed = this.slashed,
352
- unicodeI = this.unicodeI;
197
+ close() {
198
+ return this.write(null);
199
+ }
353
200
 
354
- STRING_BIGLOOP: while (true) {
355
- if (DEBUG) console.log(i, c, STATE[this.state], slashed);
201
+ write(chunk) {
202
+ if (this.error) {
203
+ throw this.error;
204
+ }
356
205
 
357
- while (unicodeI > 0) {
358
- this.unicodeS += String.fromCharCode(c);
359
- c = chunk.charCodeAt(i++);
360
- this.position++;
206
+ if (this.closed) {
207
+ return error(this, 'Cannot write after close. Assign an onready handler.');
208
+ }
361
209
 
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
- }
210
+ if (chunk === null) {
211
+ return this.end();
212
+ }
369
213
 
370
- if (!c) break STRING_BIGLOOP;
371
- }
214
+ var i = 0,
215
+ c = chunk.charCodeAt(0),
216
+ p = this.p;
217
+ if (DEBUG) console.log('write -> [' + chunk + ']');
372
218
 
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
- }
219
+ while (c) {
220
+ p = c;
221
+ this.c = c = chunk.charCodeAt(i++);
379
222
 
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
- }
223
+ if (p !== c) {
224
+ this.p = p;
225
+ } else {
226
+ p = this.p;
227
+ }
388
228
 
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++;
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
- 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;
347
+ } else {
348
+ unicodeI++;
423
349
  }
424
350
 
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
- }
351
+ if (!c) break STRING_BIGLOOP;
433
352
  }
434
353
 
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);
354
+ if (c === Char.doubleQuote && !slashed) {
450
355
  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;
356
+ this.textNode += chunk.substring(starti, i - 1);
357
+ this.position += i - 1 - starti;
358
+ break;
359
+ }
458
360
 
459
- case S.FALSE2:
460
- if (c === Char.l) this.state = S.FALSE3;else error(this, 'Invalid false started with fa' + c);
461
- continue;
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
- case S.FALSE3:
464
- if (c === Char.s) this.state = S.FALSE4;else error(this, 'Invalid false started with fal' + c);
465
- continue;
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
- 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);
390
+ c = chunk.charCodeAt(i++);
391
+ this.position++;
392
+ starti = i - 1;
393
+ if (!c) break;else continue;
394
+ }
472
395
 
473
- continue;
396
+ stringTokenPattern.lastIndex = i;
397
+ var reResult = stringTokenPattern.exec(chunk);
474
398
 
475
- case S.NULL:
476
- if (c === Char.u) this.state = S.NULL2;else error(this, 'Invalid null started with n' + c);
477
- continue;
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
- case S.NULL2:
480
- if (c === Char.l) this.state = S.NULL3;else error(this, 'Invalid null started with nu' + c);
481
- continue;
406
+ i = reResult.index + 1;
407
+ c = chunk.charCodeAt(reResult.index);
482
408
 
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;
409
+ if (!c) {
410
+ this.textNode += chunk.substring(starti, i - 1);
411
+ this.position += i - 1 - starti;
412
+ break;
513
413
  }
514
- continue;
515
-
516
- default:
517
- error(this, 'Unknown state: ' + this.state);
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
- if (this.position >= this.bufferCheckPosition) {
522
- checkBufferLength(this);
497
+ default:
498
+ error(this, 'Unknown state: ' + this.state);
523
499
  }
500
+ }
524
501
 
525
- emit(this, 'onchunkparsed');
526
- return this;
502
+ if (this.position >= this.bufferCheckPosition) {
503
+ checkBufferLength(this);
527
504
  }
528
- }]);
529
- return ClarinetParser;
530
- }();
505
+
506
+ emit(this, 'onchunkparsed');
507
+ return this;
508
+ }
509
+
510
+ }
531
511
 
532
512
  exports.default = ClarinetParser;
533
513