@loaders.gl/json 3.1.0-alpha.3 → 3.1.0-beta.2
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.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +1838 -4
- package/dist/es5/bundle.js +7 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/geojson-loader.js +95 -0
- package/dist/es5/geojson-loader.js.map +1 -0
- package/dist/es5/index.js +54 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/json-loader.js +59 -0
- package/dist/es5/json-loader.js.map +1 -0
- package/dist/es5/jsonl-loader.js +2 -0
- package/dist/{jsonl-loader.js.map → es5/jsonl-loader.js.map} +0 -0
- package/dist/{lib → es5/lib}/clarinet/LICENSE +0 -0
- package/dist/es5/lib/clarinet/clarinet.js +511 -0
- package/dist/es5/lib/clarinet/clarinet.js.map +1 -0
- package/dist/es5/lib/jsonpath/jsonpath.js +97 -0
- package/dist/es5/lib/jsonpath/jsonpath.js.map +1 -0
- package/dist/es5/lib/parse-json-in-batches.js +99 -0
- package/dist/es5/lib/parse-json-in-batches.js.map +1 -0
- package/dist/es5/lib/parse-json.js +41 -0
- package/dist/es5/lib/parse-json.js.map +1 -0
- package/dist/es5/lib/parse-ndjson-in-batches.js +46 -0
- package/dist/es5/lib/parse-ndjson-in-batches.js.map +1 -0
- package/dist/es5/lib/parse-ndjson.js +18 -0
- package/dist/es5/lib/parse-ndjson.js.map +1 -0
- package/dist/es5/lib/parser/json-parser.js +137 -0
- package/dist/es5/lib/parser/json-parser.js.map +1 -0
- package/dist/es5/lib/parser/streaming-json-parser.js +102 -0
- package/dist/es5/lib/parser/streaming-json-parser.js.map +1 -0
- package/dist/es5/ndjson-loader.js +45 -0
- package/dist/es5/ndjson-loader.js.map +1 -0
- package/dist/es5/workers/geojson-worker.js +8 -0
- package/dist/es5/workers/geojson-worker.js.map +1 -0
- package/dist/esm/bundle.js +5 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/geojson-loader.js +81 -0
- package/dist/esm/geojson-loader.js.map +1 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/json-loader.js +47 -0
- package/dist/esm/json-loader.js.map +1 -0
- package/dist/esm/jsonl-loader.js +2 -0
- package/dist/esm/jsonl-loader.js.map +1 -0
- package/dist/esm/lib/clarinet/LICENSE +28 -0
- package/dist/esm/lib/clarinet/clarinet.js +518 -0
- package/dist/esm/lib/clarinet/clarinet.js.map +1 -0
- package/dist/esm/lib/jsonpath/jsonpath.js +86 -0
- package/dist/esm/lib/jsonpath/jsonpath.js.map +1 -0
- package/dist/esm/lib/parse-json-in-batches.js +87 -0
- package/dist/esm/lib/parse-json-in-batches.js.map +1 -0
- package/dist/esm/lib/parse-json.js +34 -0
- package/dist/esm/lib/parse-json.js.map +1 -0
- package/dist/esm/lib/parse-ndjson-in-batches.js +37 -0
- package/dist/esm/lib/parse-ndjson-in-batches.js.map +1 -0
- package/dist/esm/lib/parse-ndjson.js +11 -0
- package/dist/esm/lib/parse-ndjson.js.map +1 -0
- package/dist/esm/lib/parser/json-parser.js +128 -0
- package/dist/esm/lib/parser/json-parser.js.map +1 -0
- package/dist/esm/lib/parser/streaming-json-parser.js +93 -0
- package/dist/esm/lib/parser/streaming-json-parser.js.map +1 -0
- package/dist/esm/ndjson-loader.js +32 -0
- package/dist/esm/ndjson-loader.js.map +1 -0
- package/dist/esm/workers/geojson-worker.js +4 -0
- package/dist/esm/workers/geojson-worker.js.map +1 -0
- package/dist/geojson-loader.d.ts +16 -0
- package/dist/geojson-loader.d.ts.map +1 -0
- package/dist/geojson-loader.js +66 -69
- package/dist/geojson-worker.js +1702 -2
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -6
- package/dist/json-loader.d.ts +14 -0
- package/dist/json-loader.d.ts.map +1 -0
- package/dist/json-loader.js +48 -38
- package/dist/jsonl-loader.d.ts +1 -0
- package/dist/jsonl-loader.d.ts.map +1 -0
- package/dist/jsonl-loader.js +53 -1
- package/dist/lib/clarinet/clarinet.d.ts +74 -0
- package/dist/lib/clarinet/clarinet.d.ts.map +1 -0
- package/dist/lib/clarinet/clarinet.js +517 -538
- package/dist/lib/jsonpath/jsonpath.d.ts +32 -0
- package/dist/lib/jsonpath/jsonpath.d.ts.map +1 -0
- package/dist/lib/jsonpath/jsonpath.js +81 -78
- package/dist/lib/parse-json-in-batches.d.ts +4 -0
- package/dist/lib/parse-json-in-batches.d.ts.map +1 -0
- package/dist/lib/parse-json-in-batches.js +75 -82
- package/dist/lib/parse-json.d.ts +3 -0
- package/dist/lib/parse-json.d.ts.map +1 -0
- package/dist/lib/parse-json.js +24 -29
- package/dist/lib/parse-ndjson-in-batches.d.ts +4 -0
- package/dist/lib/parse-ndjson-in-batches.d.ts.map +1 -0
- package/dist/lib/parse-ndjson-in-batches.js +32 -34
- package/dist/lib/parse-ndjson.d.ts +2 -0
- package/dist/lib/parse-ndjson.d.ts.map +1 -0
- package/dist/lib/parse-ndjson.js +13 -10
- package/dist/lib/parser/json-parser.d.ts +22 -0
- package/dist/lib/parser/json-parser.d.ts.map +1 -0
- package/dist/lib/parser/json-parser.js +95 -124
- package/dist/lib/parser/streaming-json-parser.d.ts +37 -0
- package/dist/lib/parser/streaming-json-parser.d.ts.map +1 -0
- package/dist/lib/parser/streaming-json-parser.js +95 -93
- package/dist/ndjson-loader.d.ts +22 -0
- package/dist/ndjson-loader.d.ts.map +1 -0
- package/dist/ndjson-loader.js +28 -23
- package/dist/workers/geojson-worker.d.ts +2 -0
- package/dist/workers/geojson-worker.d.ts.map +1 -0
- package/dist/workers/geojson-worker.js +5 -4
- package/package.json +10 -10
- 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/bundle.js.map +0 -1
- package/dist/dist.min.js +0 -2
- package/dist/dist.min.js.map +0 -1
- package/dist/geojson-loader.js.map +0 -1
- package/dist/geojson-worker.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/json-loader.js.map +0 -1
- package/dist/lib/clarinet/clarinet.js.map +0 -1
- package/dist/lib/jsonpath/jsonpath.js.map +0 -1
- package/dist/lib/parse-json-in-batches.js.map +0 -1
- package/dist/lib/parse-json.js.map +0 -1
- package/dist/lib/parse-ndjson-in-batches.js.map +0 -1
- package/dist/lib/parse-ndjson.js.map +0 -1
- package/dist/lib/parser/json-parser.js.map +0 -1
- package/dist/lib/parser/streaming-json-parser.js.map +0 -1
- package/dist/ndjson-loader.js.map +0 -1
- package/dist/workers/geojson-worker.js.map +0 -1
- package/src/lib/clarinet/clarinet.js +0 -578
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
const MAX_BUFFER_LENGTH = Number.MAX_SAFE_INTEGER;
|
|
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 = {}));
|
|
31
|
+
|
|
32
|
+
const Char = {
|
|
33
|
+
tab: 0x09,
|
|
34
|
+
lineFeed: 0x0a,
|
|
35
|
+
carriageReturn: 0x0d,
|
|
36
|
+
space: 0x20,
|
|
37
|
+
doubleQuote: 0x22,
|
|
38
|
+
plus: 0x2b,
|
|
39
|
+
comma: 0x2c,
|
|
40
|
+
minus: 0x2d,
|
|
41
|
+
period: 0x2e,
|
|
42
|
+
_0: 0x30,
|
|
43
|
+
_9: 0x39,
|
|
44
|
+
colon: 0x3a,
|
|
45
|
+
E: 0x45,
|
|
46
|
+
openBracket: 0x5b,
|
|
47
|
+
backslash: 0x5c,
|
|
48
|
+
closeBracket: 0x5d,
|
|
49
|
+
a: 0x61,
|
|
50
|
+
b: 0x62,
|
|
51
|
+
e: 0x65,
|
|
52
|
+
f: 0x66,
|
|
53
|
+
l: 0x6c,
|
|
54
|
+
n: 0x6e,
|
|
55
|
+
r: 0x72,
|
|
56
|
+
s: 0x73,
|
|
57
|
+
t: 0x74,
|
|
58
|
+
u: 0x75,
|
|
59
|
+
openBrace: 0x7b,
|
|
60
|
+
closeBrace: 0x7d
|
|
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);
|
|
78
|
+
|
|
79
|
+
_defineProperty(this, "bufferCheckPosition", MAX_BUFFER_LENGTH);
|
|
80
|
+
|
|
81
|
+
_defineProperty(this, "q", '');
|
|
82
|
+
|
|
83
|
+
_defineProperty(this, "c", '');
|
|
84
|
+
|
|
85
|
+
_defineProperty(this, "p", '');
|
|
86
|
+
|
|
87
|
+
_defineProperty(this, "closed", false);
|
|
88
|
+
|
|
89
|
+
_defineProperty(this, "closedRoot", false);
|
|
90
|
+
|
|
91
|
+
_defineProperty(this, "sawRoot", false);
|
|
92
|
+
|
|
93
|
+
_defineProperty(this, "error", null);
|
|
94
|
+
|
|
95
|
+
_defineProperty(this, "state", STATE.BEGIN);
|
|
96
|
+
|
|
97
|
+
_defineProperty(this, "stack", []);
|
|
98
|
+
|
|
99
|
+
_defineProperty(this, "position", 0);
|
|
100
|
+
|
|
101
|
+
_defineProperty(this, "column", 0);
|
|
102
|
+
|
|
103
|
+
_defineProperty(this, "line", 1);
|
|
104
|
+
|
|
105
|
+
_defineProperty(this, "slashed", false);
|
|
106
|
+
|
|
107
|
+
_defineProperty(this, "unicodeI", 0);
|
|
108
|
+
|
|
109
|
+
_defineProperty(this, "unicodeS", null);
|
|
110
|
+
|
|
111
|
+
_defineProperty(this, "depth", 0);
|
|
112
|
+
|
|
113
|
+
_defineProperty(this, "textNode", void 0);
|
|
114
|
+
|
|
115
|
+
_defineProperty(this, "numberNode", void 0);
|
|
116
|
+
|
|
117
|
+
this.options = { ...DEFAULT_OPTIONS,
|
|
118
|
+
...options
|
|
119
|
+
};
|
|
120
|
+
this.textNode = undefined;
|
|
121
|
+
this.numberNode = '';
|
|
122
|
+
this.emit('onready');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
end() {
|
|
126
|
+
if (this.state !== STATE.VALUE || this.depth !== 0) this._error('Unexpected end');
|
|
127
|
+
|
|
128
|
+
this._closeValue();
|
|
129
|
+
|
|
130
|
+
this.c = '';
|
|
131
|
+
this.closed = true;
|
|
132
|
+
this.emit('onend');
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
resume() {
|
|
137
|
+
this.error = null;
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
close() {
|
|
142
|
+
return this.write(null);
|
|
143
|
+
}
|
|
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
|
+
|
|
157
|
+
write(chunk) {
|
|
158
|
+
if (this.error) {
|
|
159
|
+
throw this.error;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (this.closed) {
|
|
163
|
+
return this._error('Cannot write after close. Assign an onready handler.');
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (chunk === null) {
|
|
167
|
+
return this.end();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
let i = 0;
|
|
171
|
+
let c = chunk.charCodeAt(0);
|
|
172
|
+
let p = this.p;
|
|
173
|
+
|
|
174
|
+
while (c) {
|
|
175
|
+
p = c;
|
|
176
|
+
this.c = c = chunk.charCodeAt(i++);
|
|
177
|
+
|
|
178
|
+
if (p !== c) {
|
|
179
|
+
this.p = p;
|
|
180
|
+
} else {
|
|
181
|
+
p = this.p;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (!c) break;
|
|
185
|
+
this.position++;
|
|
186
|
+
|
|
187
|
+
if (c === Char.lineFeed) {
|
|
188
|
+
this.line++;
|
|
189
|
+
this.column = 0;
|
|
190
|
+
} else this.column++;
|
|
191
|
+
|
|
192
|
+
switch (this.state) {
|
|
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 {[.');
|
|
196
|
+
}
|
|
197
|
+
continue;
|
|
198
|
+
|
|
199
|
+
case STATE.OPEN_KEY:
|
|
200
|
+
case STATE.OPEN_OBJECT:
|
|
201
|
+
if (isWhitespace(c)) continue;
|
|
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 "');
|
|
211
|
+
continue;
|
|
212
|
+
|
|
213
|
+
case STATE.CLOSE_KEY:
|
|
214
|
+
case STATE.CLOSE_OBJECT:
|
|
215
|
+
if (isWhitespace(c)) continue;
|
|
216
|
+
|
|
217
|
+
if (c === Char.colon) {
|
|
218
|
+
if (this.state === STATE.CLOSE_OBJECT) {
|
|
219
|
+
this.stack.push(STATE.CLOSE_OBJECT);
|
|
220
|
+
|
|
221
|
+
this._closeValue('onopenobject');
|
|
222
|
+
|
|
223
|
+
this.depth++;
|
|
224
|
+
} else this._closeValue('onkey');
|
|
225
|
+
|
|
226
|
+
this.state = STATE.VALUE;
|
|
227
|
+
} else if (c === Char.closeBrace) {
|
|
228
|
+
this.emitNode('oncloseobject');
|
|
229
|
+
this.depth--;
|
|
230
|
+
this.state = this.stack.pop() || STATE.VALUE;
|
|
231
|
+
} else if (c === Char.comma) {
|
|
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');
|
|
238
|
+
|
|
239
|
+
continue;
|
|
240
|
+
|
|
241
|
+
case STATE.OPEN_ARRAY:
|
|
242
|
+
case STATE.VALUE:
|
|
243
|
+
if (isWhitespace(c)) continue;
|
|
244
|
+
|
|
245
|
+
if (this.state === STATE.OPEN_ARRAY) {
|
|
246
|
+
this.emit('onopenarray');
|
|
247
|
+
this.depth++;
|
|
248
|
+
this.state = STATE.VALUE;
|
|
249
|
+
|
|
250
|
+
if (c === Char.closeBracket) {
|
|
251
|
+
this.emit('onclosearray');
|
|
252
|
+
this.depth--;
|
|
253
|
+
this.state = this.stack.pop() || STATE.VALUE;
|
|
254
|
+
continue;
|
|
255
|
+
} else {
|
|
256
|
+
this.stack.push(STATE.CLOSE_ARRAY);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
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) {
|
|
261
|
+
this.numberNode += '-';
|
|
262
|
+
} else if (Char._0 <= c && c <= Char._9) {
|
|
263
|
+
this.numberNode += String.fromCharCode(c);
|
|
264
|
+
this.state = STATE.NUMBER_DIGIT;
|
|
265
|
+
} else this._error('Bad value');
|
|
266
|
+
continue;
|
|
267
|
+
|
|
268
|
+
case STATE.CLOSE_ARRAY:
|
|
269
|
+
if (c === Char.comma) {
|
|
270
|
+
this.stack.push(STATE.CLOSE_ARRAY);
|
|
271
|
+
|
|
272
|
+
this._closeValue('onvalue');
|
|
273
|
+
|
|
274
|
+
this.state = STATE.VALUE;
|
|
275
|
+
} else if (c === Char.closeBracket) {
|
|
276
|
+
this.emitNode('onclosearray');
|
|
277
|
+
this.depth--;
|
|
278
|
+
this.state = this.stack.pop() || STATE.VALUE;
|
|
279
|
+
} else if (isWhitespace(c)) continue;else this._error('Bad array');
|
|
280
|
+
|
|
281
|
+
continue;
|
|
282
|
+
|
|
283
|
+
case STATE.STRING:
|
|
284
|
+
if (this.textNode === undefined) {
|
|
285
|
+
this.textNode = '';
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
let starti = i - 1;
|
|
289
|
+
let slashed = this.slashed;
|
|
290
|
+
let unicodeI = this.unicodeI;
|
|
291
|
+
|
|
292
|
+
STRING_BIGLOOP: while (true) {
|
|
293
|
+
while (unicodeI > 0) {
|
|
294
|
+
this.unicodeS += String.fromCharCode(c);
|
|
295
|
+
c = chunk.charCodeAt(i++);
|
|
296
|
+
this.position++;
|
|
297
|
+
|
|
298
|
+
if (unicodeI === 4) {
|
|
299
|
+
this.textNode += String.fromCharCode(parseInt(this.unicodeS, 16));
|
|
300
|
+
unicodeI = 0;
|
|
301
|
+
starti = i - 1;
|
|
302
|
+
} else {
|
|
303
|
+
unicodeI++;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (!c) break STRING_BIGLOOP;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (c === Char.doubleQuote && !slashed) {
|
|
310
|
+
this.state = this.stack.pop() || STATE.VALUE;
|
|
311
|
+
this.textNode += chunk.substring(starti, i - 1);
|
|
312
|
+
this.position += i - 1 - starti;
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (c === Char.backslash && !slashed) {
|
|
317
|
+
slashed = true;
|
|
318
|
+
this.textNode += chunk.substring(starti, i - 1);
|
|
319
|
+
this.position += i - 1 - starti;
|
|
320
|
+
c = chunk.charCodeAt(i++);
|
|
321
|
+
this.position++;
|
|
322
|
+
if (!c) break;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (slashed) {
|
|
326
|
+
slashed = false;
|
|
327
|
+
|
|
328
|
+
if (c === Char.n) {
|
|
329
|
+
this.textNode += '\n';
|
|
330
|
+
} else if (c === Char.r) {
|
|
331
|
+
this.textNode += '\r';
|
|
332
|
+
} else if (c === Char.t) {
|
|
333
|
+
this.textNode += '\t';
|
|
334
|
+
} else if (c === Char.f) {
|
|
335
|
+
this.textNode += '\f';
|
|
336
|
+
} else if (c === Char.b) {
|
|
337
|
+
this.textNode += '\b';
|
|
338
|
+
} else if (c === Char.u) {
|
|
339
|
+
unicodeI = 1;
|
|
340
|
+
this.unicodeS = '';
|
|
341
|
+
} else {
|
|
342
|
+
this.textNode += String.fromCharCode(c);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
c = chunk.charCodeAt(i++);
|
|
346
|
+
this.position++;
|
|
347
|
+
starti = i - 1;
|
|
348
|
+
if (!c) break;else continue;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
stringTokenPattern.lastIndex = i;
|
|
352
|
+
const reResult = stringTokenPattern.exec(chunk);
|
|
353
|
+
|
|
354
|
+
if (reResult === null) {
|
|
355
|
+
i = chunk.length + 1;
|
|
356
|
+
this.textNode += chunk.substring(starti, i - 1);
|
|
357
|
+
this.position += i - 1 - starti;
|
|
358
|
+
break;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
i = reResult.index + 1;
|
|
362
|
+
c = chunk.charCodeAt(reResult.index);
|
|
363
|
+
|
|
364
|
+
if (!c) {
|
|
365
|
+
this.textNode += chunk.substring(starti, i - 1);
|
|
366
|
+
this.position += i - 1 - starti;
|
|
367
|
+
break;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
this.slashed = slashed;
|
|
372
|
+
this.unicodeI = unicodeI;
|
|
373
|
+
continue;
|
|
374
|
+
|
|
375
|
+
case STATE.TRUE:
|
|
376
|
+
if (c === Char.r) this.state = STATE.TRUE2;else this._error("Invalid true started with t".concat(c));
|
|
377
|
+
continue;
|
|
378
|
+
|
|
379
|
+
case STATE.TRUE2:
|
|
380
|
+
if (c === Char.u) this.state = STATE.TRUE3;else this._error("Invalid true started with tr".concat(c));
|
|
381
|
+
continue;
|
|
382
|
+
|
|
383
|
+
case STATE.TRUE3:
|
|
384
|
+
if (c === Char.e) {
|
|
385
|
+
this.emit('onvalue', true);
|
|
386
|
+
this.state = this.stack.pop() || STATE.VALUE;
|
|
387
|
+
} else this._error("Invalid true started with tru".concat(c));
|
|
388
|
+
|
|
389
|
+
continue;
|
|
390
|
+
|
|
391
|
+
case STATE.FALSE:
|
|
392
|
+
if (c === Char.a) this.state = STATE.FALSE2;else this._error("Invalid false started with f".concat(c));
|
|
393
|
+
continue;
|
|
394
|
+
|
|
395
|
+
case STATE.FALSE2:
|
|
396
|
+
if (c === Char.l) this.state = STATE.FALSE3;else this._error("Invalid false started with fa".concat(c));
|
|
397
|
+
continue;
|
|
398
|
+
|
|
399
|
+
case STATE.FALSE3:
|
|
400
|
+
if (c === Char.s) this.state = STATE.FALSE4;else this._error("Invalid false started with fal".concat(c));
|
|
401
|
+
continue;
|
|
402
|
+
|
|
403
|
+
case STATE.FALSE4:
|
|
404
|
+
if (c === Char.e) {
|
|
405
|
+
this.emit('onvalue', false);
|
|
406
|
+
this.state = this.stack.pop() || STATE.VALUE;
|
|
407
|
+
} else this._error("Invalid false started with fals".concat(c));
|
|
408
|
+
|
|
409
|
+
continue;
|
|
410
|
+
|
|
411
|
+
case STATE.NULL:
|
|
412
|
+
if (c === Char.u) this.state = STATE.NULL2;else this._error("Invalid null started with n".concat(c));
|
|
413
|
+
continue;
|
|
414
|
+
|
|
415
|
+
case STATE.NULL2:
|
|
416
|
+
if (c === Char.l) this.state = STATE.NULL3;else this._error("Invalid null started with nu".concat(c));
|
|
417
|
+
continue;
|
|
418
|
+
|
|
419
|
+
case STATE.NULL3:
|
|
420
|
+
if (c === Char.l) {
|
|
421
|
+
this.emit('onvalue', null);
|
|
422
|
+
this.state = this.stack.pop() || STATE.VALUE;
|
|
423
|
+
} else this._error("Invalid null started with nul".concat(c));
|
|
424
|
+
|
|
425
|
+
continue;
|
|
426
|
+
|
|
427
|
+
case STATE.NUMBER_DECIMAL_POINT:
|
|
428
|
+
if (c === Char.period) {
|
|
429
|
+
this.numberNode += '.';
|
|
430
|
+
this.state = STATE.NUMBER_DIGIT;
|
|
431
|
+
} else this._error('Leading zero not followed by .');
|
|
432
|
+
|
|
433
|
+
continue;
|
|
434
|
+
|
|
435
|
+
case STATE.NUMBER_DIGIT:
|
|
436
|
+
if (Char._0 <= c && c <= Char._9) this.numberNode += String.fromCharCode(c);else if (c === Char.period) {
|
|
437
|
+
if (this.numberNode.indexOf('.') !== -1) this._error('Invalid number has two dots');
|
|
438
|
+
this.numberNode += '.';
|
|
439
|
+
} else if (c === Char.e || c === Char.E) {
|
|
440
|
+
if (this.numberNode.indexOf('e') !== -1 || this.numberNode.indexOf('E') !== -1) this._error('Invalid number has two exponential');
|
|
441
|
+
this.numberNode += 'e';
|
|
442
|
+
} else if (c === Char.plus || c === Char.minus) {
|
|
443
|
+
if (!(p === Char.e || p === Char.E)) this._error('Invalid symbol in number');
|
|
444
|
+
this.numberNode += String.fromCharCode(c);
|
|
445
|
+
} else {
|
|
446
|
+
this._closeNumber();
|
|
447
|
+
|
|
448
|
+
i--;
|
|
449
|
+
this.state = this.stack.pop() || STATE.VALUE;
|
|
450
|
+
}
|
|
451
|
+
continue;
|
|
452
|
+
|
|
453
|
+
default:
|
|
454
|
+
this._error("Unknown state: ".concat(this.state));
|
|
455
|
+
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
if (this.position >= this.bufferCheckPosition) {
|
|
460
|
+
checkBufferLength(this);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
this.emit('onchunkparsed');
|
|
464
|
+
return this;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
_closeValue(event = 'onvalue') {
|
|
468
|
+
if (this.textNode !== undefined) {
|
|
469
|
+
this.emit(event, this.textNode);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
this.textNode = undefined;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
_closeNumber() {
|
|
476
|
+
if (this.numberNode) this.emit('onvalue', parseFloat(this.numberNode));
|
|
477
|
+
this.numberNode = '';
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
_error(message = '') {
|
|
481
|
+
this._closeValue();
|
|
482
|
+
|
|
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);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
function isWhitespace(c) {
|
|
492
|
+
return c === Char.carriageReturn || c === Char.lineFeed || c === Char.space || c === Char.tab;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
function checkBufferLength(parser) {
|
|
496
|
+
const maxAllowed = Math.max(MAX_BUFFER_LENGTH, 10);
|
|
497
|
+
let maxActual = 0;
|
|
498
|
+
|
|
499
|
+
for (const buffer of ['textNode', 'numberNode']) {
|
|
500
|
+
const len = parser[buffer] === undefined ? 0 : parser[buffer].length;
|
|
501
|
+
|
|
502
|
+
if (len > maxAllowed) {
|
|
503
|
+
switch (buffer) {
|
|
504
|
+
case 'text':
|
|
505
|
+
break;
|
|
506
|
+
|
|
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;
|
|
517
|
+
}
|
|
518
|
+
//# sourceMappingURL=clarinet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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","constructor","options","BEGIN","textNode","undefined","numberNode","emit","end","state","VALUE","depth","_error","_closeValue","c","closed","resume","error","close","write","event","data","emitNode","chunk","i","charCodeAt","p","position","line","column","OPEN_OBJECT","OPEN_ARRAY","isWhitespace","OPEN_KEY","stack","push","CLOSE_KEY","pop","CLOSE_OBJECT","STRING","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,MAAMA,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,MAAMC,IAAI,GAAG;AACXC,EAAAA,GAAG,EAAE,IADM;AAEXC,EAAAA,QAAQ,EAAE,IAFC;AAGXC,EAAAA,cAAc,EAAE,IAHL;AAIXC,EAAAA,KAAK,EAAE,IAJI;AAMXC,EAAAA,WAAW,EAAE,IANF;AAOXC,EAAAA,IAAI,EAAE,IAPK;AAQXC,EAAAA,KAAK,EAAE,IARI;AASXC,EAAAA,KAAK,EAAE,IATI;AAUXC,EAAAA,MAAM,EAAE,IAVG;AAYXC,EAAAA,EAAE,EAAE,IAZO;AAaXC,EAAAA,EAAE,EAAE,IAbO;AAeXC,EAAAA,KAAK,EAAE,IAfI;AA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AM,CAAC9D,MAAP,uCAA6CmE,MAA7C;;AAPJ;AASD;;AACDD,IAAAA,SAAS,GAAGF,IAAI,CAACC,GAAL,CAASC,SAAT,EAAoBE,GAApB,CAAZ;AACD;;AACDN,EAAAA,MAAM,CAACL,mBAAP,GAA6BlH,iBAAiB,GAAG2H,SAApB,GAAgCJ,MAAM,CAAC/C,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"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
export default class JSONPath {
|
|
3
|
+
constructor(path = null) {
|
|
4
|
+
_defineProperty(this, "path", void 0);
|
|
5
|
+
|
|
6
|
+
this.path = ['$'];
|
|
7
|
+
|
|
8
|
+
if (path instanceof JSONPath) {
|
|
9
|
+
this.path = [...path.path];
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (Array.isArray(path)) {
|
|
14
|
+
this.path.push(...path);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (typeof path === 'string') {
|
|
19
|
+
this.path = path.split('.');
|
|
20
|
+
|
|
21
|
+
if (this.path[0] !== '$') {
|
|
22
|
+
throw new Error('JSONPaths must start with $');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
clone() {
|
|
28
|
+
return new JSONPath(this);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
toString() {
|
|
32
|
+
return this.path.join('.');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
push(name) {
|
|
36
|
+
this.path.push(name);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
pop() {
|
|
40
|
+
return this.path.pop();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
set(name) {
|
|
44
|
+
this.path[this.path.length - 1] = name;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
equals(other) {
|
|
48
|
+
if (!this || !other || this.path.length !== other.path.length) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
for (let i = 0; i < this.path.length; ++i) {
|
|
53
|
+
if (this.path[i] !== other.path[i]) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
setFieldAtPath(object, value) {
|
|
62
|
+
const path = [...this.path];
|
|
63
|
+
path.shift();
|
|
64
|
+
const field = path.pop();
|
|
65
|
+
|
|
66
|
+
for (const component of path) {
|
|
67
|
+
object = object[component];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
object[field] = value;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
getFieldAtPath(object) {
|
|
74
|
+
const path = [...this.path];
|
|
75
|
+
path.shift();
|
|
76
|
+
const field = path.pop();
|
|
77
|
+
|
|
78
|
+
for (const component of path) {
|
|
79
|
+
object = object[component];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return object[field];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=jsonpath.js.map
|