@codingame/monaco-vscode-api 1.78.5-next.0 → 1.78.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/json.js +1 -1
- package/dist/service-override/configuration.js +2 -2
- package/dist/service-override/keybindings.js +1 -1
- package/dist/services.js +2 -2
- package/dist/vscode/vs/base/common/jsonEdit.js +1 -1
- package/dist/vscode/vs/base/common/jsonFormatter.js +1 -1
- package/dist/vscode/vs/platform/extensionResourceLoader/common/extensionResourceLoader.js +1 -1
- package/dist/vscode/vs/platform/files/common/fileService.js +2 -2
- package/dist/vscode/vs/platform/telemetry/common/telemetryUtils.js +1 -1
- package/dist/vscode/vs/platform/userDataSync/common/settingsMerge.js +1 -1
- package/dist/vscode/vs/platform/workspaces/common/workspaces.js +3 -3
- package/dist/vscode/vs/workbench/api/browser/mainThreadBulkEdits.js +1 -1
- package/dist/vscode/vs/workbench/api/browser/mainThreadDiagnostics.js +1 -1
- package/dist/vscode/vs/workbench/api/browser/mainThreadDocuments.js +1 -1
- package/dist/vscode/vs/workbench/api/browser/mainThreadDocumentsAndEditors.js +1 -1
- package/dist/vscode/vs/workbench/api/browser/mainThreadFileSystemEventService.js +1 -1
- package/dist/vscode/vs/workbench/api/browser/mainThreadLanguageFeatures.js +1 -1
- package/dist/vscode/vs/workbench/api/browser/mainThreadTelemetry.js +1 -1
- package/dist/vscode/vs/workbench/api/common/extHostExtensionService.js +8 -8
- package/dist/vscode/vs/workbench/api/common/extHostTelemetry.js +1 -1
- package/dist/vscode/vs/workbench/browser/parts/dialogs/dialog.web.contribution.js +1 -1
- package/dist/vscode/vs/workbench/browser/parts/dialogs/dialogHandler.js +1 -1
- package/dist/vscode/vs/workbench/common/contributions.js +1 -1
- package/dist/vscode/vs/workbench/contrib/codeEditor/browser/languageConfigurationExtensionPoint.js +1 -1
- package/dist/vscode/vs/workbench/contrib/debug/browser/callStackEditorContribution.js +1 -1
- package/dist/vscode/vs/workbench/contrib/debug/browser/debugConfigurationManager.js +3 -3
- package/dist/vscode/vs/workbench/contrib/debug/browser/debugEditorContribution.js +2 -2
- package/dist/vscode/vs/workbench/contrib/debug/browser/debugService.js +1 -1
- package/dist/vscode/vs/workbench/contrib/debug/browser/debugSession.js +2 -2
- package/dist/vscode/vs/workbench/contrib/debug/common/debugModel.js +1 -1
- package/dist/vscode/vs/workbench/contrib/debug/common/debugStorage.js +1 -1
- package/dist/vscode/vs/workbench/contrib/files/browser/explorerService.js +1 -1
- package/dist/vscode/vs/workbench/contrib/quickaccess/browser/commandsQuickAccess.js +1 -1
- package/dist/vscode/vs/workbench/contrib/snippets/browser/snippetsFile.js +1 -1
- package/dist/vscode/vs/workbench/services/configuration/browser/configurationService.js +1 -1
- package/dist/vscode/vs/workbench/services/configuration/common/configurationEditing.js +4 -4
- package/dist/vscode/vs/workbench/services/configuration/common/jsonEditingService.js +2 -2
- package/dist/vscode/vs/workbench/services/decorations/browser/decorationsService.js +1 -1
- package/dist/vscode/vs/workbench/services/extensions/common/extensionsRegistry.js +1 -1
- package/dist/vscode/vs/workbench/services/keybinding/browser/keybindingService.js +1 -1
- package/dist/vscode/vs/workbench/services/keybinding/browser/keyboardLayoutService.js +1 -1
- package/dist/vscode/vs/workbench/services/lifecycle/common/lifecycleService.js +1 -1
- package/dist/vscode/vs/workbench/services/preferences/browser/preferencesService.js +2 -2
- package/dist/vscode/vs/workbench/services/preferences/common/preferencesModels.js +1 -1
- package/dist/vscode/vs/workbench/services/search/common/searchService.js +1 -1
- package/dist/vscode/vs/workbench/services/textfile/browser/browserTextFileService.js +1 -1
- package/dist/vscode/vs/workbench/services/textfile/browser/textFileService.js +2 -2
- package/dist/vscode/vs/workbench/services/textfile/common/encoding.js +1 -1
- package/dist/vscode/vs/workbench/services/textfile/common/textEditorService.js +1 -1
- package/dist/vscode/vs/workbench/services/textfile/common/textFileEditorModel.js +1 -1
- package/dist/vscode/vs/workbench/services/textfile/common/textFileEditorModelManager.js +1 -1
- package/dist/vscode/vs/workbench/services/textmodelResolver/common/textModelResolverService.js +1 -1
- package/dist/vscode/vs/workbench/services/themes/browser/fileIconThemeData.js +3 -3
- package/dist/vscode/vs/workbench/services/themes/browser/productIconThemeData.js +3 -3
- package/dist/vscode/vs/workbench/services/themes/browser/workbenchThemeService.js +1 -1
- package/dist/vscode/vs/workbench/services/themes/common/colorThemeData.js +5 -5
- package/dist/vscode/vs/workbench/services/userDataProfile/common/userDataProfileService.js +1 -1
- package/dist/vscode/vs/workbench/services/workingCopy/common/workingCopyBackupService.js +1 -1
- package/dist/vscode/vs/workbench/services/workingCopy/common/workingCopyFileService.js +1 -1
- package/dist/vscode/vs/workbench/services/workspaces/browser/abstractWorkspaceEditingService.js +2 -2
- package/dist/vscode/vs/workbench/services/workspaces/browser/workspacesService.js +1 -1
- package/dist/vscode-services/missing-services.js +3 -3
- package/monaco-editor-treemending.patch +819 -819
- package/package.json +3 -2
- package/dist/vscode/vs/base/common/json.js +0 -713
- package/dist/vscode/vs/base/common/performance.js +0 -18
- package/dist/vscode/vs/base/common/stream.js +0 -300
- package/dist/vscode/vs/platform/product/common/productService.js +0 -4
- package/dist/vscode/vs/platform/remote/common/remoteHosts.js +0 -18
- package/dist/vscode/vs/platform/uriIdentity/common/uriIdentity.js +0 -3
- package/dist/vscode/vs/platform/userDataProfile/common/userDataProfile.js +0 -427
|
@@ -1,713 +0,0 @@
|
|
|
1
|
-
var ParseOptions;
|
|
2
|
-
( (function(ParseOptions) {
|
|
3
|
-
ParseOptions.DEFAULT = {
|
|
4
|
-
allowTrailingComma: true
|
|
5
|
-
};
|
|
6
|
-
})(ParseOptions || (ParseOptions = {})));
|
|
7
|
-
function createScanner(text, ignoreTrivia = false) {
|
|
8
|
-
let pos = 0;
|
|
9
|
-
const len = text.length;
|
|
10
|
-
let value = '';
|
|
11
|
-
let tokenOffset = 0;
|
|
12
|
-
let token = 16 ;
|
|
13
|
-
let scanError = 0 ;
|
|
14
|
-
function scanHexDigits(count) {
|
|
15
|
-
let digits = 0;
|
|
16
|
-
let hexValue = 0;
|
|
17
|
-
while (digits < count) {
|
|
18
|
-
const ch = text.charCodeAt(pos);
|
|
19
|
-
if (ch >= 48 && ch <= 57 ) {
|
|
20
|
-
hexValue = hexValue * 16 + ch - 48 ;
|
|
21
|
-
}
|
|
22
|
-
else if (ch >= 65 && ch <= 70 ) {
|
|
23
|
-
hexValue = hexValue * 16 + ch - 65 + 10;
|
|
24
|
-
}
|
|
25
|
-
else if (ch >= 97 && ch <= 102 ) {
|
|
26
|
-
hexValue = hexValue * 16 + ch - 97 + 10;
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
break;
|
|
30
|
-
}
|
|
31
|
-
pos++;
|
|
32
|
-
digits++;
|
|
33
|
-
}
|
|
34
|
-
if (digits < count) {
|
|
35
|
-
hexValue = -1;
|
|
36
|
-
}
|
|
37
|
-
return hexValue;
|
|
38
|
-
}
|
|
39
|
-
function setPosition(newPosition) {
|
|
40
|
-
pos = newPosition;
|
|
41
|
-
value = '';
|
|
42
|
-
tokenOffset = 0;
|
|
43
|
-
token = 16 ;
|
|
44
|
-
scanError = 0 ;
|
|
45
|
-
}
|
|
46
|
-
function scanNumber() {
|
|
47
|
-
const start = pos;
|
|
48
|
-
if (text.charCodeAt(pos) === 48 ) {
|
|
49
|
-
pos++;
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
pos++;
|
|
53
|
-
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
54
|
-
pos++;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
if (pos < text.length && text.charCodeAt(pos) === 46 ) {
|
|
58
|
-
pos++;
|
|
59
|
-
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
60
|
-
pos++;
|
|
61
|
-
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
62
|
-
pos++;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
scanError = 3 ;
|
|
67
|
-
return text.substring(start, pos);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
let end = pos;
|
|
71
|
-
if (pos < text.length && ((text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101) )) {
|
|
72
|
-
pos++;
|
|
73
|
-
if (pos < text.length && text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45 ) {
|
|
74
|
-
pos++;
|
|
75
|
-
}
|
|
76
|
-
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
77
|
-
pos++;
|
|
78
|
-
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
79
|
-
pos++;
|
|
80
|
-
}
|
|
81
|
-
end = pos;
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
scanError = 3 ;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return text.substring(start, end);
|
|
88
|
-
}
|
|
89
|
-
function scanString() {
|
|
90
|
-
let result = '', start = pos;
|
|
91
|
-
while (true) {
|
|
92
|
-
if (pos >= len) {
|
|
93
|
-
result += text.substring(start, pos);
|
|
94
|
-
scanError = 2 ;
|
|
95
|
-
break;
|
|
96
|
-
}
|
|
97
|
-
const ch = text.charCodeAt(pos);
|
|
98
|
-
if (ch === 34 ) {
|
|
99
|
-
result += text.substring(start, pos);
|
|
100
|
-
pos++;
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
if (ch === 92 ) {
|
|
104
|
-
result += text.substring(start, pos);
|
|
105
|
-
pos++;
|
|
106
|
-
if (pos >= len) {
|
|
107
|
-
scanError = 2 ;
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
const ch2 = text.charCodeAt(pos++);
|
|
111
|
-
switch (ch2) {
|
|
112
|
-
case 34 :
|
|
113
|
-
result += '\"';
|
|
114
|
-
break;
|
|
115
|
-
case 92 :
|
|
116
|
-
result += '\\';
|
|
117
|
-
break;
|
|
118
|
-
case 47 :
|
|
119
|
-
result += '/';
|
|
120
|
-
break;
|
|
121
|
-
case 98 :
|
|
122
|
-
result += '\b';
|
|
123
|
-
break;
|
|
124
|
-
case 102 :
|
|
125
|
-
result += '\f';
|
|
126
|
-
break;
|
|
127
|
-
case 110 :
|
|
128
|
-
result += '\n';
|
|
129
|
-
break;
|
|
130
|
-
case 114 :
|
|
131
|
-
result += '\r';
|
|
132
|
-
break;
|
|
133
|
-
case 116 :
|
|
134
|
-
result += '\t';
|
|
135
|
-
break;
|
|
136
|
-
case 117 : {
|
|
137
|
-
const ch3 = scanHexDigits(4);
|
|
138
|
-
if (ch3 >= 0) {
|
|
139
|
-
result += String.fromCharCode(ch3);
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
scanError = 4 ;
|
|
143
|
-
}
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
default:
|
|
147
|
-
scanError = 5 ;
|
|
148
|
-
}
|
|
149
|
-
start = pos;
|
|
150
|
-
continue;
|
|
151
|
-
}
|
|
152
|
-
if (ch >= 0 && ch <= 0x1F) {
|
|
153
|
-
if (isLineBreak(ch)) {
|
|
154
|
-
result += text.substring(start, pos);
|
|
155
|
-
scanError = 2 ;
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
scanError = 6 ;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
pos++;
|
|
163
|
-
}
|
|
164
|
-
return result;
|
|
165
|
-
}
|
|
166
|
-
function scanNext() {
|
|
167
|
-
value = '';
|
|
168
|
-
scanError = 0 ;
|
|
169
|
-
tokenOffset = pos;
|
|
170
|
-
if (pos >= len) {
|
|
171
|
-
tokenOffset = len;
|
|
172
|
-
return token = 17 ;
|
|
173
|
-
}
|
|
174
|
-
let code = text.charCodeAt(pos);
|
|
175
|
-
if (isWhitespace(code)) {
|
|
176
|
-
do {
|
|
177
|
-
pos++;
|
|
178
|
-
value += String.fromCharCode(code);
|
|
179
|
-
code = text.charCodeAt(pos);
|
|
180
|
-
} while (isWhitespace(code));
|
|
181
|
-
return token = 15 ;
|
|
182
|
-
}
|
|
183
|
-
if (isLineBreak(code)) {
|
|
184
|
-
pos++;
|
|
185
|
-
value += String.fromCharCode(code);
|
|
186
|
-
if (code === 13 && text.charCodeAt(pos) === 10 ) {
|
|
187
|
-
pos++;
|
|
188
|
-
value += '\n';
|
|
189
|
-
}
|
|
190
|
-
return token = 14 ;
|
|
191
|
-
}
|
|
192
|
-
switch (code) {
|
|
193
|
-
case 123 :
|
|
194
|
-
pos++;
|
|
195
|
-
return token = 1 ;
|
|
196
|
-
case 125 :
|
|
197
|
-
pos++;
|
|
198
|
-
return token = 2 ;
|
|
199
|
-
case 91 :
|
|
200
|
-
pos++;
|
|
201
|
-
return token = 3 ;
|
|
202
|
-
case 93 :
|
|
203
|
-
pos++;
|
|
204
|
-
return token = 4 ;
|
|
205
|
-
case 58 :
|
|
206
|
-
pos++;
|
|
207
|
-
return token = 6 ;
|
|
208
|
-
case 44 :
|
|
209
|
-
pos++;
|
|
210
|
-
return token = 5 ;
|
|
211
|
-
case 34 :
|
|
212
|
-
pos++;
|
|
213
|
-
value = scanString();
|
|
214
|
-
return token = 10 ;
|
|
215
|
-
case 47 : {
|
|
216
|
-
const start = pos - 1;
|
|
217
|
-
if (text.charCodeAt(pos + 1) === 47 ) {
|
|
218
|
-
pos += 2;
|
|
219
|
-
while (pos < len) {
|
|
220
|
-
if (isLineBreak(text.charCodeAt(pos))) {
|
|
221
|
-
break;
|
|
222
|
-
}
|
|
223
|
-
pos++;
|
|
224
|
-
}
|
|
225
|
-
value = text.substring(start, pos);
|
|
226
|
-
return token = 12 ;
|
|
227
|
-
}
|
|
228
|
-
if (text.charCodeAt(pos + 1) === 42 ) {
|
|
229
|
-
pos += 2;
|
|
230
|
-
const safeLength = len - 1;
|
|
231
|
-
let commentClosed = false;
|
|
232
|
-
while (pos < safeLength) {
|
|
233
|
-
const ch = text.charCodeAt(pos);
|
|
234
|
-
if (ch === 42 && text.charCodeAt(pos + 1) === 47 ) {
|
|
235
|
-
pos += 2;
|
|
236
|
-
commentClosed = true;
|
|
237
|
-
break;
|
|
238
|
-
}
|
|
239
|
-
pos++;
|
|
240
|
-
}
|
|
241
|
-
if (!commentClosed) {
|
|
242
|
-
pos++;
|
|
243
|
-
scanError = 1 ;
|
|
244
|
-
}
|
|
245
|
-
value = text.substring(start, pos);
|
|
246
|
-
return token = 13 ;
|
|
247
|
-
}
|
|
248
|
-
value += String.fromCharCode(code);
|
|
249
|
-
pos++;
|
|
250
|
-
return token = 16 ;
|
|
251
|
-
}
|
|
252
|
-
case 45 :
|
|
253
|
-
value += String.fromCharCode(code);
|
|
254
|
-
pos++;
|
|
255
|
-
if (pos === len || !isDigit(text.charCodeAt(pos))) {
|
|
256
|
-
return token = 16 ;
|
|
257
|
-
}
|
|
258
|
-
case 48 :
|
|
259
|
-
case 49 :
|
|
260
|
-
case 50 :
|
|
261
|
-
case 51 :
|
|
262
|
-
case 52 :
|
|
263
|
-
case 53 :
|
|
264
|
-
case 54 :
|
|
265
|
-
case 55 :
|
|
266
|
-
case 56 :
|
|
267
|
-
case 57 :
|
|
268
|
-
value += scanNumber();
|
|
269
|
-
return token = 11 ;
|
|
270
|
-
default:
|
|
271
|
-
while (pos < len && isUnknownContentCharacter(code)) {
|
|
272
|
-
pos++;
|
|
273
|
-
code = text.charCodeAt(pos);
|
|
274
|
-
}
|
|
275
|
-
if (tokenOffset !== pos) {
|
|
276
|
-
value = text.substring(tokenOffset, pos);
|
|
277
|
-
switch (value) {
|
|
278
|
-
case 'true': return token = 8 ;
|
|
279
|
-
case 'false': return token = 9 ;
|
|
280
|
-
case 'null': return token = 7 ;
|
|
281
|
-
}
|
|
282
|
-
return token = 16 ;
|
|
283
|
-
}
|
|
284
|
-
value += String.fromCharCode(code);
|
|
285
|
-
pos++;
|
|
286
|
-
return token = 16 ;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
function isUnknownContentCharacter(code) {
|
|
290
|
-
if (isWhitespace(code) || isLineBreak(code)) {
|
|
291
|
-
return false;
|
|
292
|
-
}
|
|
293
|
-
switch (code) {
|
|
294
|
-
case 125 :
|
|
295
|
-
case 93 :
|
|
296
|
-
case 123 :
|
|
297
|
-
case 91 :
|
|
298
|
-
case 34 :
|
|
299
|
-
case 58 :
|
|
300
|
-
case 44 :
|
|
301
|
-
case 47 :
|
|
302
|
-
return false;
|
|
303
|
-
}
|
|
304
|
-
return true;
|
|
305
|
-
}
|
|
306
|
-
function scanNextNonTrivia() {
|
|
307
|
-
let result;
|
|
308
|
-
do {
|
|
309
|
-
result = scanNext();
|
|
310
|
-
} while (result >= 12 && result <= 15 );
|
|
311
|
-
return result;
|
|
312
|
-
}
|
|
313
|
-
return {
|
|
314
|
-
setPosition: setPosition,
|
|
315
|
-
getPosition: () => pos,
|
|
316
|
-
scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
|
|
317
|
-
getToken: () => token,
|
|
318
|
-
getTokenValue: () => value,
|
|
319
|
-
getTokenOffset: () => tokenOffset,
|
|
320
|
-
getTokenLength: () => pos - tokenOffset,
|
|
321
|
-
getTokenError: () => scanError
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
function isWhitespace(ch) {
|
|
325
|
-
return ch === 32 || ch === 9 || ch === 11 || ch === 12 ||
|
|
326
|
-
ch === 160 || ch === 5760 || ch >= 8192 && ch <= 8203 ||
|
|
327
|
-
ch === 8239 || ch === 8287 || ch === 12288 || ch === 65279 ;
|
|
328
|
-
}
|
|
329
|
-
function isLineBreak(ch) {
|
|
330
|
-
return ch === 10 || ch === 13 || ch === 8232 || ch === 8233 ;
|
|
331
|
-
}
|
|
332
|
-
function isDigit(ch) {
|
|
333
|
-
return ch >= 48 && ch <= 57 ;
|
|
334
|
-
}
|
|
335
|
-
function parse(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
336
|
-
let currentProperty = null;
|
|
337
|
-
let currentParent = [];
|
|
338
|
-
const previousParents = [];
|
|
339
|
-
function onValue(value) {
|
|
340
|
-
if (Array.isArray(currentParent)) {
|
|
341
|
-
currentParent.push(value);
|
|
342
|
-
}
|
|
343
|
-
else if (currentProperty !== null) {
|
|
344
|
-
currentParent[currentProperty] = value;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
const visitor = {
|
|
348
|
-
onObjectBegin: () => {
|
|
349
|
-
const object = {};
|
|
350
|
-
onValue(object);
|
|
351
|
-
previousParents.push(currentParent);
|
|
352
|
-
currentParent = object;
|
|
353
|
-
currentProperty = null;
|
|
354
|
-
},
|
|
355
|
-
onObjectProperty: (name) => {
|
|
356
|
-
currentProperty = name;
|
|
357
|
-
},
|
|
358
|
-
onObjectEnd: () => {
|
|
359
|
-
currentParent = previousParents.pop();
|
|
360
|
-
},
|
|
361
|
-
onArrayBegin: () => {
|
|
362
|
-
const array = [];
|
|
363
|
-
onValue(array);
|
|
364
|
-
previousParents.push(currentParent);
|
|
365
|
-
currentParent = array;
|
|
366
|
-
currentProperty = null;
|
|
367
|
-
},
|
|
368
|
-
onArrayEnd: () => {
|
|
369
|
-
currentParent = previousParents.pop();
|
|
370
|
-
},
|
|
371
|
-
onLiteralValue: onValue,
|
|
372
|
-
onError: (error, offset, length) => {
|
|
373
|
-
errors.push({ error, offset, length });
|
|
374
|
-
}
|
|
375
|
-
};
|
|
376
|
-
visit(text, visitor, options);
|
|
377
|
-
return currentParent[0];
|
|
378
|
-
}
|
|
379
|
-
function parseTree(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
380
|
-
let currentParent = { type: 'array', offset: -1, length: -1, children: [], parent: undefined };
|
|
381
|
-
function ensurePropertyComplete(endOffset) {
|
|
382
|
-
if (currentParent.type === 'property') {
|
|
383
|
-
currentParent.length = endOffset - currentParent.offset;
|
|
384
|
-
currentParent = currentParent.parent;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
function onValue(valueNode) {
|
|
388
|
-
currentParent.children.push(valueNode);
|
|
389
|
-
return valueNode;
|
|
390
|
-
}
|
|
391
|
-
const visitor = {
|
|
392
|
-
onObjectBegin: (offset) => {
|
|
393
|
-
currentParent = onValue({ type: 'object', offset, length: -1, parent: currentParent, children: [] });
|
|
394
|
-
},
|
|
395
|
-
onObjectProperty: (name, offset, length) => {
|
|
396
|
-
currentParent = onValue({ type: 'property', offset, length: -1, parent: currentParent, children: [] });
|
|
397
|
-
currentParent.children.push({ type: 'string', value: name, offset, length, parent: currentParent });
|
|
398
|
-
},
|
|
399
|
-
onObjectEnd: (offset, length) => {
|
|
400
|
-
currentParent.length = offset + length - currentParent.offset;
|
|
401
|
-
currentParent = currentParent.parent;
|
|
402
|
-
ensurePropertyComplete(offset + length);
|
|
403
|
-
},
|
|
404
|
-
onArrayBegin: (offset, length) => {
|
|
405
|
-
currentParent = onValue({ type: 'array', offset, length: -1, parent: currentParent, children: [] });
|
|
406
|
-
},
|
|
407
|
-
onArrayEnd: (offset, length) => {
|
|
408
|
-
currentParent.length = offset + length - currentParent.offset;
|
|
409
|
-
currentParent = currentParent.parent;
|
|
410
|
-
ensurePropertyComplete(offset + length);
|
|
411
|
-
},
|
|
412
|
-
onLiteralValue: (value, offset, length) => {
|
|
413
|
-
onValue({ type: getNodeType(value), offset, length, parent: currentParent, value });
|
|
414
|
-
ensurePropertyComplete(offset + length);
|
|
415
|
-
},
|
|
416
|
-
onSeparator: (sep, offset, length) => {
|
|
417
|
-
if (currentParent.type === 'property') {
|
|
418
|
-
if (sep === ':') {
|
|
419
|
-
currentParent.colonOffset = offset;
|
|
420
|
-
}
|
|
421
|
-
else if (sep === ',') {
|
|
422
|
-
ensurePropertyComplete(offset);
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
},
|
|
426
|
-
onError: (error, offset, length) => {
|
|
427
|
-
errors.push({ error, offset, length });
|
|
428
|
-
}
|
|
429
|
-
};
|
|
430
|
-
visit(text, visitor, options);
|
|
431
|
-
const result = currentParent.children[0];
|
|
432
|
-
if (result) {
|
|
433
|
-
delete result.parent;
|
|
434
|
-
}
|
|
435
|
-
return result;
|
|
436
|
-
}
|
|
437
|
-
function findNodeAtLocation(root, path) {
|
|
438
|
-
if (!root) {
|
|
439
|
-
return undefined;
|
|
440
|
-
}
|
|
441
|
-
let node = root;
|
|
442
|
-
for (const segment of path) {
|
|
443
|
-
if (typeof segment === 'string') {
|
|
444
|
-
if (node.type !== 'object' || !Array.isArray(node.children)) {
|
|
445
|
-
return undefined;
|
|
446
|
-
}
|
|
447
|
-
let found = false;
|
|
448
|
-
for (const propertyNode of node.children) {
|
|
449
|
-
if (Array.isArray(propertyNode.children) && propertyNode.children[0].value === segment) {
|
|
450
|
-
node = propertyNode.children[1];
|
|
451
|
-
found = true;
|
|
452
|
-
break;
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
if (!found) {
|
|
456
|
-
return undefined;
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
else {
|
|
460
|
-
const index = segment;
|
|
461
|
-
if (node.type !== 'array' || index < 0 || !Array.isArray(node.children) || index >= node.children.length) {
|
|
462
|
-
return undefined;
|
|
463
|
-
}
|
|
464
|
-
node = node.children[index];
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
return node;
|
|
468
|
-
}
|
|
469
|
-
function visit(text, visitor, options = ParseOptions.DEFAULT) {
|
|
470
|
-
const _scanner = createScanner(text, false);
|
|
471
|
-
function toNoArgVisit(visitFunction) {
|
|
472
|
-
return visitFunction ? () => visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength()) : () => true;
|
|
473
|
-
}
|
|
474
|
-
function toOneArgVisit(visitFunction) {
|
|
475
|
-
return visitFunction ? (arg) => visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength()) : () => true;
|
|
476
|
-
}
|
|
477
|
-
const onObjectBegin = toNoArgVisit(visitor.onObjectBegin), onObjectProperty = toOneArgVisit(visitor.onObjectProperty), onObjectEnd = toNoArgVisit(visitor.onObjectEnd), onArrayBegin = toNoArgVisit(visitor.onArrayBegin), onArrayEnd = toNoArgVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisit(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
|
|
478
|
-
const disallowComments = options && options.disallowComments;
|
|
479
|
-
const allowTrailingComma = options && options.allowTrailingComma;
|
|
480
|
-
function scanNext() {
|
|
481
|
-
while (true) {
|
|
482
|
-
const token = _scanner.scan();
|
|
483
|
-
switch (_scanner.getTokenError()) {
|
|
484
|
-
case 4 :
|
|
485
|
-
handleError(14 );
|
|
486
|
-
break;
|
|
487
|
-
case 5 :
|
|
488
|
-
handleError(15 );
|
|
489
|
-
break;
|
|
490
|
-
case 3 :
|
|
491
|
-
handleError(13 );
|
|
492
|
-
break;
|
|
493
|
-
case 1 :
|
|
494
|
-
if (!disallowComments) {
|
|
495
|
-
handleError(11 );
|
|
496
|
-
}
|
|
497
|
-
break;
|
|
498
|
-
case 2 :
|
|
499
|
-
handleError(12 );
|
|
500
|
-
break;
|
|
501
|
-
case 6 :
|
|
502
|
-
handleError(16 );
|
|
503
|
-
break;
|
|
504
|
-
}
|
|
505
|
-
switch (token) {
|
|
506
|
-
case 12 :
|
|
507
|
-
case 13 :
|
|
508
|
-
if (disallowComments) {
|
|
509
|
-
handleError(10 );
|
|
510
|
-
}
|
|
511
|
-
else {
|
|
512
|
-
onComment();
|
|
513
|
-
}
|
|
514
|
-
break;
|
|
515
|
-
case 16 :
|
|
516
|
-
handleError(1 );
|
|
517
|
-
break;
|
|
518
|
-
case 15 :
|
|
519
|
-
case 14 :
|
|
520
|
-
break;
|
|
521
|
-
default:
|
|
522
|
-
return token;
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
function handleError(error, skipUntilAfter = [], skipUntil = []) {
|
|
527
|
-
onError(error);
|
|
528
|
-
if (skipUntilAfter.length + skipUntil.length > 0) {
|
|
529
|
-
let token = _scanner.getToken();
|
|
530
|
-
while (token !== 17 ) {
|
|
531
|
-
if (skipUntilAfter.indexOf(token) !== -1) {
|
|
532
|
-
scanNext();
|
|
533
|
-
break;
|
|
534
|
-
}
|
|
535
|
-
else if (skipUntil.indexOf(token) !== -1) {
|
|
536
|
-
break;
|
|
537
|
-
}
|
|
538
|
-
token = scanNext();
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
function parseString(isValue) {
|
|
543
|
-
const value = _scanner.getTokenValue();
|
|
544
|
-
if (isValue) {
|
|
545
|
-
onLiteralValue(value);
|
|
546
|
-
}
|
|
547
|
-
else {
|
|
548
|
-
onObjectProperty(value);
|
|
549
|
-
}
|
|
550
|
-
scanNext();
|
|
551
|
-
return true;
|
|
552
|
-
}
|
|
553
|
-
function parseLiteral() {
|
|
554
|
-
switch (_scanner.getToken()) {
|
|
555
|
-
case 11 : {
|
|
556
|
-
let value = 0;
|
|
557
|
-
try {
|
|
558
|
-
value = JSON.parse(_scanner.getTokenValue());
|
|
559
|
-
if (typeof value !== 'number') {
|
|
560
|
-
handleError(2 );
|
|
561
|
-
value = 0;
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
catch (e) {
|
|
565
|
-
handleError(2 );
|
|
566
|
-
}
|
|
567
|
-
onLiteralValue(value);
|
|
568
|
-
break;
|
|
569
|
-
}
|
|
570
|
-
case 7 :
|
|
571
|
-
onLiteralValue(null);
|
|
572
|
-
break;
|
|
573
|
-
case 8 :
|
|
574
|
-
onLiteralValue(true);
|
|
575
|
-
break;
|
|
576
|
-
case 9 :
|
|
577
|
-
onLiteralValue(false);
|
|
578
|
-
break;
|
|
579
|
-
default:
|
|
580
|
-
return false;
|
|
581
|
-
}
|
|
582
|
-
scanNext();
|
|
583
|
-
return true;
|
|
584
|
-
}
|
|
585
|
-
function parseProperty() {
|
|
586
|
-
if (_scanner.getToken() !== 10 ) {
|
|
587
|
-
handleError(3 , [], [2 , 5 ]);
|
|
588
|
-
return false;
|
|
589
|
-
}
|
|
590
|
-
parseString(false);
|
|
591
|
-
if (_scanner.getToken() === 6 ) {
|
|
592
|
-
onSeparator(':');
|
|
593
|
-
scanNext();
|
|
594
|
-
if (!parseValue()) {
|
|
595
|
-
handleError(4 , [], [2 , 5 ]);
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
else {
|
|
599
|
-
handleError(5 , [], [2 , 5 ]);
|
|
600
|
-
}
|
|
601
|
-
return true;
|
|
602
|
-
}
|
|
603
|
-
function parseObject() {
|
|
604
|
-
onObjectBegin();
|
|
605
|
-
scanNext();
|
|
606
|
-
let needsComma = false;
|
|
607
|
-
while (_scanner.getToken() !== 2 && _scanner.getToken() !== 17 ) {
|
|
608
|
-
if (_scanner.getToken() === 5 ) {
|
|
609
|
-
if (!needsComma) {
|
|
610
|
-
handleError(4 , [], []);
|
|
611
|
-
}
|
|
612
|
-
onSeparator(',');
|
|
613
|
-
scanNext();
|
|
614
|
-
if (_scanner.getToken() === 2 && allowTrailingComma) {
|
|
615
|
-
break;
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
else if (needsComma) {
|
|
619
|
-
handleError(6 , [], []);
|
|
620
|
-
}
|
|
621
|
-
if (!parseProperty()) {
|
|
622
|
-
handleError(4 , [], [2 , 5 ]);
|
|
623
|
-
}
|
|
624
|
-
needsComma = true;
|
|
625
|
-
}
|
|
626
|
-
onObjectEnd();
|
|
627
|
-
if (_scanner.getToken() !== 2 ) {
|
|
628
|
-
handleError(7 , [2 ], []);
|
|
629
|
-
}
|
|
630
|
-
else {
|
|
631
|
-
scanNext();
|
|
632
|
-
}
|
|
633
|
-
return true;
|
|
634
|
-
}
|
|
635
|
-
function parseArray() {
|
|
636
|
-
onArrayBegin();
|
|
637
|
-
scanNext();
|
|
638
|
-
let needsComma = false;
|
|
639
|
-
while (_scanner.getToken() !== 4 && _scanner.getToken() !== 17 ) {
|
|
640
|
-
if (_scanner.getToken() === 5 ) {
|
|
641
|
-
if (!needsComma) {
|
|
642
|
-
handleError(4 , [], []);
|
|
643
|
-
}
|
|
644
|
-
onSeparator(',');
|
|
645
|
-
scanNext();
|
|
646
|
-
if (_scanner.getToken() === 4 && allowTrailingComma) {
|
|
647
|
-
break;
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
else if (needsComma) {
|
|
651
|
-
handleError(6 , [], []);
|
|
652
|
-
}
|
|
653
|
-
if (!parseValue()) {
|
|
654
|
-
handleError(4 , [], [4 , 5 ]);
|
|
655
|
-
}
|
|
656
|
-
needsComma = true;
|
|
657
|
-
}
|
|
658
|
-
onArrayEnd();
|
|
659
|
-
if (_scanner.getToken() !== 4 ) {
|
|
660
|
-
handleError(8 , [4 ], []);
|
|
661
|
-
}
|
|
662
|
-
else {
|
|
663
|
-
scanNext();
|
|
664
|
-
}
|
|
665
|
-
return true;
|
|
666
|
-
}
|
|
667
|
-
function parseValue() {
|
|
668
|
-
switch (_scanner.getToken()) {
|
|
669
|
-
case 3 :
|
|
670
|
-
return parseArray();
|
|
671
|
-
case 1 :
|
|
672
|
-
return parseObject();
|
|
673
|
-
case 10 :
|
|
674
|
-
return parseString(true);
|
|
675
|
-
default:
|
|
676
|
-
return parseLiteral();
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
scanNext();
|
|
680
|
-
if (_scanner.getToken() === 17 ) {
|
|
681
|
-
if (options.allowEmptyContent) {
|
|
682
|
-
return true;
|
|
683
|
-
}
|
|
684
|
-
handleError(4 , [], []);
|
|
685
|
-
return false;
|
|
686
|
-
}
|
|
687
|
-
if (!parseValue()) {
|
|
688
|
-
handleError(4 , [], []);
|
|
689
|
-
return false;
|
|
690
|
-
}
|
|
691
|
-
if (_scanner.getToken() !== 17 ) {
|
|
692
|
-
handleError(9 , [], []);
|
|
693
|
-
}
|
|
694
|
-
return true;
|
|
695
|
-
}
|
|
696
|
-
function getNodeType(value) {
|
|
697
|
-
switch (typeof value) {
|
|
698
|
-
case 'boolean': return 'boolean';
|
|
699
|
-
case 'number': return 'number';
|
|
700
|
-
case 'string': return 'string';
|
|
701
|
-
case 'object': {
|
|
702
|
-
if (!value) {
|
|
703
|
-
return 'null';
|
|
704
|
-
}
|
|
705
|
-
else if (Array.isArray(value)) {
|
|
706
|
-
return 'array';
|
|
707
|
-
}
|
|
708
|
-
return 'object';
|
|
709
|
-
}
|
|
710
|
-
default: return 'null';
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
export { ParseOptions, createScanner, findNodeAtLocation, getNodeType, parse, parseTree, visit };
|