@loaders.gl/json 3.1.3 → 4.0.0-alpha.5
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 -2
- package/dist/bundle.js.map +1 -0
- package/dist/geojson-loader.js +69 -66
- package/dist/geojson-loader.js.map +1 -0
- package/dist/geojson-worker.js +1 -1
- package/dist/index.js +7 -19
- package/dist/index.js.map +1 -0
- package/dist/json-loader.js +38 -48
- package/dist/json-loader.js.map +1 -0
- package/dist/jsonl-loader.js +1 -53
- package/dist/{es5/jsonl-loader.js.map → jsonl-loader.js.map} +0 -0
- package/dist/{es5/lib → lib}/clarinet/LICENSE +0 -0
- package/dist/lib/clarinet/clarinet.js +493 -510
- package/dist/lib/clarinet/clarinet.js.map +1 -0
- package/dist/lib/jsonpath/jsonpath.js +78 -81
- package/dist/lib/jsonpath/jsonpath.js.map +1 -0
- package/dist/lib/parse-json-in-batches.js +98 -94
- package/dist/lib/parse-json-in-batches.js.map +1 -0
- package/dist/lib/parse-json.js +29 -24
- package/dist/lib/parse-json.js.map +1 -0
- package/dist/lib/parse-ndjson-in-batches.js +34 -32
- package/dist/lib/parse-ndjson-in-batches.js.map +1 -0
- package/dist/lib/parse-ndjson.js +10 -13
- package/dist/lib/parse-ndjson.js.map +1 -0
- package/dist/lib/parser/json-parser.js +125 -95
- package/dist/lib/parser/json-parser.js.map +1 -0
- package/dist/lib/parser/streaming-json-parser.js +88 -95
- package/dist/lib/parser/streaming-json-parser.js.map +1 -0
- package/dist/ndjson-loader.js +25 -28
- package/dist/ndjson-loader.js.map +1 -0
- package/dist/workers/geojson-worker.js +4 -5
- package/dist/workers/geojson-worker.js.map +1 -0
- package/package.json +8 -8
- package/dist/es5/bundle.js +0 -7
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/geojson-loader.js +0 -209
- package/dist/es5/geojson-loader.js.map +0 -1
- package/dist/es5/index.js +0 -62
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/json-loader.js +0 -85
- package/dist/es5/json-loader.js.map +0 -1
- package/dist/es5/jsonl-loader.js +0 -2
- package/dist/es5/lib/clarinet/clarinet.js +0 -535
- package/dist/es5/lib/clarinet/clarinet.js.map +0 -1
- package/dist/es5/lib/jsonpath/jsonpath.js +0 -144
- package/dist/es5/lib/jsonpath/jsonpath.js.map +0 -1
- package/dist/es5/lib/parse-json-in-batches.js +0 -278
- package/dist/es5/lib/parse-json-in-batches.js.map +0 -1
- package/dist/es5/lib/parse-json.js +0 -46
- package/dist/es5/lib/parse-json.js.map +0 -1
- package/dist/es5/lib/parse-ndjson-in-batches.js +0 -158
- package/dist/es5/lib/parse-ndjson-in-batches.js.map +0 -1
- package/dist/es5/lib/parse-ndjson.js +0 -18
- package/dist/es5/lib/parse-ndjson.js.map +0 -1
- package/dist/es5/lib/parser/json-parser.js +0 -159
- package/dist/es5/lib/parser/json-parser.js.map +0 -1
- package/dist/es5/lib/parser/streaming-json-parser.js +0 -158
- package/dist/es5/lib/parser/streaming-json-parser.js.map +0 -1
- package/dist/es5/ndjson-loader.js +0 -67
- package/dist/es5/ndjson-loader.js.map +0 -1
- package/dist/es5/workers/geojson-worker.js +0 -8
- package/dist/es5/workers/geojson-worker.js.map +0 -1
- package/dist/esm/bundle.js +0 -5
- package/dist/esm/bundle.js.map +0 -1
- package/dist/esm/geojson-loader.js +0 -81
- package/dist/esm/geojson-loader.js.map +0 -1
- package/dist/esm/index.js +0 -7
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/json-loader.js +0 -47
- package/dist/esm/json-loader.js.map +0 -1
- package/dist/esm/jsonl-loader.js +0 -2
- package/dist/esm/jsonl-loader.js.map +0 -1
- package/dist/esm/lib/clarinet/LICENSE +0 -28
- package/dist/esm/lib/clarinet/clarinet.js +0 -518
- package/dist/esm/lib/clarinet/clarinet.js.map +0 -1
- package/dist/esm/lib/jsonpath/jsonpath.js +0 -86
- package/dist/esm/lib/jsonpath/jsonpath.js.map +0 -1
- package/dist/esm/lib/parse-json-in-batches.js +0 -104
- package/dist/esm/lib/parse-json-in-batches.js.map +0 -1
- package/dist/esm/lib/parse-json.js +0 -34
- package/dist/esm/lib/parse-json.js.map +0 -1
- package/dist/esm/lib/parse-ndjson-in-batches.js +0 -37
- package/dist/esm/lib/parse-ndjson-in-batches.js.map +0 -1
- package/dist/esm/lib/parse-ndjson.js +0 -11
- package/dist/esm/lib/parse-ndjson.js.map +0 -1
- package/dist/esm/lib/parser/json-parser.js +0 -128
- package/dist/esm/lib/parser/json-parser.js.map +0 -1
- package/dist/esm/lib/parser/streaming-json-parser.js +0 -93
- package/dist/esm/lib/parser/streaming-json-parser.js.map +0 -1
- package/dist/esm/ndjson-loader.js +0 -32
- package/dist/esm/ndjson-loader.js.map +0 -1
- package/dist/esm/workers/geojson-worker.js +0 -4
- package/dist/esm/workers/geojson-worker.js.map +0 -1
|
@@ -1,535 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = 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 _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
-
|
|
16
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
17
|
-
|
|
18
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
19
|
-
|
|
20
|
-
var MAX_BUFFER_LENGTH = Number.MAX_SAFE_INTEGER;
|
|
21
|
-
var STATE;
|
|
22
|
-
|
|
23
|
-
(function (STATE) {
|
|
24
|
-
STATE[STATE["BEGIN"] = 0] = "BEGIN";
|
|
25
|
-
STATE[STATE["VALUE"] = 1] = "VALUE";
|
|
26
|
-
STATE[STATE["OPEN_OBJECT"] = 2] = "OPEN_OBJECT";
|
|
27
|
-
STATE[STATE["CLOSE_OBJECT"] = 3] = "CLOSE_OBJECT";
|
|
28
|
-
STATE[STATE["OPEN_ARRAY"] = 4] = "OPEN_ARRAY";
|
|
29
|
-
STATE[STATE["CLOSE_ARRAY"] = 5] = "CLOSE_ARRAY";
|
|
30
|
-
STATE[STATE["TEXT_ESCAPE"] = 6] = "TEXT_ESCAPE";
|
|
31
|
-
STATE[STATE["STRING"] = 7] = "STRING";
|
|
32
|
-
STATE[STATE["BACKSLASH"] = 8] = "BACKSLASH";
|
|
33
|
-
STATE[STATE["END"] = 9] = "END";
|
|
34
|
-
STATE[STATE["OPEN_KEY"] = 10] = "OPEN_KEY";
|
|
35
|
-
STATE[STATE["CLOSE_KEY"] = 11] = "CLOSE_KEY";
|
|
36
|
-
STATE[STATE["TRUE"] = 12] = "TRUE";
|
|
37
|
-
STATE[STATE["TRUE2"] = 13] = "TRUE2";
|
|
38
|
-
STATE[STATE["TRUE3"] = 14] = "TRUE3";
|
|
39
|
-
STATE[STATE["FALSE"] = 15] = "FALSE";
|
|
40
|
-
STATE[STATE["FALSE2"] = 16] = "FALSE2";
|
|
41
|
-
STATE[STATE["FALSE3"] = 17] = "FALSE3";
|
|
42
|
-
STATE[STATE["FALSE4"] = 18] = "FALSE4";
|
|
43
|
-
STATE[STATE["NULL"] = 19] = "NULL";
|
|
44
|
-
STATE[STATE["NULL2"] = 20] = "NULL2";
|
|
45
|
-
STATE[STATE["NULL3"] = 21] = "NULL3";
|
|
46
|
-
STATE[STATE["NUMBER_DECIMAL_POINT"] = 22] = "NUMBER_DECIMAL_POINT";
|
|
47
|
-
STATE[STATE["NUMBER_DIGIT"] = 23] = "NUMBER_DIGIT";
|
|
48
|
-
})(STATE || (STATE = {}));
|
|
49
|
-
|
|
50
|
-
var Char = {
|
|
51
|
-
tab: 0x09,
|
|
52
|
-
lineFeed: 0x0a,
|
|
53
|
-
carriageReturn: 0x0d,
|
|
54
|
-
space: 0x20,
|
|
55
|
-
doubleQuote: 0x22,
|
|
56
|
-
plus: 0x2b,
|
|
57
|
-
comma: 0x2c,
|
|
58
|
-
minus: 0x2d,
|
|
59
|
-
period: 0x2e,
|
|
60
|
-
_0: 0x30,
|
|
61
|
-
_9: 0x39,
|
|
62
|
-
colon: 0x3a,
|
|
63
|
-
E: 0x45,
|
|
64
|
-
openBracket: 0x5b,
|
|
65
|
-
backslash: 0x5c,
|
|
66
|
-
closeBracket: 0x5d,
|
|
67
|
-
a: 0x61,
|
|
68
|
-
b: 0x62,
|
|
69
|
-
e: 0x65,
|
|
70
|
-
f: 0x66,
|
|
71
|
-
l: 0x6c,
|
|
72
|
-
n: 0x6e,
|
|
73
|
-
r: 0x72,
|
|
74
|
-
s: 0x73,
|
|
75
|
-
t: 0x74,
|
|
76
|
-
u: 0x75,
|
|
77
|
-
openBrace: 0x7b,
|
|
78
|
-
closeBrace: 0x7d
|
|
79
|
-
};
|
|
80
|
-
var stringTokenPattern = /[\\"\n]/g;
|
|
81
|
-
var DEFAULT_OPTIONS = {
|
|
82
|
-
onready: function onready() {},
|
|
83
|
-
onopenobject: function onopenobject() {},
|
|
84
|
-
onkey: function onkey() {},
|
|
85
|
-
oncloseobject: function oncloseobject() {},
|
|
86
|
-
onopenarray: function onopenarray() {},
|
|
87
|
-
onclosearray: function onclosearray() {},
|
|
88
|
-
onvalue: function onvalue() {},
|
|
89
|
-
onerror: function onerror() {},
|
|
90
|
-
onend: function onend() {},
|
|
91
|
-
onchunkparsed: function onchunkparsed() {}
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
var ClarinetParser = function () {
|
|
95
|
-
function ClarinetParser() {
|
|
96
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
97
|
-
(0, _classCallCheck2.default)(this, ClarinetParser);
|
|
98
|
-
(0, _defineProperty2.default)(this, "options", DEFAULT_OPTIONS);
|
|
99
|
-
(0, _defineProperty2.default)(this, "bufferCheckPosition", MAX_BUFFER_LENGTH);
|
|
100
|
-
(0, _defineProperty2.default)(this, "q", '');
|
|
101
|
-
(0, _defineProperty2.default)(this, "c", '');
|
|
102
|
-
(0, _defineProperty2.default)(this, "p", '');
|
|
103
|
-
(0, _defineProperty2.default)(this, "closed", false);
|
|
104
|
-
(0, _defineProperty2.default)(this, "closedRoot", false);
|
|
105
|
-
(0, _defineProperty2.default)(this, "sawRoot", false);
|
|
106
|
-
(0, _defineProperty2.default)(this, "error", null);
|
|
107
|
-
(0, _defineProperty2.default)(this, "state", STATE.BEGIN);
|
|
108
|
-
(0, _defineProperty2.default)(this, "stack", []);
|
|
109
|
-
(0, _defineProperty2.default)(this, "position", 0);
|
|
110
|
-
(0, _defineProperty2.default)(this, "column", 0);
|
|
111
|
-
(0, _defineProperty2.default)(this, "line", 1);
|
|
112
|
-
(0, _defineProperty2.default)(this, "slashed", false);
|
|
113
|
-
(0, _defineProperty2.default)(this, "unicodeI", 0);
|
|
114
|
-
(0, _defineProperty2.default)(this, "unicodeS", null);
|
|
115
|
-
(0, _defineProperty2.default)(this, "depth", 0);
|
|
116
|
-
(0, _defineProperty2.default)(this, "textNode", void 0);
|
|
117
|
-
(0, _defineProperty2.default)(this, "numberNode", void 0);
|
|
118
|
-
this.options = _objectSpread(_objectSpread({}, DEFAULT_OPTIONS), options);
|
|
119
|
-
this.textNode = undefined;
|
|
120
|
-
this.numberNode = '';
|
|
121
|
-
this.emit('onready');
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
(0, _createClass2.default)(ClarinetParser, [{
|
|
125
|
-
key: "end",
|
|
126
|
-
value: function end() {
|
|
127
|
-
if (this.state !== STATE.VALUE || this.depth !== 0) this._error('Unexpected end');
|
|
128
|
-
|
|
129
|
-
this._closeValue();
|
|
130
|
-
|
|
131
|
-
this.c = '';
|
|
132
|
-
this.closed = true;
|
|
133
|
-
this.emit('onend');
|
|
134
|
-
return this;
|
|
135
|
-
}
|
|
136
|
-
}, {
|
|
137
|
-
key: "resume",
|
|
138
|
-
value: function resume() {
|
|
139
|
-
this.error = null;
|
|
140
|
-
return this;
|
|
141
|
-
}
|
|
142
|
-
}, {
|
|
143
|
-
key: "close",
|
|
144
|
-
value: function close() {
|
|
145
|
-
return this.write(null);
|
|
146
|
-
}
|
|
147
|
-
}, {
|
|
148
|
-
key: "emit",
|
|
149
|
-
value: function emit(event, data) {
|
|
150
|
-
var _this$options$event, _this$options;
|
|
151
|
-
|
|
152
|
-
(_this$options$event = (_this$options = this.options)[event]) === null || _this$options$event === void 0 ? void 0 : _this$options$event.call(_this$options, data, this);
|
|
153
|
-
}
|
|
154
|
-
}, {
|
|
155
|
-
key: "emitNode",
|
|
156
|
-
value: function emitNode(event, data) {
|
|
157
|
-
this._closeValue();
|
|
158
|
-
|
|
159
|
-
this.emit(event, data);
|
|
160
|
-
}
|
|
161
|
-
}, {
|
|
162
|
-
key: "write",
|
|
163
|
-
value: function write(chunk) {
|
|
164
|
-
if (this.error) {
|
|
165
|
-
throw this.error;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (this.closed) {
|
|
169
|
-
return this._error('Cannot write after close. Assign an onready handler.');
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (chunk === null) {
|
|
173
|
-
return this.end();
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
var i = 0;
|
|
177
|
-
var c = chunk.charCodeAt(0);
|
|
178
|
-
var p = this.p;
|
|
179
|
-
|
|
180
|
-
while (c) {
|
|
181
|
-
p = c;
|
|
182
|
-
this.c = c = chunk.charCodeAt(i++);
|
|
183
|
-
|
|
184
|
-
if (p !== c) {
|
|
185
|
-
this.p = p;
|
|
186
|
-
} else {
|
|
187
|
-
p = this.p;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if (!c) break;
|
|
191
|
-
this.position++;
|
|
192
|
-
|
|
193
|
-
if (c === Char.lineFeed) {
|
|
194
|
-
this.line++;
|
|
195
|
-
this.column = 0;
|
|
196
|
-
} else this.column++;
|
|
197
|
-
|
|
198
|
-
switch (this.state) {
|
|
199
|
-
case STATE.BEGIN:
|
|
200
|
-
if (c === Char.openBrace) this.state = STATE.OPEN_OBJECT;else if (c === Char.openBracket) this.state = STATE.OPEN_ARRAY;else if (!isWhitespace(c)) {
|
|
201
|
-
this._error('Non-whitespace before {[.');
|
|
202
|
-
}
|
|
203
|
-
continue;
|
|
204
|
-
|
|
205
|
-
case STATE.OPEN_KEY:
|
|
206
|
-
case STATE.OPEN_OBJECT:
|
|
207
|
-
if (isWhitespace(c)) continue;
|
|
208
|
-
if (this.state === STATE.OPEN_KEY) this.stack.push(STATE.CLOSE_KEY);else if (c === Char.closeBrace) {
|
|
209
|
-
this.emit('onopenobject');
|
|
210
|
-
this.depth++;
|
|
211
|
-
this.emit('oncloseobject');
|
|
212
|
-
this.depth--;
|
|
213
|
-
this.state = this.stack.pop() || STATE.VALUE;
|
|
214
|
-
continue;
|
|
215
|
-
} else this.stack.push(STATE.CLOSE_OBJECT);
|
|
216
|
-
if (c === Char.doubleQuote) this.state = STATE.STRING;else this._error('Malformed object key should start with "');
|
|
217
|
-
continue;
|
|
218
|
-
|
|
219
|
-
case STATE.CLOSE_KEY:
|
|
220
|
-
case STATE.CLOSE_OBJECT:
|
|
221
|
-
if (isWhitespace(c)) continue;
|
|
222
|
-
|
|
223
|
-
if (c === Char.colon) {
|
|
224
|
-
if (this.state === STATE.CLOSE_OBJECT) {
|
|
225
|
-
this.stack.push(STATE.CLOSE_OBJECT);
|
|
226
|
-
|
|
227
|
-
this._closeValue('onopenobject');
|
|
228
|
-
|
|
229
|
-
this.depth++;
|
|
230
|
-
} else this._closeValue('onkey');
|
|
231
|
-
|
|
232
|
-
this.state = STATE.VALUE;
|
|
233
|
-
} else if (c === Char.closeBrace) {
|
|
234
|
-
this.emitNode('oncloseobject');
|
|
235
|
-
this.depth--;
|
|
236
|
-
this.state = this.stack.pop() || STATE.VALUE;
|
|
237
|
-
} else if (c === Char.comma) {
|
|
238
|
-
if (this.state === STATE.CLOSE_OBJECT) this.stack.push(STATE.CLOSE_OBJECT);
|
|
239
|
-
|
|
240
|
-
this._closeValue();
|
|
241
|
-
|
|
242
|
-
this.state = STATE.OPEN_KEY;
|
|
243
|
-
} else this._error('Bad object');
|
|
244
|
-
|
|
245
|
-
continue;
|
|
246
|
-
|
|
247
|
-
case STATE.OPEN_ARRAY:
|
|
248
|
-
case STATE.VALUE:
|
|
249
|
-
if (isWhitespace(c)) continue;
|
|
250
|
-
|
|
251
|
-
if (this.state === STATE.OPEN_ARRAY) {
|
|
252
|
-
this.emit('onopenarray');
|
|
253
|
-
this.depth++;
|
|
254
|
-
this.state = STATE.VALUE;
|
|
255
|
-
|
|
256
|
-
if (c === Char.closeBracket) {
|
|
257
|
-
this.emit('onclosearray');
|
|
258
|
-
this.depth--;
|
|
259
|
-
this.state = this.stack.pop() || STATE.VALUE;
|
|
260
|
-
continue;
|
|
261
|
-
} else {
|
|
262
|
-
this.stack.push(STATE.CLOSE_ARRAY);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
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) {
|
|
267
|
-
this.numberNode += '-';
|
|
268
|
-
} else if (Char._0 <= c && c <= Char._9) {
|
|
269
|
-
this.numberNode += String.fromCharCode(c);
|
|
270
|
-
this.state = STATE.NUMBER_DIGIT;
|
|
271
|
-
} else this._error('Bad value');
|
|
272
|
-
continue;
|
|
273
|
-
|
|
274
|
-
case STATE.CLOSE_ARRAY:
|
|
275
|
-
if (c === Char.comma) {
|
|
276
|
-
this.stack.push(STATE.CLOSE_ARRAY);
|
|
277
|
-
|
|
278
|
-
this._closeValue('onvalue');
|
|
279
|
-
|
|
280
|
-
this.state = STATE.VALUE;
|
|
281
|
-
} else if (c === Char.closeBracket) {
|
|
282
|
-
this.emitNode('onclosearray');
|
|
283
|
-
this.depth--;
|
|
284
|
-
this.state = this.stack.pop() || STATE.VALUE;
|
|
285
|
-
} else if (isWhitespace(c)) continue;else this._error('Bad array');
|
|
286
|
-
|
|
287
|
-
continue;
|
|
288
|
-
|
|
289
|
-
case STATE.STRING:
|
|
290
|
-
if (this.textNode === undefined) {
|
|
291
|
-
this.textNode = '';
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
var starti = i - 1;
|
|
295
|
-
var slashed = this.slashed;
|
|
296
|
-
var unicodeI = this.unicodeI;
|
|
297
|
-
|
|
298
|
-
STRING_BIGLOOP: while (true) {
|
|
299
|
-
while (unicodeI > 0) {
|
|
300
|
-
this.unicodeS += String.fromCharCode(c);
|
|
301
|
-
c = chunk.charCodeAt(i++);
|
|
302
|
-
this.position++;
|
|
303
|
-
|
|
304
|
-
if (unicodeI === 4) {
|
|
305
|
-
this.textNode += String.fromCharCode(parseInt(this.unicodeS, 16));
|
|
306
|
-
unicodeI = 0;
|
|
307
|
-
starti = i - 1;
|
|
308
|
-
} else {
|
|
309
|
-
unicodeI++;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
if (!c) break STRING_BIGLOOP;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
if (c === Char.doubleQuote && !slashed) {
|
|
316
|
-
this.state = this.stack.pop() || STATE.VALUE;
|
|
317
|
-
this.textNode += chunk.substring(starti, i - 1);
|
|
318
|
-
this.position += i - 1 - starti;
|
|
319
|
-
break;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
if (c === Char.backslash && !slashed) {
|
|
323
|
-
slashed = true;
|
|
324
|
-
this.textNode += chunk.substring(starti, i - 1);
|
|
325
|
-
this.position += i - 1 - starti;
|
|
326
|
-
c = chunk.charCodeAt(i++);
|
|
327
|
-
this.position++;
|
|
328
|
-
if (!c) break;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
if (slashed) {
|
|
332
|
-
slashed = false;
|
|
333
|
-
|
|
334
|
-
if (c === Char.n) {
|
|
335
|
-
this.textNode += '\n';
|
|
336
|
-
} else if (c === Char.r) {
|
|
337
|
-
this.textNode += '\r';
|
|
338
|
-
} else if (c === Char.t) {
|
|
339
|
-
this.textNode += '\t';
|
|
340
|
-
} else if (c === Char.f) {
|
|
341
|
-
this.textNode += '\f';
|
|
342
|
-
} else if (c === Char.b) {
|
|
343
|
-
this.textNode += '\b';
|
|
344
|
-
} else if (c === Char.u) {
|
|
345
|
-
unicodeI = 1;
|
|
346
|
-
this.unicodeS = '';
|
|
347
|
-
} else {
|
|
348
|
-
this.textNode += String.fromCharCode(c);
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
c = chunk.charCodeAt(i++);
|
|
352
|
-
this.position++;
|
|
353
|
-
starti = i - 1;
|
|
354
|
-
if (!c) break;else continue;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
stringTokenPattern.lastIndex = i;
|
|
358
|
-
var reResult = stringTokenPattern.exec(chunk);
|
|
359
|
-
|
|
360
|
-
if (reResult === null) {
|
|
361
|
-
i = chunk.length + 1;
|
|
362
|
-
this.textNode += chunk.substring(starti, i - 1);
|
|
363
|
-
this.position += i - 1 - starti;
|
|
364
|
-
break;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
i = reResult.index + 1;
|
|
368
|
-
c = chunk.charCodeAt(reResult.index);
|
|
369
|
-
|
|
370
|
-
if (!c) {
|
|
371
|
-
this.textNode += chunk.substring(starti, i - 1);
|
|
372
|
-
this.position += i - 1 - starti;
|
|
373
|
-
break;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
this.slashed = slashed;
|
|
378
|
-
this.unicodeI = unicodeI;
|
|
379
|
-
continue;
|
|
380
|
-
|
|
381
|
-
case STATE.TRUE:
|
|
382
|
-
if (c === Char.r) this.state = STATE.TRUE2;else this._error("Invalid true started with t".concat(c));
|
|
383
|
-
continue;
|
|
384
|
-
|
|
385
|
-
case STATE.TRUE2:
|
|
386
|
-
if (c === Char.u) this.state = STATE.TRUE3;else this._error("Invalid true started with tr".concat(c));
|
|
387
|
-
continue;
|
|
388
|
-
|
|
389
|
-
case STATE.TRUE3:
|
|
390
|
-
if (c === Char.e) {
|
|
391
|
-
this.emit('onvalue', true);
|
|
392
|
-
this.state = this.stack.pop() || STATE.VALUE;
|
|
393
|
-
} else this._error("Invalid true started with tru".concat(c));
|
|
394
|
-
|
|
395
|
-
continue;
|
|
396
|
-
|
|
397
|
-
case STATE.FALSE:
|
|
398
|
-
if (c === Char.a) this.state = STATE.FALSE2;else this._error("Invalid false started with f".concat(c));
|
|
399
|
-
continue;
|
|
400
|
-
|
|
401
|
-
case STATE.FALSE2:
|
|
402
|
-
if (c === Char.l) this.state = STATE.FALSE3;else this._error("Invalid false started with fa".concat(c));
|
|
403
|
-
continue;
|
|
404
|
-
|
|
405
|
-
case STATE.FALSE3:
|
|
406
|
-
if (c === Char.s) this.state = STATE.FALSE4;else this._error("Invalid false started with fal".concat(c));
|
|
407
|
-
continue;
|
|
408
|
-
|
|
409
|
-
case STATE.FALSE4:
|
|
410
|
-
if (c === Char.e) {
|
|
411
|
-
this.emit('onvalue', false);
|
|
412
|
-
this.state = this.stack.pop() || STATE.VALUE;
|
|
413
|
-
} else this._error("Invalid false started with fals".concat(c));
|
|
414
|
-
|
|
415
|
-
continue;
|
|
416
|
-
|
|
417
|
-
case STATE.NULL:
|
|
418
|
-
if (c === Char.u) this.state = STATE.NULL2;else this._error("Invalid null started with n".concat(c));
|
|
419
|
-
continue;
|
|
420
|
-
|
|
421
|
-
case STATE.NULL2:
|
|
422
|
-
if (c === Char.l) this.state = STATE.NULL3;else this._error("Invalid null started with nu".concat(c));
|
|
423
|
-
continue;
|
|
424
|
-
|
|
425
|
-
case STATE.NULL3:
|
|
426
|
-
if (c === Char.l) {
|
|
427
|
-
this.emit('onvalue', null);
|
|
428
|
-
this.state = this.stack.pop() || STATE.VALUE;
|
|
429
|
-
} else this._error("Invalid null started with nul".concat(c));
|
|
430
|
-
|
|
431
|
-
continue;
|
|
432
|
-
|
|
433
|
-
case STATE.NUMBER_DECIMAL_POINT:
|
|
434
|
-
if (c === Char.period) {
|
|
435
|
-
this.numberNode += '.';
|
|
436
|
-
this.state = STATE.NUMBER_DIGIT;
|
|
437
|
-
} else this._error('Leading zero not followed by .');
|
|
438
|
-
|
|
439
|
-
continue;
|
|
440
|
-
|
|
441
|
-
case STATE.NUMBER_DIGIT:
|
|
442
|
-
if (Char._0 <= c && c <= Char._9) this.numberNode += String.fromCharCode(c);else if (c === Char.period) {
|
|
443
|
-
if (this.numberNode.indexOf('.') !== -1) this._error('Invalid number has two dots');
|
|
444
|
-
this.numberNode += '.';
|
|
445
|
-
} else if (c === Char.e || c === Char.E) {
|
|
446
|
-
if (this.numberNode.indexOf('e') !== -1 || this.numberNode.indexOf('E') !== -1) this._error('Invalid number has two exponential');
|
|
447
|
-
this.numberNode += 'e';
|
|
448
|
-
} else if (c === Char.plus || c === Char.minus) {
|
|
449
|
-
if (!(p === Char.e || p === Char.E)) this._error('Invalid symbol in number');
|
|
450
|
-
this.numberNode += String.fromCharCode(c);
|
|
451
|
-
} else {
|
|
452
|
-
this._closeNumber();
|
|
453
|
-
|
|
454
|
-
i--;
|
|
455
|
-
this.state = this.stack.pop() || STATE.VALUE;
|
|
456
|
-
}
|
|
457
|
-
continue;
|
|
458
|
-
|
|
459
|
-
default:
|
|
460
|
-
this._error("Unknown state: ".concat(this.state));
|
|
461
|
-
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
if (this.position >= this.bufferCheckPosition) {
|
|
466
|
-
checkBufferLength(this);
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
this.emit('onchunkparsed');
|
|
470
|
-
return this;
|
|
471
|
-
}
|
|
472
|
-
}, {
|
|
473
|
-
key: "_closeValue",
|
|
474
|
-
value: function _closeValue() {
|
|
475
|
-
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'onvalue';
|
|
476
|
-
|
|
477
|
-
if (this.textNode !== undefined) {
|
|
478
|
-
this.emit(event, this.textNode);
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
this.textNode = undefined;
|
|
482
|
-
}
|
|
483
|
-
}, {
|
|
484
|
-
key: "_closeNumber",
|
|
485
|
-
value: function _closeNumber() {
|
|
486
|
-
if (this.numberNode) this.emit('onvalue', parseFloat(this.numberNode));
|
|
487
|
-
this.numberNode = '';
|
|
488
|
-
}
|
|
489
|
-
}, {
|
|
490
|
-
key: "_error",
|
|
491
|
-
value: function _error() {
|
|
492
|
-
var message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
493
|
-
|
|
494
|
-
this._closeValue();
|
|
495
|
-
|
|
496
|
-
message += "\nLine: ".concat(this.line, "\nColumn: ").concat(this.column, "\nChar: ").concat(this.c);
|
|
497
|
-
var error = new Error(message);
|
|
498
|
-
this.error = error;
|
|
499
|
-
this.emit('onerror', error);
|
|
500
|
-
}
|
|
501
|
-
}]);
|
|
502
|
-
return ClarinetParser;
|
|
503
|
-
}();
|
|
504
|
-
|
|
505
|
-
exports.default = ClarinetParser;
|
|
506
|
-
|
|
507
|
-
function isWhitespace(c) {
|
|
508
|
-
return c === Char.carriageReturn || c === Char.lineFeed || c === Char.space || c === Char.tab;
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
function checkBufferLength(parser) {
|
|
512
|
-
var maxAllowed = Math.max(MAX_BUFFER_LENGTH, 10);
|
|
513
|
-
var maxActual = 0;
|
|
514
|
-
|
|
515
|
-
for (var _i = 0, _arr = ['textNode', 'numberNode']; _i < _arr.length; _i++) {
|
|
516
|
-
var buffer = _arr[_i];
|
|
517
|
-
var len = parser[buffer] === undefined ? 0 : parser[buffer].length;
|
|
518
|
-
|
|
519
|
-
if (len > maxAllowed) {
|
|
520
|
-
switch (buffer) {
|
|
521
|
-
case 'text':
|
|
522
|
-
break;
|
|
523
|
-
|
|
524
|
-
default:
|
|
525
|
-
parser._error("Max buffer length exceeded: ".concat(buffer));
|
|
526
|
-
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
maxActual = Math.max(maxActual, len);
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
parser.bufferCheckPosition = MAX_BUFFER_LENGTH - maxActual + parser.position;
|
|
534
|
-
}
|
|
535
|
-
//# sourceMappingURL=clarinet.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/clarinet/clarinet.ts"],"names":["MAX_BUFFER_LENGTH","Number","MAX_SAFE_INTEGER","STATE","Char","tab","lineFeed","carriageReturn","space","doubleQuote","plus","comma","minus","period","_0","_9","colon","E","openBracket","backslash","closeBracket","a","b","e","f","l","n","r","s","t","u","openBrace","closeBrace","stringTokenPattern","DEFAULT_OPTIONS","onready","onopenobject","onkey","oncloseobject","onopenarray","onclosearray","onvalue","onerror","onend","onchunkparsed","ClarinetParser","options","BEGIN","textNode","undefined","numberNode","emit","state","VALUE","depth","_error","_closeValue","c","closed","error","write","event","data","chunk","end","i","charCodeAt","p","position","line","column","OPEN_OBJECT","OPEN_ARRAY","isWhitespace","OPEN_KEY","stack","push","CLOSE_KEY","pop","CLOSE_OBJECT","STRING","emitNode","CLOSE_ARRAY","TRUE","FALSE","NULL","String","fromCharCode","NUMBER_DIGIT","starti","slashed","unicodeI","STRING_BIGLOOP","unicodeS","parseInt","substring","lastIndex","reResult","exec","length","index","TRUE2","TRUE3","FALSE2","FALSE3","FALSE4","NULL2","NULL3","NUMBER_DECIMAL_POINT","indexOf","_closeNumber","bufferCheckPosition","checkBufferLength","parseFloat","message","Error","parser","maxAllowed","Math","max","maxActual","buffer","len"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,IAAMA,iBAAiB,GAAGC,MAAM,CAACC,gBAAjC;IAGKC,K;;WAAAA,K;AAAAA,EAAAA,K,CAAAA,K;AAAAA,EAAAA,K,CAAAA,K;AAAAA,EAAAA,K,CAAAA,K;AAAAA,EAAAA,K,CAAAA,K;AAAAA,EAAAA,K,CAAAA,K;AAAAA,EAAAA,K,CAAAA,K;AAAAA,EAAAA,K,CAAAA,K;AAAAA,EAAAA,K,CAAAA,K;AAAAA,EAAAA,K,CAAAA,K;AAAAA,EAAAA,K,CAAAA,K;AAAAA,EAAAA,K,CAAAA,K;AAAAA,EAAAA,K,CAAAA,K;AAAAA,EAAAA,K,CAAAA,K;AAAAA,EAAAA,K,CAAAA,K;AAAAA,EAAAA,K,CAAAA,K;AAAAA,EAAAA,K,CAAAA,K;AAAAA,EAAAA,K,CAAAA,K;AAAAA,EAAAA,K,CAAAA,K;AAAAA,EAAAA,K,CAAAA,K;AAAAA,EAAAA,K,CAAAA,K;AAAAA,EAAAA,K,CAAAA,K;AAAAA,EAAAA,K,CAAAA,K;AAAAA,EAAAA,K,CAAAA,K;AAAAA,EAAAA,K,CAAAA,K;GAAAA,K,KAAAA,K;;AA2BL,IAAMC,IAAI,GAAG;AACXC,EAAAA,GAAG,EAAE,IADM;AAEXC,EAAAA,QAAQ,EAAE,IAFC;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AAM,CAACK,MAAD,CAAN,KAAmBxE,SAAnB,GAA+B,CAA/B,GAAmCmE,MAAM,CAACK,MAAD,CAAN,CAAetB,MAA9D;;AACA,QAAIuB,GAAG,GAAGL,UAAV,EAAsB;AACpB,cAAQI,MAAR;AACE,aAAK,MAAL;AAGE;;AAEF;AACEL,UAAAA,MAAM,CAAC7D,MAAP,uCAA6CkE,MAA7C;;AAPJ;AASD;;AACDD,IAAAA,SAAS,GAAGF,IAAI,CAACC,GAAL,CAASC,SAAT,EAAoBE,GAApB,CAAZ;AACD;;AACDN,EAAAA,MAAM,CAACL,mBAAP,GAA6B/G,iBAAiB,GAAGwH,SAApB,GAAgCJ,MAAM,CAAChD,QAApE;AACD","sourcesContent":["// loaders.gl, MIT license\n// This is a fork of the clarinet library, originally BSD license (see LICENSE file)\n// loaders.gl changes:\n// - typescript port\n\nexport type ClarinetEvent =\n | 'onvalue'\n | 'onstring'\n | 'onkey'\n | 'onopenobject'\n | 'oncloseobject'\n | 'onopenarray'\n | 'onclosearray'\n | 'onerror'\n | 'onend'\n | 'onready';\n\n// Removes the MAX_BUFFER_LENGTH, originally set to 64 * 1024\nconst MAX_BUFFER_LENGTH = Number.MAX_SAFE_INTEGER;\n// const DEBUG = false;\n\nenum STATE {\n BEGIN = 0,\n VALUE, // general stuff\n OPEN_OBJECT, // {\n CLOSE_OBJECT, // }\n OPEN_ARRAY, // [\n CLOSE_ARRAY, // ]\n TEXT_ESCAPE, // \\ stuff\n STRING, // \"\"\n BACKSLASH,\n END, // No more stack\n OPEN_KEY, // , \"a\"\n CLOSE_KEY, // :\n TRUE, // r\n TRUE2, // u\n TRUE3, // e\n FALSE, // a\n FALSE2, // l\n FALSE3, // s\n FALSE4, // e\n NULL, // u\n NULL2, // l\n NULL3, // l\n NUMBER_DECIMAL_POINT, // .\n NUMBER_DIGIT // [0-9]\n}\n\nconst Char = {\n tab: 0x09, // \\t\n lineFeed: 0x0a, // \\n\n carriageReturn: 0x0d, // \\r\n space: 0x20, // \" \"\n\n doubleQuote: 0x22, // \"\n plus: 0x2b, // +\n comma: 0x2c, // ,\n minus: 0x2d, // -\n period: 0x2e, // .\n\n _0: 0x30, // 0\n _9: 0x39, // 9\n\n colon: 0x3a, // :\n\n E: 0x45, // E\n\n openBracket: 0x5b, // [\n backslash: 0x5c, // \\\n closeBracket: 0x5d, // ]\n\n a: 0x61, // a\n b: 0x62, // b\n e: 0x65, // e\n f: 0x66, // f\n l: 0x6c, // l\n n: 0x6e, // n\n r: 0x72, // r\n s: 0x73, // s\n t: 0x74, // t\n u: 0x75, // u\n\n openBrace: 0x7b, // {\n closeBrace: 0x7d // }\n};\n\nconst stringTokenPattern = /[\\\\\"\\n]/g;\n\ntype ParserEvent = (parser: ClarinetParser, event: string, data?: any) => void;\n\nexport type ClarinetParserOptions = {\n onready?: ParserEvent;\n onopenobject?: ParserEvent;\n onkey?: ParserEvent;\n oncloseobject?: ParserEvent;\n onopenarray?: ParserEvent;\n onclosearray?: ParserEvent;\n onvalue?: ParserEvent;\n onerror?: ParserEvent;\n onend?: ParserEvent;\n onchunkparsed?: ParserEvent;\n};\n\nconst DEFAULT_OPTIONS: Required<ClarinetParserOptions> = {\n onready: () => {},\n onopenobject: () => {},\n onkey: () => {},\n oncloseobject: () => {},\n onopenarray: () => {},\n onclosearray: () => {},\n onvalue: () => {},\n onerror: () => {},\n onend: () => {},\n onchunkparsed: () => {}\n};\nexport default class ClarinetParser {\n protected options: Required<ClarinetParserOptions> = DEFAULT_OPTIONS;\n\n bufferCheckPosition = MAX_BUFFER_LENGTH;\n q = '';\n c = '';\n p = '';\n closed = false;\n closedRoot = false;\n sawRoot = false;\n // tag = null;\n error: Error | null = null;\n state = STATE.BEGIN;\n stack: STATE[] = [];\n // mostly just for error reporting\n position: number = 0;\n column: number = 0;\n line: number = 1;\n slashed: boolean = false;\n unicodeI: number = 0;\n unicodeS: string | null = null;\n depth: number = 0;\n\n textNode;\n numberNode;\n\n constructor(options: ClarinetParserOptions = {}) {\n this.options = {...DEFAULT_OPTIONS, ...options};\n this.textNode = undefined;\n this.numberNode = '';\n this.emit('onready');\n }\n\n end() {\n if (this.state !== STATE.VALUE || this.depth !== 0) this._error('Unexpected end');\n\n this._closeValue();\n this.c = '';\n this.closed = true;\n this.emit('onend');\n return this;\n }\n\n resume() {\n this.error = null;\n return this;\n }\n\n close() {\n return this.write(null);\n }\n\n // protected\n\n emit(event: string, data?: any): void {\n // if (DEBUG) console.log('-- emit', event, data);\n this.options[event]?.(data, this);\n }\n\n emitNode(event: string, data?: any): void {\n this._closeValue();\n this.emit(event, data);\n }\n\n /* eslint-disable no-continue */\n // eslint-disable-next-line complexity, max-statements\n write(chunk) {\n if (this.error) {\n throw this.error;\n }\n if (this.closed) {\n return this._error('Cannot write after close. Assign an onready handler.');\n }\n if (chunk === null) {\n return this.end();\n }\n let i = 0;\n let c = chunk.charCodeAt(0);\n let p = this.p;\n // if (DEBUG) console.log(`write -> [${ chunk }]`);\n while (c) {\n p = c;\n this.c = c = chunk.charCodeAt(i++);\n // if chunk doesnt have next, like streaming char by char\n // this way we need to check if previous is really previous\n // if not we need to reset to what the this says is the previous\n // from buffer\n if (p !== c) {\n this.p = p;\n } else {\n p = this.p;\n }\n\n if (!c) break;\n\n // if (DEBUG) console.log(i, c, STATE[this.state]);\n this.position++;\n if (c === Char.lineFeed) {\n this.line++;\n this.column = 0;\n } else this.column++;\n\n switch (this.state) {\n case STATE.BEGIN:\n if (c === Char.openBrace) this.state = STATE.OPEN_OBJECT;\n else if (c === Char.openBracket) this.state = STATE.OPEN_ARRAY;\n else if (!isWhitespace(c)) {\n this._error('Non-whitespace before {[.');\n }\n continue;\n\n case STATE.OPEN_KEY:\n case STATE.OPEN_OBJECT:\n if (isWhitespace(c)) continue;\n if (this.state === STATE.OPEN_KEY) this.stack.push(STATE.CLOSE_KEY);\n else if (c === Char.closeBrace) {\n this.emit('onopenobject');\n this.depth++;\n this.emit('oncloseobject');\n this.depth--;\n this.state = this.stack.pop() || STATE.VALUE;\n continue;\n } else this.stack.push(STATE.CLOSE_OBJECT);\n if (c === Char.doubleQuote) this.state = STATE.STRING;\n else this._error('Malformed object key should start with \"');\n continue;\n\n case STATE.CLOSE_KEY:\n case STATE.CLOSE_OBJECT:\n if (isWhitespace(c)) continue;\n // let event = this.state === STATE.CLOSE_KEY ? 'key' : 'object';\n if (c === Char.colon) {\n if (this.state === STATE.CLOSE_OBJECT) {\n this.stack.push(STATE.CLOSE_OBJECT);\n this._closeValue('onopenobject');\n this.depth++;\n } else this._closeValue('onkey');\n this.state = STATE.VALUE;\n } else if (c === Char.closeBrace) {\n this.emitNode('oncloseobject');\n this.depth--;\n this.state = this.stack.pop() || STATE.VALUE;\n } else if (c === Char.comma) {\n if (this.state === STATE.CLOSE_OBJECT) this.stack.push(STATE.CLOSE_OBJECT);\n this._closeValue();\n this.state = STATE.OPEN_KEY;\n } else this._error('Bad object');\n continue;\n\n case STATE.OPEN_ARRAY: // after an array there always a value\n case STATE.VALUE:\n if (isWhitespace(c)) continue;\n if (this.state === STATE.OPEN_ARRAY) {\n this.emit('onopenarray');\n this.depth++;\n this.state = STATE.VALUE;\n if (c === Char.closeBracket) {\n this.emit('onclosearray');\n this.depth--;\n this.state = this.stack.pop() || STATE.VALUE;\n continue;\n } else {\n this.stack.push(STATE.CLOSE_ARRAY);\n }\n }\n if (c === Char.doubleQuote) this.state = STATE.STRING;\n else if (c === Char.openBrace) this.state = STATE.OPEN_OBJECT;\n else if (c === Char.openBracket) this.state = STATE.OPEN_ARRAY;\n else if (c === Char.t) this.state = STATE.TRUE;\n else if (c === Char.f) this.state = STATE.FALSE;\n else if (c === Char.n) this.state = STATE.NULL;\n else if (c === Char.minus) {\n // keep and continue\n this.numberNode += '-';\n } else if (Char._0 <= c && c <= Char._9) {\n this.numberNode += String.fromCharCode(c);\n this.state = STATE.NUMBER_DIGIT;\n } else this._error('Bad value');\n continue;\n\n case STATE.CLOSE_ARRAY:\n if (c === Char.comma) {\n this.stack.push(STATE.CLOSE_ARRAY);\n this._closeValue('onvalue');\n this.state = STATE.VALUE;\n } else if (c === Char.closeBracket) {\n this.emitNode('onclosearray');\n this.depth--;\n this.state = this.stack.pop() || STATE.VALUE;\n } else if (isWhitespace(c)) continue;\n else this._error('Bad array');\n continue;\n\n case STATE.STRING:\n if (this.textNode === undefined) {\n this.textNode = '';\n }\n\n // thanks thejh, this is an about 50% performance improvement.\n let starti = i - 1;\n let slashed = this.slashed;\n let unicodeI = this.unicodeI;\n // eslint-disable-next-line no-constant-condition, no-labels\n STRING_BIGLOOP: while (true) {\n // if (DEBUG) console.log(i, c, STATE[this.state], slashed);\n // zero means \"no unicode active\". 1-4 mean \"parse some more\". end after 4.\n while (unicodeI > 0) {\n this.unicodeS += String.fromCharCode(c);\n c = chunk.charCodeAt(i++);\n this.position++;\n if (unicodeI === 4) {\n // TODO this might be slow? well, probably not used too often anyway\n this.textNode += String.fromCharCode(parseInt(this.unicodeS as string, 16));\n unicodeI = 0;\n starti = i - 1;\n } else {\n unicodeI++;\n }\n // we can just break here: no stuff we skipped that still has to be sliced out or so\n // eslint-disable-next-line no-labels\n if (!c) break STRING_BIGLOOP;\n }\n if (c === Char.doubleQuote && !slashed) {\n this.state = this.stack.pop() || STATE.VALUE;\n this.textNode += chunk.substring(starti, i - 1);\n this.position += i - 1 - starti;\n break;\n }\n if (c === Char.backslash && !slashed) {\n slashed = true;\n this.textNode += chunk.substring(starti, i - 1);\n this.position += i - 1 - starti;\n c = chunk.charCodeAt(i++);\n this.position++;\n if (!c) break;\n }\n if (slashed) {\n slashed = false;\n if (c === Char.n) {\n this.textNode += '\\n';\n } else if (c === Char.r) {\n this.textNode += '\\r';\n } else if (c === Char.t) {\n this.textNode += '\\t';\n } else if (c === Char.f) {\n this.textNode += '\\f';\n } else if (c === Char.b) {\n this.textNode += '\\b';\n } else if (c === Char.u) {\n // \\uxxxx. meh!\n unicodeI = 1;\n this.unicodeS = '';\n } else {\n this.textNode += String.fromCharCode(c);\n }\n c = chunk.charCodeAt(i++);\n this.position++;\n starti = i - 1;\n if (!c) break;\n else continue;\n }\n\n stringTokenPattern.lastIndex = i;\n const reResult = stringTokenPattern.exec(chunk);\n if (reResult === null) {\n i = chunk.length + 1;\n this.textNode += chunk.substring(starti, i - 1);\n this.position += i - 1 - starti;\n break;\n }\n i = reResult.index + 1;\n c = chunk.charCodeAt(reResult.index);\n if (!c) {\n this.textNode += chunk.substring(starti, i - 1);\n this.position += i - 1 - starti;\n break;\n }\n }\n this.slashed = slashed;\n this.unicodeI = unicodeI;\n continue;\n\n case STATE.TRUE:\n if (c === Char.r) this.state = STATE.TRUE2;\n else this._error(`Invalid true started with t${c}`);\n continue;\n\n case STATE.TRUE2:\n if (c === Char.u) this.state = STATE.TRUE3;\n else this._error(`Invalid true started with tr${c}`);\n continue;\n\n case STATE.TRUE3:\n if (c === Char.e) {\n this.emit('onvalue', true);\n this.state = this.stack.pop() || STATE.VALUE;\n } else this._error(`Invalid true started with tru${c}`);\n continue;\n\n case STATE.FALSE:\n if (c === Char.a) this.state = STATE.FALSE2;\n else this._error(`Invalid false started with f${c}`);\n continue;\n\n case STATE.FALSE2:\n if (c === Char.l) this.state = STATE.FALSE3;\n else this._error(`Invalid false started with fa${c}`);\n continue;\n\n case STATE.FALSE3:\n if (c === Char.s) this.state = STATE.FALSE4;\n else this._error(`Invalid false started with fal${c}`);\n continue;\n\n case STATE.FALSE4:\n if (c === Char.e) {\n this.emit('onvalue', false);\n this.state = this.stack.pop() || STATE.VALUE;\n } else this._error(`Invalid false started with fals${c}`);\n continue;\n\n case STATE.NULL:\n if (c === Char.u) this.state = STATE.NULL2;\n else this._error(`Invalid null started with n${c}`);\n continue;\n\n case STATE.NULL2:\n if (c === Char.l) this.state = STATE.NULL3;\n else this._error(`Invalid null started with nu${c}`);\n continue;\n\n case STATE.NULL3:\n if (c === Char.l) {\n this.emit('onvalue', null);\n this.state = this.stack.pop() || STATE.VALUE;\n } else this._error(`Invalid null started with nul${c}`);\n continue;\n\n case STATE.NUMBER_DECIMAL_POINT:\n if (c === Char.period) {\n this.numberNode += '.';\n this.state = STATE.NUMBER_DIGIT;\n } else this._error('Leading zero not followed by .');\n continue;\n\n case STATE.NUMBER_DIGIT:\n if (Char._0 <= c && c <= Char._9) this.numberNode += String.fromCharCode(c);\n else if (c === Char.period) {\n if (this.numberNode.indexOf('.') !== -1) this._error('Invalid number has two dots');\n this.numberNode += '.';\n } else if (c === Char.e || c === Char.E) {\n if (this.numberNode.indexOf('e') !== -1 || this.numberNode.indexOf('E') !== -1)\n this._error('Invalid number has two exponential');\n this.numberNode += 'e';\n } else if (c === Char.plus || c === Char.minus) {\n // @ts-expect-error\n if (!(p === Char.e || p === Char.E)) this._error('Invalid symbol in number');\n this.numberNode += String.fromCharCode(c);\n } else {\n this._closeNumber();\n i--; // go back one\n this.state = this.stack.pop() || STATE.VALUE;\n }\n continue;\n\n default:\n this._error(`Unknown state: ${this.state}`);\n }\n }\n if (this.position >= this.bufferCheckPosition) {\n checkBufferLength(this);\n }\n\n this.emit('onchunkparsed');\n\n return this;\n }\n\n _closeValue(event: string = 'onvalue'): void {\n if (this.textNode !== undefined) {\n this.emit(event, this.textNode);\n }\n this.textNode = undefined;\n }\n\n _closeNumber(): void {\n if (this.numberNode) this.emit('onvalue', parseFloat(this.numberNode));\n this.numberNode = '';\n }\n\n _error(message: string = ''): void {\n this._closeValue();\n message += `\\nLine: ${this.line}\\nColumn: ${this.column}\\nChar: ${this.c}`;\n const error = new Error(message);\n this.error = error;\n this.emit('onerror', error);\n }\n}\n\nfunction isWhitespace(c): boolean {\n return c === Char.carriageReturn || c === Char.lineFeed || c === Char.space || c === Char.tab;\n}\n\nfunction checkBufferLength(parser) {\n const maxAllowed = Math.max(MAX_BUFFER_LENGTH, 10);\n let maxActual = 0;\n\n for (const buffer of ['textNode', 'numberNode']) {\n const len = parser[buffer] === undefined ? 0 : parser[buffer].length;\n if (len > maxAllowed) {\n switch (buffer) {\n case 'text':\n // TODO - should this be closeValue?\n // closeText(parser);\n break;\n\n default:\n parser._error(`Max buffer length exceeded: ${buffer}`);\n }\n }\n maxActual = Math.max(maxActual, len);\n }\n parser.bufferCheckPosition = MAX_BUFFER_LENGTH - maxActual + parser.position;\n}\n"],"file":"clarinet.js"}
|