@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.
@@ -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
- const env = {};
8
- const EVENTS = ['value', 'string', 'key', 'openobject', 'closeobject', 'openarray', 'closearray', 'error', 'end', 'ready'];
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
- const MAX_BUFFER_LENGTH = Number.MAX_SAFE_INTEGER;
11
- const DEBUG = env.CDEBUG === 'debug';
12
- const buffers = {
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
- let S = 0;
17
- const STATE = {
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) STATE[STATE[s_]] = s_;
51
+ for (var s_ in STATE) {
52
+ STATE[STATE[s_]] = s_;
53
+ }
45
54
 
46
55
  S = STATE;
47
- const Char = {
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
- const maxAllowed = Math.max(MAX_BUFFER_LENGTH, 10);
80
- let maxActual = 0;
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
- class ClarinetParser {
105
- constructor(options = {}) {
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
- _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;
133
- }
134
-
135
- if ('onopenobject' in options) {
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
- if ('onkey' in options) {
140
- this.onkey = options.onkey;
141
- }
149
+ if ('onopenobject' in options) {
150
+ this.onopenobject = options.onopenobject;
151
+ }
142
152
 
143
- if ('oncloseobject' in options) {
144
- this.oncloseobject = options.oncloseobject;
145
- }
153
+ if ('onkey' in options) {
154
+ this.onkey = options.onkey;
155
+ }
146
156
 
147
- if ('onopenarray' in options) {
148
- this.onopenarray = options.onopenarray;
149
- }
157
+ if ('oncloseobject' in options) {
158
+ this.oncloseobject = options.oncloseobject;
159
+ }
150
160
 
151
- if ('onclosearray' in options) {
152
- this.onclosearray = options.onclosearray;
153
- }
161
+ if ('onopenarray' in options) {
162
+ this.onopenarray = options.onopenarray;
163
+ }
154
164
 
155
- if ('onvalue' in options) {
156
- this.onvalue = options.onvalue;
157
- }
165
+ if ('onclosearray' in options) {
166
+ this.onclosearray = options.onclosearray;
167
+ }
158
168
 
159
- if ('onerror' in options) {
160
- this.onerror = options.onerror;
161
- }
169
+ if ('onvalue' in options) {
170
+ this.onvalue = options.onvalue;
171
+ }
162
172
 
163
- if ('onend' in options) {
164
- this.onend = options.onend;
165
- }
173
+ if ('onerror' in options) {
174
+ this.onerror = options.onerror;
175
+ }
166
176
 
167
- if ('onchunkparsed' in options) {
168
- this.onchunkparsed = options.onchunkparsed;
169
- }
177
+ if ('onend' in options) {
178
+ this.onend = options.onend;
179
+ }
170
180
 
171
- emit(this, 'onready');
172
- }
181
+ if ('onchunkparsed' in options) {
182
+ this.onchunkparsed = options.onchunkparsed;
183
+ }
173
184
 
174
- _clearBuffers() {
175
- for (var buffer in buffers) {
176
- this[buffer] = buffers[buffer];
185
+ emit(this, 'onready');
177
186
  }
178
- }
179
-
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');
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
- if (this.closed) {
207
- return error(this, 'Cannot write after close. Assign an onready handler.');
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
- if (chunk === null) {
211
- return this.end();
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
- var i = 0,
215
- c = chunk.charCodeAt(0),
216
- p = this.p;
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 (p !== c) {
224
- this.p = p;
225
- } else {
226
- p = this.p;
229
+ if (chunk === null) {
230
+ return this.end();
227
231
  }
228
232
 
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');
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
- 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');
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
- } 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');
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
- continue;
300
- } else {
301
- this.stack.push(S.CLOSE_ARRAY);
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
- 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;
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
- } else {
348
- unicodeI++;
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
- if (!c) break STRING_BIGLOOP;
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
- if (c === Char.doubleQuote && !slashed) {
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
- this.textNode += chunk.substring(starti, i - 1);
357
- this.position += i - 1 - starti;
358
- break;
359
- }
451
+ } else error(this, 'Invalid true started with tru' + c);
360
452
 
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
- }
453
+ continue;
369
454
 
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
- }
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
- c = chunk.charCodeAt(i++);
391
- this.position++;
392
- starti = i - 1;
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
- stringTokenPattern.lastIndex = i;
397
- var reResult = stringTokenPattern.exec(chunk);
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
- 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
- }
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
- i = reResult.index + 1;
407
- c = chunk.charCodeAt(reResult.index);
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
- if (!c) {
410
- this.textNode += chunk.substring(starti, i - 1);
411
- this.position += i - 1 - starti;
412
- break;
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
- default:
498
- error(this, 'Unknown state: ' + this.state);
516
+ default:
517
+ error(this, 'Unknown state: ' + this.state);
518
+ }
499
519
  }
500
- }
501
520
 
502
- if (this.position >= this.bufferCheckPosition) {
503
- checkBufferLength(this);
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