@loaders.gl/json 3.4.14 → 3.4.15
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/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/geojson-loader.js +34 -103
- package/dist/es5/geojson-loader.js.map +1 -1
- package/dist/es5/index.js +7 -7
- package/dist/es5/json-loader.js +22 -33
- package/dist/es5/json-loader.js.map +1 -1
- package/dist/es5/lib/clarinet/clarinet.js +295 -318
- package/dist/es5/lib/clarinet/clarinet.js.map +1 -1
- package/dist/es5/lib/jsonpath/jsonpath.js +44 -88
- package/dist/es5/lib/jsonpath/jsonpath.js.map +1 -1
- package/dist/es5/lib/parse-json-in-batches.js +74 -181
- package/dist/es5/lib/parse-json-in-batches.js.map +1 -1
- package/dist/es5/lib/parse-json.js +4 -7
- package/dist/es5/lib/parse-json.js.map +1 -1
- package/dist/es5/lib/parse-ndjson-in-batches.js +29 -103
- package/dist/es5/lib/parse-ndjson-in-batches.js.map +1 -1
- package/dist/es5/lib/parse-ndjson.js +2 -2
- package/dist/es5/lib/parse-ndjson.js.map +1 -1
- package/dist/es5/lib/parser/json-parser.js +84 -106
- package/dist/es5/lib/parser/json-parser.js.map +1 -1
- package/dist/es5/lib/parser/streaming-json-parser.js +52 -95
- package/dist/es5/lib/parser/streaming-json-parser.js.map +1 -1
- package/dist/es5/ndgeoson-loader.js +5 -23
- package/dist/es5/ndgeoson-loader.js.map +1 -1
- package/dist/es5/ndjson-loader.js +3 -21
- package/dist/es5/ndjson-loader.js.map +1 -1
- package/dist/esm/geojson-loader.js +1 -1
- package/dist/esm/json-loader.js +1 -1
- package/dist/esm/ndgeoson-loader.js +1 -1
- package/dist/esm/ndjson-loader.js +1 -1
- package/dist/geojson-worker.js +1 -1
- package/package.json +5 -5
|
@@ -5,12 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
13
|
-
var MAX_BUFFER_LENGTH = Number.MAX_SAFE_INTEGER;
|
|
9
|
+
const MAX_BUFFER_LENGTH = Number.MAX_SAFE_INTEGER;
|
|
14
10
|
var STATE = function (STATE) {
|
|
15
11
|
STATE[STATE["BEGIN"] = 0] = "BEGIN";
|
|
16
12
|
STATE[STATE["VALUE"] = 1] = "VALUE";
|
|
@@ -38,7 +34,7 @@ var STATE = function (STATE) {
|
|
|
38
34
|
STATE[STATE["NUMBER_DIGIT"] = 23] = "NUMBER_DIGIT";
|
|
39
35
|
return STATE;
|
|
40
36
|
}(STATE || {});
|
|
41
|
-
|
|
37
|
+
const Char = {
|
|
42
38
|
tab: 0x09,
|
|
43
39
|
lineFeed: 0x0a,
|
|
44
40
|
carriageReturn: 0x0d,
|
|
@@ -68,23 +64,22 @@ var Char = {
|
|
|
68
64
|
openBrace: 0x7b,
|
|
69
65
|
closeBrace: 0x7d
|
|
70
66
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
onready:
|
|
74
|
-
onopenobject:
|
|
75
|
-
onkey:
|
|
76
|
-
oncloseobject:
|
|
77
|
-
onopenarray:
|
|
78
|
-
onclosearray:
|
|
79
|
-
onvalue:
|
|
80
|
-
onerror:
|
|
81
|
-
onend:
|
|
82
|
-
onchunkparsed:
|
|
67
|
+
const stringTokenPattern = /[\\"\n]/g;
|
|
68
|
+
const DEFAULT_OPTIONS = {
|
|
69
|
+
onready: () => {},
|
|
70
|
+
onopenobject: () => {},
|
|
71
|
+
onkey: () => {},
|
|
72
|
+
oncloseobject: () => {},
|
|
73
|
+
onopenarray: () => {},
|
|
74
|
+
onclosearray: () => {},
|
|
75
|
+
onvalue: () => {},
|
|
76
|
+
onerror: () => {},
|
|
77
|
+
onend: () => {},
|
|
78
|
+
onchunkparsed: () => {}
|
|
83
79
|
};
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
(0, _classCallCheck2.default)(this, ClarinetParser);
|
|
80
|
+
class ClarinetParser {
|
|
81
|
+
constructor() {
|
|
82
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
88
83
|
(0, _defineProperty2.default)(this, "options", DEFAULT_OPTIONS);
|
|
89
84
|
(0, _defineProperty2.default)(this, "bufferCheckPosition", MAX_BUFFER_LENGTH);
|
|
90
85
|
(0, _defineProperty2.default)(this, "q", '');
|
|
@@ -105,332 +100,314 @@ var ClarinetParser = function () {
|
|
|
105
100
|
(0, _defineProperty2.default)(this, "depth", 0);
|
|
106
101
|
(0, _defineProperty2.default)(this, "textNode", void 0);
|
|
107
102
|
(0, _defineProperty2.default)(this, "numberNode", void 0);
|
|
108
|
-
this.options =
|
|
103
|
+
this.options = {
|
|
104
|
+
...DEFAULT_OPTIONS,
|
|
105
|
+
...options
|
|
106
|
+
};
|
|
109
107
|
this.textNode = undefined;
|
|
110
108
|
this.numberNode = '';
|
|
111
109
|
this.emit('onready');
|
|
112
110
|
}
|
|
113
|
-
(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
111
|
+
end() {
|
|
112
|
+
if (this.state !== STATE.VALUE || this.depth !== 0) this._error('Unexpected end');
|
|
113
|
+
this._closeValue();
|
|
114
|
+
this.c = '';
|
|
115
|
+
this.closed = true;
|
|
116
|
+
this.emit('onend');
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
resume() {
|
|
120
|
+
this.error = null;
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
close() {
|
|
124
|
+
return this.write(null);
|
|
125
|
+
}
|
|
126
|
+
emit(event, data) {
|
|
127
|
+
var _this$options$event, _this$options;
|
|
128
|
+
(_this$options$event = (_this$options = this.options)[event]) === null || _this$options$event === void 0 ? void 0 : _this$options$event.call(_this$options, data, this);
|
|
129
|
+
}
|
|
130
|
+
emitNode(event, data) {
|
|
131
|
+
this._closeValue();
|
|
132
|
+
this.emit(event, data);
|
|
133
|
+
}
|
|
134
|
+
write(chunk) {
|
|
135
|
+
if (this.error) {
|
|
136
|
+
throw this.error;
|
|
133
137
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
value: function emit(event, data) {
|
|
137
|
-
var _this$options$event, _this$options;
|
|
138
|
-
(_this$options$event = (_this$options = this.options)[event]) === null || _this$options$event === void 0 ? void 0 : _this$options$event.call(_this$options, data, this);
|
|
138
|
+
if (this.closed) {
|
|
139
|
+
return this._error('Cannot write after close. Assign an onready handler.');
|
|
139
140
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
value: function emitNode(event, data) {
|
|
143
|
-
this._closeValue();
|
|
144
|
-
this.emit(event, data);
|
|
141
|
+
if (chunk === null) {
|
|
142
|
+
return this.end();
|
|
145
143
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if (
|
|
153
|
-
|
|
144
|
+
let i = 0;
|
|
145
|
+
let c = chunk.charCodeAt(0);
|
|
146
|
+
let p = this.p;
|
|
147
|
+
while (c) {
|
|
148
|
+
p = c;
|
|
149
|
+
this.c = c = chunk.charCodeAt(i++);
|
|
150
|
+
if (p !== c) {
|
|
151
|
+
this.p = p;
|
|
152
|
+
} else {
|
|
153
|
+
p = this.p;
|
|
154
154
|
}
|
|
155
|
-
if (
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
case STATE.BEGIN:
|
|
177
|
-
if (c === Char.openBrace) this.state = STATE.OPEN_OBJECT;else if (c === Char.openBracket) this.state = STATE.OPEN_ARRAY;else if (!isWhitespace(c)) {
|
|
178
|
-
this._error('Non-whitespace before {[.');
|
|
179
|
-
}
|
|
155
|
+
if (!c) break;
|
|
156
|
+
this.position++;
|
|
157
|
+
if (c === Char.lineFeed) {
|
|
158
|
+
this.line++;
|
|
159
|
+
this.column = 0;
|
|
160
|
+
} else this.column++;
|
|
161
|
+
switch (this.state) {
|
|
162
|
+
case STATE.BEGIN:
|
|
163
|
+
if (c === Char.openBrace) this.state = STATE.OPEN_OBJECT;else if (c === Char.openBracket) this.state = STATE.OPEN_ARRAY;else if (!isWhitespace(c)) {
|
|
164
|
+
this._error('Non-whitespace before {[.');
|
|
165
|
+
}
|
|
166
|
+
continue;
|
|
167
|
+
case STATE.OPEN_KEY:
|
|
168
|
+
case STATE.OPEN_OBJECT:
|
|
169
|
+
if (isWhitespace(c)) continue;
|
|
170
|
+
if (this.state === STATE.OPEN_KEY) this.stack.push(STATE.CLOSE_KEY);else if (c === Char.closeBrace) {
|
|
171
|
+
this.emit('onopenobject');
|
|
172
|
+
this.depth++;
|
|
173
|
+
this.emit('oncloseobject');
|
|
174
|
+
this.depth--;
|
|
175
|
+
this.state = this.stack.pop() || STATE.VALUE;
|
|
180
176
|
continue;
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
177
|
+
} else this.stack.push(STATE.CLOSE_OBJECT);
|
|
178
|
+
if (c === Char.doubleQuote) this.state = STATE.STRING;else this._error('Malformed object key should start with "');
|
|
179
|
+
continue;
|
|
180
|
+
case STATE.CLOSE_KEY:
|
|
181
|
+
case STATE.CLOSE_OBJECT:
|
|
182
|
+
if (isWhitespace(c)) continue;
|
|
183
|
+
if (c === Char.colon) {
|
|
184
|
+
if (this.state === STATE.CLOSE_OBJECT) {
|
|
185
|
+
this.stack.push(STATE.CLOSE_OBJECT);
|
|
186
|
+
this._closeValue('onopenobject');
|
|
186
187
|
this.depth++;
|
|
187
|
-
|
|
188
|
+
} else this._closeValue('onkey');
|
|
189
|
+
this.state = STATE.VALUE;
|
|
190
|
+
} else if (c === Char.closeBrace) {
|
|
191
|
+
this.emitNode('oncloseobject');
|
|
192
|
+
this.depth--;
|
|
193
|
+
this.state = this.stack.pop() || STATE.VALUE;
|
|
194
|
+
} else if (c === Char.comma) {
|
|
195
|
+
if (this.state === STATE.CLOSE_OBJECT) this.stack.push(STATE.CLOSE_OBJECT);
|
|
196
|
+
this._closeValue();
|
|
197
|
+
this.state = STATE.OPEN_KEY;
|
|
198
|
+
} else this._error('Bad object');
|
|
199
|
+
continue;
|
|
200
|
+
case STATE.OPEN_ARRAY:
|
|
201
|
+
case STATE.VALUE:
|
|
202
|
+
if (isWhitespace(c)) continue;
|
|
203
|
+
if (this.state === STATE.OPEN_ARRAY) {
|
|
204
|
+
this.emit('onopenarray');
|
|
205
|
+
this.depth++;
|
|
206
|
+
this.state = STATE.VALUE;
|
|
207
|
+
if (c === Char.closeBracket) {
|
|
208
|
+
this.emit('onclosearray');
|
|
188
209
|
this.depth--;
|
|
189
210
|
this.state = this.stack.pop() || STATE.VALUE;
|
|
190
211
|
continue;
|
|
191
|
-
} else
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
212
|
+
} else {
|
|
213
|
+
this.stack.push(STATE.CLOSE_ARRAY);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
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) {
|
|
217
|
+
this.numberNode += '-';
|
|
218
|
+
} else if (Char._0 <= c && c <= Char._9) {
|
|
219
|
+
this.numberNode += String.fromCharCode(c);
|
|
220
|
+
this.state = STATE.NUMBER_DIGIT;
|
|
221
|
+
} else this._error('Bad value');
|
|
222
|
+
continue;
|
|
223
|
+
case STATE.CLOSE_ARRAY:
|
|
224
|
+
if (c === Char.comma) {
|
|
225
|
+
this.stack.push(STATE.CLOSE_ARRAY);
|
|
226
|
+
this._closeValue('onvalue');
|
|
227
|
+
this.state = STATE.VALUE;
|
|
228
|
+
} else if (c === Char.closeBracket) {
|
|
229
|
+
this.emitNode('onclosearray');
|
|
230
|
+
this.depth--;
|
|
231
|
+
this.state = this.stack.pop() || STATE.VALUE;
|
|
232
|
+
} else if (isWhitespace(c)) continue;else this._error('Bad array');
|
|
233
|
+
continue;
|
|
234
|
+
case STATE.STRING:
|
|
235
|
+
if (this.textNode === undefined) {
|
|
236
|
+
this.textNode = '';
|
|
237
|
+
}
|
|
238
|
+
let starti = i - 1;
|
|
239
|
+
let slashed = this.slashed;
|
|
240
|
+
let unicodeI = this.unicodeI;
|
|
241
|
+
STRING_BIGLOOP: while (true) {
|
|
242
|
+
while (unicodeI > 0) {
|
|
243
|
+
this.unicodeS += String.fromCharCode(c);
|
|
244
|
+
c = chunk.charCodeAt(i++);
|
|
245
|
+
this.position++;
|
|
246
|
+
if (unicodeI === 4) {
|
|
247
|
+
this.textNode += String.fromCharCode(parseInt(this.unicodeS, 16));
|
|
248
|
+
unicodeI = 0;
|
|
249
|
+
starti = i - 1;
|
|
226
250
|
} else {
|
|
227
|
-
|
|
251
|
+
unicodeI++;
|
|
228
252
|
}
|
|
253
|
+
if (!c) break STRING_BIGLOOP;
|
|
229
254
|
}
|
|
230
|
-
if (c === Char.doubleQuote
|
|
231
|
-
this.numberNode += '-';
|
|
232
|
-
} else if (Char._0 <= c && c <= Char._9) {
|
|
233
|
-
this.numberNode += String.fromCharCode(c);
|
|
234
|
-
this.state = STATE.NUMBER_DIGIT;
|
|
235
|
-
} else this._error('Bad value');
|
|
236
|
-
continue;
|
|
237
|
-
case STATE.CLOSE_ARRAY:
|
|
238
|
-
if (c === Char.comma) {
|
|
239
|
-
this.stack.push(STATE.CLOSE_ARRAY);
|
|
240
|
-
this._closeValue('onvalue');
|
|
241
|
-
this.state = STATE.VALUE;
|
|
242
|
-
} else if (c === Char.closeBracket) {
|
|
243
|
-
this.emitNode('onclosearray');
|
|
244
|
-
this.depth--;
|
|
255
|
+
if (c === Char.doubleQuote && !slashed) {
|
|
245
256
|
this.state = this.stack.pop() || STATE.VALUE;
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
if (this.textNode === undefined) {
|
|
250
|
-
this.textNode = '';
|
|
257
|
+
this.textNode += chunk.substring(starti, i - 1);
|
|
258
|
+
this.position += i - 1 - starti;
|
|
259
|
+
break;
|
|
251
260
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
this.textNode +=
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
this.textNode += chunk.substring(starti, i - 1);
|
|
278
|
-
this.position += i - 1 - starti;
|
|
279
|
-
c = chunk.charCodeAt(i++);
|
|
280
|
-
this.position++;
|
|
281
|
-
if (!c) break;
|
|
282
|
-
}
|
|
283
|
-
if (slashed) {
|
|
284
|
-
slashed = false;
|
|
285
|
-
if (c === Char.n) {
|
|
286
|
-
this.textNode += '\n';
|
|
287
|
-
} else if (c === Char.r) {
|
|
288
|
-
this.textNode += '\r';
|
|
289
|
-
} else if (c === Char.t) {
|
|
290
|
-
this.textNode += '\t';
|
|
291
|
-
} else if (c === Char.f) {
|
|
292
|
-
this.textNode += '\f';
|
|
293
|
-
} else if (c === Char.b) {
|
|
294
|
-
this.textNode += '\b';
|
|
295
|
-
} else if (c === Char.u) {
|
|
296
|
-
unicodeI = 1;
|
|
297
|
-
this.unicodeS = '';
|
|
298
|
-
} else {
|
|
299
|
-
this.textNode += String.fromCharCode(c);
|
|
300
|
-
}
|
|
301
|
-
c = chunk.charCodeAt(i++);
|
|
302
|
-
this.position++;
|
|
303
|
-
starti = i - 1;
|
|
304
|
-
if (!c) break;else continue;
|
|
305
|
-
}
|
|
306
|
-
stringTokenPattern.lastIndex = i;
|
|
307
|
-
var reResult = stringTokenPattern.exec(chunk);
|
|
308
|
-
if (reResult === null) {
|
|
309
|
-
i = chunk.length + 1;
|
|
310
|
-
this.textNode += chunk.substring(starti, i - 1);
|
|
311
|
-
this.position += i - 1 - starti;
|
|
312
|
-
break;
|
|
313
|
-
}
|
|
314
|
-
i = reResult.index + 1;
|
|
315
|
-
c = chunk.charCodeAt(reResult.index);
|
|
316
|
-
if (!c) {
|
|
317
|
-
this.textNode += chunk.substring(starti, i - 1);
|
|
318
|
-
this.position += i - 1 - starti;
|
|
319
|
-
break;
|
|
261
|
+
if (c === Char.backslash && !slashed) {
|
|
262
|
+
slashed = true;
|
|
263
|
+
this.textNode += chunk.substring(starti, i - 1);
|
|
264
|
+
this.position += i - 1 - starti;
|
|
265
|
+
c = chunk.charCodeAt(i++);
|
|
266
|
+
this.position++;
|
|
267
|
+
if (!c) break;
|
|
268
|
+
}
|
|
269
|
+
if (slashed) {
|
|
270
|
+
slashed = false;
|
|
271
|
+
if (c === Char.n) {
|
|
272
|
+
this.textNode += '\n';
|
|
273
|
+
} else if (c === Char.r) {
|
|
274
|
+
this.textNode += '\r';
|
|
275
|
+
} else if (c === Char.t) {
|
|
276
|
+
this.textNode += '\t';
|
|
277
|
+
} else if (c === Char.f) {
|
|
278
|
+
this.textNode += '\f';
|
|
279
|
+
} else if (c === Char.b) {
|
|
280
|
+
this.textNode += '\b';
|
|
281
|
+
} else if (c === Char.u) {
|
|
282
|
+
unicodeI = 1;
|
|
283
|
+
this.unicodeS = '';
|
|
284
|
+
} else {
|
|
285
|
+
this.textNode += String.fromCharCode(c);
|
|
320
286
|
}
|
|
287
|
+
c = chunk.charCodeAt(i++);
|
|
288
|
+
this.position++;
|
|
289
|
+
starti = i - 1;
|
|
290
|
+
if (!c) break;else continue;
|
|
321
291
|
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
if (c === Char.u) this.state = STATE.TRUE3;else this._error("Invalid true started with tr".concat(c));
|
|
330
|
-
continue;
|
|
331
|
-
case STATE.TRUE3:
|
|
332
|
-
if (c === Char.e) {
|
|
333
|
-
this.emit('onvalue', true);
|
|
334
|
-
this.state = this.stack.pop() || STATE.VALUE;
|
|
335
|
-
} else this._error("Invalid true started with tru".concat(c));
|
|
336
|
-
continue;
|
|
337
|
-
case STATE.FALSE:
|
|
338
|
-
if (c === Char.a) this.state = STATE.FALSE2;else this._error("Invalid false started with f".concat(c));
|
|
339
|
-
continue;
|
|
340
|
-
case STATE.FALSE2:
|
|
341
|
-
if (c === Char.l) this.state = STATE.FALSE3;else this._error("Invalid false started with fa".concat(c));
|
|
342
|
-
continue;
|
|
343
|
-
case STATE.FALSE3:
|
|
344
|
-
if (c === Char.s) this.state = STATE.FALSE4;else this._error("Invalid false started with fal".concat(c));
|
|
345
|
-
continue;
|
|
346
|
-
case STATE.FALSE4:
|
|
347
|
-
if (c === Char.e) {
|
|
348
|
-
this.emit('onvalue', false);
|
|
349
|
-
this.state = this.stack.pop() || STATE.VALUE;
|
|
350
|
-
} else this._error("Invalid false started with fals".concat(c));
|
|
351
|
-
continue;
|
|
352
|
-
case STATE.NULL:
|
|
353
|
-
if (c === Char.u) this.state = STATE.NULL2;else this._error("Invalid null started with n".concat(c));
|
|
354
|
-
continue;
|
|
355
|
-
case STATE.NULL2:
|
|
356
|
-
if (c === Char.l) this.state = STATE.NULL3;else this._error("Invalid null started with nu".concat(c));
|
|
357
|
-
continue;
|
|
358
|
-
case STATE.NULL3:
|
|
359
|
-
if (c === Char.l) {
|
|
360
|
-
this.emit('onvalue', null);
|
|
361
|
-
this.state = this.stack.pop() || STATE.VALUE;
|
|
362
|
-
} else this._error("Invalid null started with nul".concat(c));
|
|
363
|
-
continue;
|
|
364
|
-
case STATE.NUMBER_DECIMAL_POINT:
|
|
365
|
-
if (c === Char.period) {
|
|
366
|
-
this.numberNode += '.';
|
|
367
|
-
this.state = STATE.NUMBER_DIGIT;
|
|
368
|
-
} else this._error('Leading zero not followed by .');
|
|
369
|
-
continue;
|
|
370
|
-
case STATE.NUMBER_DIGIT:
|
|
371
|
-
if (Char._0 <= c && c <= Char._9) this.numberNode += String.fromCharCode(c);else if (c === Char.period) {
|
|
372
|
-
if (this.numberNode.indexOf('.') !== -1) this._error('Invalid number has two dots');
|
|
373
|
-
this.numberNode += '.';
|
|
374
|
-
} else if (c === Char.e || c === Char.E) {
|
|
375
|
-
if (this.numberNode.indexOf('e') !== -1 || this.numberNode.indexOf('E') !== -1) this._error('Invalid number has two exponential');
|
|
376
|
-
this.numberNode += 'e';
|
|
377
|
-
} else if (c === Char.plus || c === Char.minus) {
|
|
378
|
-
if (!(p === Char.e || p === Char.E)) this._error('Invalid symbol in number');
|
|
379
|
-
this.numberNode += String.fromCharCode(c);
|
|
380
|
-
} else {
|
|
381
|
-
this._closeNumber();
|
|
382
|
-
i--;
|
|
383
|
-
this.state = this.stack.pop() || STATE.VALUE;
|
|
292
|
+
stringTokenPattern.lastIndex = i;
|
|
293
|
+
const reResult = stringTokenPattern.exec(chunk);
|
|
294
|
+
if (reResult === null) {
|
|
295
|
+
i = chunk.length + 1;
|
|
296
|
+
this.textNode += chunk.substring(starti, i - 1);
|
|
297
|
+
this.position += i - 1 - starti;
|
|
298
|
+
break;
|
|
384
299
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
300
|
+
i = reResult.index + 1;
|
|
301
|
+
c = chunk.charCodeAt(reResult.index);
|
|
302
|
+
if (!c) {
|
|
303
|
+
this.textNode += chunk.substring(starti, i - 1);
|
|
304
|
+
this.position += i - 1 - starti;
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
this.slashed = slashed;
|
|
309
|
+
this.unicodeI = unicodeI;
|
|
310
|
+
continue;
|
|
311
|
+
case STATE.TRUE:
|
|
312
|
+
if (c === Char.r) this.state = STATE.TRUE2;else this._error("Invalid true started with t".concat(c));
|
|
313
|
+
continue;
|
|
314
|
+
case STATE.TRUE2:
|
|
315
|
+
if (c === Char.u) this.state = STATE.TRUE3;else this._error("Invalid true started with tr".concat(c));
|
|
316
|
+
continue;
|
|
317
|
+
case STATE.TRUE3:
|
|
318
|
+
if (c === Char.e) {
|
|
319
|
+
this.emit('onvalue', true);
|
|
320
|
+
this.state = this.stack.pop() || STATE.VALUE;
|
|
321
|
+
} else this._error("Invalid true started with tru".concat(c));
|
|
322
|
+
continue;
|
|
323
|
+
case STATE.FALSE:
|
|
324
|
+
if (c === Char.a) this.state = STATE.FALSE2;else this._error("Invalid false started with f".concat(c));
|
|
325
|
+
continue;
|
|
326
|
+
case STATE.FALSE2:
|
|
327
|
+
if (c === Char.l) this.state = STATE.FALSE3;else this._error("Invalid false started with fa".concat(c));
|
|
328
|
+
continue;
|
|
329
|
+
case STATE.FALSE3:
|
|
330
|
+
if (c === Char.s) this.state = STATE.FALSE4;else this._error("Invalid false started with fal".concat(c));
|
|
331
|
+
continue;
|
|
332
|
+
case STATE.FALSE4:
|
|
333
|
+
if (c === Char.e) {
|
|
334
|
+
this.emit('onvalue', false);
|
|
335
|
+
this.state = this.stack.pop() || STATE.VALUE;
|
|
336
|
+
} else this._error("Invalid false started with fals".concat(c));
|
|
337
|
+
continue;
|
|
338
|
+
case STATE.NULL:
|
|
339
|
+
if (c === Char.u) this.state = STATE.NULL2;else this._error("Invalid null started with n".concat(c));
|
|
340
|
+
continue;
|
|
341
|
+
case STATE.NULL2:
|
|
342
|
+
if (c === Char.l) this.state = STATE.NULL3;else this._error("Invalid null started with nu".concat(c));
|
|
343
|
+
continue;
|
|
344
|
+
case STATE.NULL3:
|
|
345
|
+
if (c === Char.l) {
|
|
346
|
+
this.emit('onvalue', null);
|
|
347
|
+
this.state = this.stack.pop() || STATE.VALUE;
|
|
348
|
+
} else this._error("Invalid null started with nul".concat(c));
|
|
349
|
+
continue;
|
|
350
|
+
case STATE.NUMBER_DECIMAL_POINT:
|
|
351
|
+
if (c === Char.period) {
|
|
352
|
+
this.numberNode += '.';
|
|
353
|
+
this.state = STATE.NUMBER_DIGIT;
|
|
354
|
+
} else this._error('Leading zero not followed by .');
|
|
355
|
+
continue;
|
|
356
|
+
case STATE.NUMBER_DIGIT:
|
|
357
|
+
if (Char._0 <= c && c <= Char._9) this.numberNode += String.fromCharCode(c);else if (c === Char.period) {
|
|
358
|
+
if (this.numberNode.indexOf('.') !== -1) this._error('Invalid number has two dots');
|
|
359
|
+
this.numberNode += '.';
|
|
360
|
+
} else if (c === Char.e || c === Char.E) {
|
|
361
|
+
if (this.numberNode.indexOf('e') !== -1 || this.numberNode.indexOf('E') !== -1) this._error('Invalid number has two exponential');
|
|
362
|
+
this.numberNode += 'e';
|
|
363
|
+
} else if (c === Char.plus || c === Char.minus) {
|
|
364
|
+
if (!(p === Char.e || p === Char.E)) this._error('Invalid symbol in number');
|
|
365
|
+
this.numberNode += String.fromCharCode(c);
|
|
366
|
+
} else {
|
|
367
|
+
this._closeNumber();
|
|
368
|
+
i--;
|
|
369
|
+
this.state = this.stack.pop() || STATE.VALUE;
|
|
370
|
+
}
|
|
371
|
+
continue;
|
|
372
|
+
default:
|
|
373
|
+
this._error("Unknown state: ".concat(this.state));
|
|
402
374
|
}
|
|
403
|
-
this.textNode = undefined;
|
|
404
375
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
value: function _closeNumber() {
|
|
408
|
-
if (this.numberNode) this.emit('onvalue', parseFloat(this.numberNode));
|
|
409
|
-
this.numberNode = '';
|
|
376
|
+
if (this.position >= this.bufferCheckPosition) {
|
|
377
|
+
checkBufferLength(this);
|
|
410
378
|
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
this.error = error;
|
|
419
|
-
this.emit('onerror', error);
|
|
379
|
+
this.emit('onchunkparsed');
|
|
380
|
+
return this;
|
|
381
|
+
}
|
|
382
|
+
_closeValue() {
|
|
383
|
+
let event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'onvalue';
|
|
384
|
+
if (this.textNode !== undefined) {
|
|
385
|
+
this.emit(event, this.textNode);
|
|
420
386
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
387
|
+
this.textNode = undefined;
|
|
388
|
+
}
|
|
389
|
+
_closeNumber() {
|
|
390
|
+
if (this.numberNode) this.emit('onvalue', parseFloat(this.numberNode));
|
|
391
|
+
this.numberNode = '';
|
|
392
|
+
}
|
|
393
|
+
_error() {
|
|
394
|
+
let message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
395
|
+
this._closeValue();
|
|
396
|
+
message += "\nLine: ".concat(this.line, "\nColumn: ").concat(this.column, "\nChar: ").concat(this.c);
|
|
397
|
+
const error = new Error(message);
|
|
398
|
+
this.error = error;
|
|
399
|
+
this.emit('onerror', error);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
424
402
|
exports.default = ClarinetParser;
|
|
425
403
|
function isWhitespace(c) {
|
|
426
404
|
return c === Char.carriageReturn || c === Char.lineFeed || c === Char.space || c === Char.tab;
|
|
427
405
|
}
|
|
428
406
|
function checkBufferLength(parser) {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
for (
|
|
432
|
-
|
|
433
|
-
var len = parser[buffer] === undefined ? 0 : parser[buffer].length;
|
|
407
|
+
const maxAllowed = Math.max(MAX_BUFFER_LENGTH, 10);
|
|
408
|
+
let maxActual = 0;
|
|
409
|
+
for (const buffer of ['textNode', 'numberNode']) {
|
|
410
|
+
const len = parser[buffer] === undefined ? 0 : parser[buffer].length;
|
|
434
411
|
if (len > maxAllowed) {
|
|
435
412
|
switch (buffer) {
|
|
436
413
|
case 'text':
|