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