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