@optique/core 0.9.0-dev.217 → 0.9.0-dev.224
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/constructs.cjs +602 -1332
- package/dist/constructs.d.cts +62 -182
- package/dist/constructs.d.ts +62 -182
- package/dist/constructs.js +602 -1332
- package/dist/facade.cjs +144 -188
- package/dist/facade.d.cts +3 -41
- package/dist/facade.d.ts +3 -41
- package/dist/facade.js +145 -187
- package/dist/index.cjs +1 -8
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/message.cjs +50 -0
- package/dist/message.d.cts +66 -1
- package/dist/message.d.ts +66 -1
- package/dist/message.js +50 -1
- package/dist/modifiers.cjs +79 -228
- package/dist/modifiers.d.cts +6 -11
- package/dist/modifiers.d.ts +6 -11
- package/dist/modifiers.js +79 -228
- package/dist/parser.cjs +33 -217
- package/dist/parser.d.cts +18 -202
- package/dist/parser.d.ts +18 -202
- package/dist/parser.js +34 -212
- package/dist/primitives.cjs +97 -242
- package/dist/primitives.d.cts +10 -14
- package/dist/primitives.d.ts +10 -14
- package/dist/primitives.js +97 -242
- package/dist/valueparser.cjs +3 -16
- package/dist/valueparser.d.cts +16 -29
- package/dist/valueparser.d.ts +16 -29
- package/dist/valueparser.js +4 -17
- package/package.json +1 -1
package/dist/constructs.cjs
CHANGED
|
@@ -117,79 +117,45 @@ function generateNoMatchError(context) {
|
|
|
117
117
|
* Creates a complete() method shared by or() and longestMatch().
|
|
118
118
|
* @internal
|
|
119
119
|
*/
|
|
120
|
-
function createExclusiveComplete(parsers, options, noMatchContext
|
|
121
|
-
const syncParsers = parsers;
|
|
120
|
+
function createExclusiveComplete(parsers, options, noMatchContext) {
|
|
122
121
|
return (state) => {
|
|
123
122
|
if (state == null) return {
|
|
124
123
|
success: false,
|
|
125
124
|
error: getNoMatchError(options, noMatchContext)
|
|
126
125
|
};
|
|
127
126
|
const [i, result] = state;
|
|
128
|
-
if (
|
|
127
|
+
if (result.success) return parsers[i].complete(result.next.state);
|
|
128
|
+
return {
|
|
129
129
|
success: false,
|
|
130
130
|
error: result.error
|
|
131
131
|
};
|
|
132
|
-
if (isAsync) return (async () => {
|
|
133
|
-
const completeResult = await parsers[i].complete(result.next.state);
|
|
134
|
-
return completeResult;
|
|
135
|
-
})();
|
|
136
|
-
return syncParsers[i].complete(result.next.state);
|
|
137
132
|
};
|
|
138
133
|
}
|
|
139
134
|
/**
|
|
140
135
|
* Creates a suggest() method shared by or() and longestMatch().
|
|
141
136
|
* @internal
|
|
142
137
|
*/
|
|
143
|
-
function createExclusiveSuggest(parsers
|
|
144
|
-
const syncParsers = parsers;
|
|
145
|
-
if (isAsync) return (context, prefix) => {
|
|
146
|
-
return async function* () {
|
|
147
|
-
const suggestions = [];
|
|
148
|
-
if (context.state == null) for (const parser of parsers) {
|
|
149
|
-
const parserSuggestions = parser.suggest({
|
|
150
|
-
...context,
|
|
151
|
-
state: parser.initialState
|
|
152
|
-
}, prefix);
|
|
153
|
-
if (parser.$mode === "async") for await (const s of parserSuggestions) suggestions.push(s);
|
|
154
|
-
else suggestions.push(...parserSuggestions);
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
const [index, parserResult] = context.state;
|
|
158
|
-
if (parserResult.success) {
|
|
159
|
-
const parser = parsers[index];
|
|
160
|
-
const parserSuggestions = parser.suggest({
|
|
161
|
-
...context,
|
|
162
|
-
state: parserResult.next.state
|
|
163
|
-
}, prefix);
|
|
164
|
-
if (parser.$mode === "async") for await (const s of parserSuggestions) suggestions.push(s);
|
|
165
|
-
else suggestions.push(...parserSuggestions);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
yield* require_suggestion.deduplicateSuggestions(suggestions);
|
|
169
|
-
}();
|
|
170
|
-
};
|
|
138
|
+
function createExclusiveSuggest(parsers) {
|
|
171
139
|
return (context, prefix) => {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
140
|
+
const suggestions = [];
|
|
141
|
+
if (context.state == null) for (const parser of parsers) {
|
|
142
|
+
const parserSuggestions = parser.suggest({
|
|
143
|
+
...context,
|
|
144
|
+
state: parser.initialState
|
|
145
|
+
}, prefix);
|
|
146
|
+
suggestions.push(...parserSuggestions);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
const [index, parserResult] = context.state;
|
|
150
|
+
if (parserResult.success) {
|
|
151
|
+
const parserSuggestions = parsers[index].suggest({
|
|
176
152
|
...context,
|
|
177
|
-
state:
|
|
153
|
+
state: parserResult.next.state
|
|
178
154
|
}, prefix);
|
|
179
155
|
suggestions.push(...parserSuggestions);
|
|
180
156
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
if (parserResult.success) {
|
|
184
|
-
const parserSuggestions = syncParsers[index].suggest({
|
|
185
|
-
...context,
|
|
186
|
-
state: parserResult.next.state
|
|
187
|
-
}, prefix);
|
|
188
|
-
suggestions.push(...parserSuggestions);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
yield* require_suggestion.deduplicateSuggestions(suggestions);
|
|
192
|
-
}();
|
|
157
|
+
}
|
|
158
|
+
return require_suggestion.deduplicateSuggestions(suggestions);
|
|
193
159
|
};
|
|
194
160
|
}
|
|
195
161
|
/**
|
|
@@ -225,80 +191,7 @@ function or(...args) {
|
|
|
225
191
|
options = void 0;
|
|
226
192
|
}
|
|
227
193
|
const noMatchContext = analyzeNoMatchContext(parsers);
|
|
228
|
-
const combinedMode = parsers.some((p) => p.$mode === "async") ? "async" : "sync";
|
|
229
|
-
const isAsync = combinedMode === "async";
|
|
230
|
-
const syncParsers = parsers;
|
|
231
|
-
const getInitialError = (context) => ({
|
|
232
|
-
consumed: 0,
|
|
233
|
-
error: context.buffer.length < 1 ? getNoMatchError(options, noMatchContext) : createUnexpectedInputError(context.buffer[0], context.usage, options)
|
|
234
|
-
});
|
|
235
|
-
const parseSync = (context) => {
|
|
236
|
-
let error = getInitialError(context);
|
|
237
|
-
const orderedParsers = syncParsers.map((p, i) => [p, i]);
|
|
238
|
-
orderedParsers.sort(([_, a], [__, b]) => context.state?.[0] === a ? -1 : context.state?.[0] === b ? 1 : a - b);
|
|
239
|
-
for (const [parser, i] of orderedParsers) {
|
|
240
|
-
const result = parser.parse({
|
|
241
|
-
...context,
|
|
242
|
-
state: context.state == null || context.state[0] !== i || !context.state[1].success ? parser.initialState : context.state[1].next.state
|
|
243
|
-
});
|
|
244
|
-
if (result.success && result.consumed.length > 0) {
|
|
245
|
-
if (context.state?.[0] !== i && context.state?.[1].success) return {
|
|
246
|
-
success: false,
|
|
247
|
-
consumed: context.buffer.length - result.next.buffer.length,
|
|
248
|
-
error: require_message.message`${require_message.values(context.state[1].consumed)} and ${require_message.values(result.consumed)} cannot be used together.`
|
|
249
|
-
};
|
|
250
|
-
return {
|
|
251
|
-
success: true,
|
|
252
|
-
next: {
|
|
253
|
-
...context,
|
|
254
|
-
buffer: result.next.buffer,
|
|
255
|
-
optionsTerminated: result.next.optionsTerminated,
|
|
256
|
-
state: [i, result]
|
|
257
|
-
},
|
|
258
|
-
consumed: result.consumed
|
|
259
|
-
};
|
|
260
|
-
} else if (!result.success && error.consumed < result.consumed) error = result;
|
|
261
|
-
}
|
|
262
|
-
return {
|
|
263
|
-
...error,
|
|
264
|
-
success: false
|
|
265
|
-
};
|
|
266
|
-
};
|
|
267
|
-
const parseAsync = async (context) => {
|
|
268
|
-
let error = getInitialError(context);
|
|
269
|
-
const orderedParsers = parsers.map((p, i) => [p, i]);
|
|
270
|
-
orderedParsers.sort(([_, a], [__, b]) => context.state?.[0] === a ? -1 : context.state?.[0] === b ? 1 : a - b);
|
|
271
|
-
for (const [parser, i] of orderedParsers) {
|
|
272
|
-
const resultOrPromise = parser.parse({
|
|
273
|
-
...context,
|
|
274
|
-
state: context.state == null || context.state[0] !== i || !context.state[1].success ? parser.initialState : context.state[1].next.state
|
|
275
|
-
});
|
|
276
|
-
const result = await resultOrPromise;
|
|
277
|
-
if (result.success && result.consumed.length > 0) {
|
|
278
|
-
if (context.state?.[0] !== i && context.state?.[1].success) return {
|
|
279
|
-
success: false,
|
|
280
|
-
consumed: context.buffer.length - result.next.buffer.length,
|
|
281
|
-
error: require_message.message`${require_message.values(context.state[1].consumed)} and ${require_message.values(result.consumed)} cannot be used together.`
|
|
282
|
-
};
|
|
283
|
-
return {
|
|
284
|
-
success: true,
|
|
285
|
-
next: {
|
|
286
|
-
...context,
|
|
287
|
-
buffer: result.next.buffer,
|
|
288
|
-
optionsTerminated: result.next.optionsTerminated,
|
|
289
|
-
state: [i, result]
|
|
290
|
-
},
|
|
291
|
-
consumed: result.consumed
|
|
292
|
-
};
|
|
293
|
-
} else if (!result.success && error.consumed < result.consumed) error = result;
|
|
294
|
-
}
|
|
295
|
-
return {
|
|
296
|
-
...error,
|
|
297
|
-
success: false
|
|
298
|
-
};
|
|
299
|
-
};
|
|
300
194
|
return {
|
|
301
|
-
$mode: combinedMode,
|
|
302
195
|
$valueType: [],
|
|
303
196
|
$stateType: [],
|
|
304
197
|
priority: Math.max(...parsers.map((p) => p.priority)),
|
|
@@ -307,12 +200,43 @@ function or(...args) {
|
|
|
307
200
|
terms: parsers.map((p) => p.usage)
|
|
308
201
|
}],
|
|
309
202
|
initialState: void 0,
|
|
310
|
-
complete: createExclusiveComplete(parsers, options, noMatchContext
|
|
203
|
+
complete: createExclusiveComplete(parsers, options, noMatchContext),
|
|
311
204
|
parse(context) {
|
|
312
|
-
|
|
313
|
-
|
|
205
|
+
let error = {
|
|
206
|
+
consumed: 0,
|
|
207
|
+
error: context.buffer.length < 1 ? getNoMatchError(options, noMatchContext) : createUnexpectedInputError(context.buffer[0], context.usage, options)
|
|
208
|
+
};
|
|
209
|
+
const orderedParsers = parsers.map((p, i) => [p, i]);
|
|
210
|
+
orderedParsers.sort(([_, a], [__, b]) => context.state?.[0] === a ? -1 : context.state?.[0] === b ? 1 : a - b);
|
|
211
|
+
for (const [parser, i] of orderedParsers) {
|
|
212
|
+
const result = parser.parse({
|
|
213
|
+
...context,
|
|
214
|
+
state: context.state == null || context.state[0] !== i || !context.state[1].success ? parser.initialState : context.state[1].next.state
|
|
215
|
+
});
|
|
216
|
+
if (result.success && result.consumed.length > 0) {
|
|
217
|
+
if (context.state?.[0] !== i && context.state?.[1].success) return {
|
|
218
|
+
success: false,
|
|
219
|
+
consumed: context.buffer.length - result.next.buffer.length,
|
|
220
|
+
error: require_message.message`${require_message.values(context.state[1].consumed)} and ${require_message.values(result.consumed)} cannot be used together.`
|
|
221
|
+
};
|
|
222
|
+
return {
|
|
223
|
+
success: true,
|
|
224
|
+
next: {
|
|
225
|
+
...context,
|
|
226
|
+
buffer: result.next.buffer,
|
|
227
|
+
optionsTerminated: result.next.optionsTerminated,
|
|
228
|
+
state: [i, result]
|
|
229
|
+
},
|
|
230
|
+
consumed: result.consumed
|
|
231
|
+
};
|
|
232
|
+
} else if (!result.success && error.consumed < result.consumed) error = result;
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
...error,
|
|
236
|
+
success: false
|
|
237
|
+
};
|
|
314
238
|
},
|
|
315
|
-
suggest: createExclusiveSuggest(parsers
|
|
239
|
+
suggest: createExclusiveSuggest(parsers),
|
|
316
240
|
getDocFragments(state, _defaultValue) {
|
|
317
241
|
let description;
|
|
318
242
|
let fragments;
|
|
@@ -361,82 +285,7 @@ function longestMatch(...args) {
|
|
|
361
285
|
options = void 0;
|
|
362
286
|
}
|
|
363
287
|
const noMatchContext = analyzeNoMatchContext(parsers);
|
|
364
|
-
const combinedMode = parsers.some((p) => p.$mode === "async") ? "async" : "sync";
|
|
365
|
-
const isAsync = combinedMode === "async";
|
|
366
|
-
const syncParsers = parsers;
|
|
367
|
-
const getInitialError = (context) => ({
|
|
368
|
-
consumed: 0,
|
|
369
|
-
error: context.buffer.length < 1 ? getNoMatchError(options, noMatchContext) : createUnexpectedInputError(context.buffer[0], context.usage, options)
|
|
370
|
-
});
|
|
371
|
-
const parseSync = (context) => {
|
|
372
|
-
let bestMatch = null;
|
|
373
|
-
let error = getInitialError(context);
|
|
374
|
-
for (let i = 0; i < syncParsers.length; i++) {
|
|
375
|
-
const parser = syncParsers[i];
|
|
376
|
-
const result = parser.parse({
|
|
377
|
-
...context,
|
|
378
|
-
state: context.state == null || context.state[0] !== i || !context.state[1].success ? parser.initialState : context.state[1].next.state
|
|
379
|
-
});
|
|
380
|
-
if (result.success) {
|
|
381
|
-
const consumed = context.buffer.length - result.next.buffer.length;
|
|
382
|
-
if (bestMatch === null || consumed > bestMatch.consumed) bestMatch = {
|
|
383
|
-
index: i,
|
|
384
|
-
result,
|
|
385
|
-
consumed
|
|
386
|
-
};
|
|
387
|
-
} else if (error.consumed < result.consumed) error = result;
|
|
388
|
-
}
|
|
389
|
-
if (bestMatch && bestMatch.result.success) return {
|
|
390
|
-
success: true,
|
|
391
|
-
next: {
|
|
392
|
-
...context,
|
|
393
|
-
buffer: bestMatch.result.next.buffer,
|
|
394
|
-
optionsTerminated: bestMatch.result.next.optionsTerminated,
|
|
395
|
-
state: [bestMatch.index, bestMatch.result]
|
|
396
|
-
},
|
|
397
|
-
consumed: bestMatch.result.consumed
|
|
398
|
-
};
|
|
399
|
-
return {
|
|
400
|
-
...error,
|
|
401
|
-
success: false
|
|
402
|
-
};
|
|
403
|
-
};
|
|
404
|
-
const parseAsync = async (context) => {
|
|
405
|
-
let bestMatch = null;
|
|
406
|
-
let error = getInitialError(context);
|
|
407
|
-
for (let i = 0; i < parsers.length; i++) {
|
|
408
|
-
const parser = parsers[i];
|
|
409
|
-
const resultOrPromise = parser.parse({
|
|
410
|
-
...context,
|
|
411
|
-
state: context.state == null || context.state[0] !== i || !context.state[1].success ? parser.initialState : context.state[1].next.state
|
|
412
|
-
});
|
|
413
|
-
const result = await resultOrPromise;
|
|
414
|
-
if (result.success) {
|
|
415
|
-
const consumed = context.buffer.length - result.next.buffer.length;
|
|
416
|
-
if (bestMatch === null || consumed > bestMatch.consumed) bestMatch = {
|
|
417
|
-
index: i,
|
|
418
|
-
result,
|
|
419
|
-
consumed
|
|
420
|
-
};
|
|
421
|
-
} else if (error.consumed < result.consumed) error = result;
|
|
422
|
-
}
|
|
423
|
-
if (bestMatch && bestMatch.result.success) return {
|
|
424
|
-
success: true,
|
|
425
|
-
next: {
|
|
426
|
-
...context,
|
|
427
|
-
buffer: bestMatch.result.next.buffer,
|
|
428
|
-
optionsTerminated: bestMatch.result.next.optionsTerminated,
|
|
429
|
-
state: [bestMatch.index, bestMatch.result]
|
|
430
|
-
},
|
|
431
|
-
consumed: bestMatch.result.consumed
|
|
432
|
-
};
|
|
433
|
-
return {
|
|
434
|
-
...error,
|
|
435
|
-
success: false
|
|
436
|
-
};
|
|
437
|
-
};
|
|
438
288
|
return {
|
|
439
|
-
$mode: combinedMode,
|
|
440
289
|
$valueType: [],
|
|
441
290
|
$stateType: [],
|
|
442
291
|
priority: Math.max(...parsers.map((p) => p.priority)),
|
|
@@ -445,12 +294,44 @@ function longestMatch(...args) {
|
|
|
445
294
|
terms: parsers.map((p) => p.usage)
|
|
446
295
|
}],
|
|
447
296
|
initialState: void 0,
|
|
448
|
-
complete: createExclusiveComplete(parsers, options, noMatchContext
|
|
297
|
+
complete: createExclusiveComplete(parsers, options, noMatchContext),
|
|
449
298
|
parse(context) {
|
|
450
|
-
|
|
451
|
-
|
|
299
|
+
let bestMatch = null;
|
|
300
|
+
let error = {
|
|
301
|
+
consumed: 0,
|
|
302
|
+
error: context.buffer.length < 1 ? getNoMatchError(options, noMatchContext) : createUnexpectedInputError(context.buffer[0], context.usage, options)
|
|
303
|
+
};
|
|
304
|
+
for (let i = 0; i < parsers.length; i++) {
|
|
305
|
+
const parser = parsers[i];
|
|
306
|
+
const result = parser.parse({
|
|
307
|
+
...context,
|
|
308
|
+
state: context.state == null || context.state[0] !== i || !context.state[1].success ? parser.initialState : context.state[1].next.state
|
|
309
|
+
});
|
|
310
|
+
if (result.success) {
|
|
311
|
+
const consumed = context.buffer.length - result.next.buffer.length;
|
|
312
|
+
if (bestMatch === null || consumed > bestMatch.consumed) bestMatch = {
|
|
313
|
+
index: i,
|
|
314
|
+
result,
|
|
315
|
+
consumed
|
|
316
|
+
};
|
|
317
|
+
} else if (error.consumed < result.consumed) error = result;
|
|
318
|
+
}
|
|
319
|
+
if (bestMatch && bestMatch.result.success) return {
|
|
320
|
+
success: true,
|
|
321
|
+
next: {
|
|
322
|
+
...context,
|
|
323
|
+
buffer: bestMatch.result.next.buffer,
|
|
324
|
+
optionsTerminated: bestMatch.result.next.optionsTerminated,
|
|
325
|
+
state: [bestMatch.index, bestMatch.result]
|
|
326
|
+
},
|
|
327
|
+
consumed: bestMatch.result.consumed
|
|
328
|
+
};
|
|
329
|
+
return {
|
|
330
|
+
...error,
|
|
331
|
+
success: false
|
|
332
|
+
};
|
|
452
333
|
},
|
|
453
|
-
suggest: createExclusiveSuggest(parsers
|
|
334
|
+
suggest: createExclusiveSuggest(parsers),
|
|
454
335
|
getDocFragments(state, _defaultValue) {
|
|
455
336
|
let description;
|
|
456
337
|
let footer;
|
|
@@ -476,61 +357,6 @@ function longestMatch(...args) {
|
|
|
476
357
|
}
|
|
477
358
|
};
|
|
478
359
|
}
|
|
479
|
-
/**
|
|
480
|
-
* Internal sync helper for object suggest functionality.
|
|
481
|
-
* @internal
|
|
482
|
-
*/
|
|
483
|
-
function* suggestObjectSync(context, prefix, parserPairs) {
|
|
484
|
-
if (context.buffer.length > 0) {
|
|
485
|
-
const lastToken = context.buffer[context.buffer.length - 1];
|
|
486
|
-
for (const [field, parser] of parserPairs) if (isOptionRequiringValue(parser.usage, lastToken)) {
|
|
487
|
-
const fieldState = context.state && typeof context.state === "object" && field in context.state ? context.state[field] : parser.initialState;
|
|
488
|
-
yield* parser.suggest({
|
|
489
|
-
...context,
|
|
490
|
-
state: fieldState
|
|
491
|
-
}, prefix);
|
|
492
|
-
return;
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
const suggestions = [];
|
|
496
|
-
for (const [field, parser] of parserPairs) {
|
|
497
|
-
const fieldState = context.state && typeof context.state === "object" && field in context.state ? context.state[field] : parser.initialState;
|
|
498
|
-
const fieldSuggestions = parser.suggest({
|
|
499
|
-
...context,
|
|
500
|
-
state: fieldState
|
|
501
|
-
}, prefix);
|
|
502
|
-
suggestions.push(...fieldSuggestions);
|
|
503
|
-
}
|
|
504
|
-
yield* require_suggestion.deduplicateSuggestions(suggestions);
|
|
505
|
-
}
|
|
506
|
-
/**
|
|
507
|
-
* Internal async helper for object suggest functionality.
|
|
508
|
-
* @internal
|
|
509
|
-
*/
|
|
510
|
-
async function* suggestObjectAsync(context, prefix, parserPairs) {
|
|
511
|
-
if (context.buffer.length > 0) {
|
|
512
|
-
const lastToken = context.buffer[context.buffer.length - 1];
|
|
513
|
-
for (const [field, parser] of parserPairs) if (isOptionRequiringValue(parser.usage, lastToken)) {
|
|
514
|
-
const fieldState = context.state && typeof context.state === "object" && field in context.state ? context.state[field] : parser.initialState;
|
|
515
|
-
const suggestions$1 = parser.suggest({
|
|
516
|
-
...context,
|
|
517
|
-
state: fieldState
|
|
518
|
-
}, prefix);
|
|
519
|
-
for await (const s of suggestions$1) yield s;
|
|
520
|
-
return;
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
const suggestions = [];
|
|
524
|
-
for (const [field, parser] of parserPairs) {
|
|
525
|
-
const fieldState = context.state && typeof context.state === "object" && field in context.state ? context.state[field] : parser.initialState;
|
|
526
|
-
const fieldSuggestions = parser.suggest({
|
|
527
|
-
...context,
|
|
528
|
-
state: fieldState
|
|
529
|
-
}, prefix);
|
|
530
|
-
for await (const s of fieldSuggestions) suggestions.push(s);
|
|
531
|
-
}
|
|
532
|
-
yield* require_suggestion.deduplicateSuggestions(suggestions);
|
|
533
|
-
}
|
|
534
360
|
function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
535
361
|
const label = typeof labelOrParsers === "string" ? labelOrParsers : void 0;
|
|
536
362
|
let parsers;
|
|
@@ -549,181 +375,131 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
549
375
|
for (const key of parserKeys) initialState[key] = parsers[key].initialState;
|
|
550
376
|
if (!options.allowDuplicates) checkDuplicateOptionNames(parserPairs.map(([field, parser]) => [field, parser.usage]));
|
|
551
377
|
const noMatchContext = analyzeNoMatchContext(parserKeys.map((k) => parsers[k]));
|
|
552
|
-
const combinedMode = parserKeys.some((k) => parsers[k].$mode === "async") ? "async" : "sync";
|
|
553
|
-
const isAsync = combinedMode === "async";
|
|
554
|
-
const getInitialError = (context) => ({
|
|
555
|
-
consumed: 0,
|
|
556
|
-
error: context.buffer.length > 0 ? (() => {
|
|
557
|
-
const token = context.buffer[0];
|
|
558
|
-
const customMessage = options.errors?.unexpectedInput;
|
|
559
|
-
if (customMessage) return typeof customMessage === "function" ? customMessage(token) : customMessage;
|
|
560
|
-
const baseError = require_message.message`Unexpected option or argument: ${token}.`;
|
|
561
|
-
return require_suggestion.createErrorWithSuggestions(baseError, token, context.usage, "both", options.errors?.suggestions);
|
|
562
|
-
})() : (() => {
|
|
563
|
-
const customEndOfInput = options.errors?.endOfInput;
|
|
564
|
-
return customEndOfInput ? typeof customEndOfInput === "function" ? customEndOfInput(noMatchContext) : customEndOfInput : generateNoMatchError(noMatchContext);
|
|
565
|
-
})()
|
|
566
|
-
});
|
|
567
|
-
const parseSync = (context) => {
|
|
568
|
-
let error = getInitialError(context);
|
|
569
|
-
let currentContext = context;
|
|
570
|
-
let anySuccess = false;
|
|
571
|
-
const allConsumed = [];
|
|
572
|
-
let madeProgress = true;
|
|
573
|
-
while (madeProgress && currentContext.buffer.length > 0) {
|
|
574
|
-
madeProgress = false;
|
|
575
|
-
for (const [field, parser] of parserPairs) {
|
|
576
|
-
const result = parser.parse({
|
|
577
|
-
...currentContext,
|
|
578
|
-
state: currentContext.state && typeof currentContext.state === "object" && field in currentContext.state ? currentContext.state[field] : parser.initialState
|
|
579
|
-
});
|
|
580
|
-
if (result.success && result.consumed.length > 0) {
|
|
581
|
-
currentContext = {
|
|
582
|
-
...currentContext,
|
|
583
|
-
buffer: result.next.buffer,
|
|
584
|
-
optionsTerminated: result.next.optionsTerminated,
|
|
585
|
-
state: {
|
|
586
|
-
...currentContext.state,
|
|
587
|
-
[field]: result.next.state
|
|
588
|
-
}
|
|
589
|
-
};
|
|
590
|
-
allConsumed.push(...result.consumed);
|
|
591
|
-
anySuccess = true;
|
|
592
|
-
madeProgress = true;
|
|
593
|
-
break;
|
|
594
|
-
} else if (!result.success && error.consumed < result.consumed) error = result;
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
if (anySuccess) return {
|
|
598
|
-
success: true,
|
|
599
|
-
next: currentContext,
|
|
600
|
-
consumed: allConsumed
|
|
601
|
-
};
|
|
602
|
-
if (context.buffer.length === 0) {
|
|
603
|
-
let allCanComplete = true;
|
|
604
|
-
for (const [field, parser] of parserPairs) {
|
|
605
|
-
const fieldState = context.state && typeof context.state === "object" && field in context.state ? context.state[field] : parser.initialState;
|
|
606
|
-
const completeResult = parser.complete(fieldState);
|
|
607
|
-
if (!completeResult.success) {
|
|
608
|
-
allCanComplete = false;
|
|
609
|
-
break;
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
if (allCanComplete) return {
|
|
613
|
-
success: true,
|
|
614
|
-
next: context,
|
|
615
|
-
consumed: []
|
|
616
|
-
};
|
|
617
|
-
}
|
|
618
|
-
return {
|
|
619
|
-
...error,
|
|
620
|
-
success: false
|
|
621
|
-
};
|
|
622
|
-
};
|
|
623
|
-
const parseAsync = async (context) => {
|
|
624
|
-
let error = getInitialError(context);
|
|
625
|
-
let currentContext = context;
|
|
626
|
-
let anySuccess = false;
|
|
627
|
-
const allConsumed = [];
|
|
628
|
-
let madeProgress = true;
|
|
629
|
-
while (madeProgress && currentContext.buffer.length > 0) {
|
|
630
|
-
madeProgress = false;
|
|
631
|
-
for (const [field, parser] of parserPairs) {
|
|
632
|
-
const resultOrPromise = parser.parse({
|
|
633
|
-
...currentContext,
|
|
634
|
-
state: currentContext.state && typeof currentContext.state === "object" && field in currentContext.state ? currentContext.state[field] : parser.initialState
|
|
635
|
-
});
|
|
636
|
-
const result = await resultOrPromise;
|
|
637
|
-
if (result.success && result.consumed.length > 0) {
|
|
638
|
-
currentContext = {
|
|
639
|
-
...currentContext,
|
|
640
|
-
buffer: result.next.buffer,
|
|
641
|
-
optionsTerminated: result.next.optionsTerminated,
|
|
642
|
-
state: {
|
|
643
|
-
...currentContext.state,
|
|
644
|
-
[field]: result.next.state
|
|
645
|
-
}
|
|
646
|
-
};
|
|
647
|
-
allConsumed.push(...result.consumed);
|
|
648
|
-
anySuccess = true;
|
|
649
|
-
madeProgress = true;
|
|
650
|
-
break;
|
|
651
|
-
} else if (!result.success && error.consumed < result.consumed) error = result;
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
if (anySuccess) return {
|
|
655
|
-
success: true,
|
|
656
|
-
next: currentContext,
|
|
657
|
-
consumed: allConsumed
|
|
658
|
-
};
|
|
659
|
-
if (context.buffer.length === 0) {
|
|
660
|
-
let allCanComplete = true;
|
|
661
|
-
for (const [field, parser] of parserPairs) {
|
|
662
|
-
const fieldState = context.state && typeof context.state === "object" && field in context.state ? context.state[field] : parser.initialState;
|
|
663
|
-
const completeResult = await parser.complete(fieldState);
|
|
664
|
-
if (!completeResult.success) {
|
|
665
|
-
allCanComplete = false;
|
|
666
|
-
break;
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
if (allCanComplete) return {
|
|
670
|
-
success: true,
|
|
671
|
-
next: context,
|
|
672
|
-
consumed: []
|
|
673
|
-
};
|
|
674
|
-
}
|
|
675
|
-
return {
|
|
676
|
-
...error,
|
|
677
|
-
success: false
|
|
678
|
-
};
|
|
679
|
-
};
|
|
680
378
|
return {
|
|
681
|
-
$mode: combinedMode,
|
|
682
379
|
$valueType: [],
|
|
683
380
|
$stateType: [],
|
|
684
381
|
priority: Math.max(...parserKeys.map((k) => parsers[k].priority)),
|
|
685
382
|
usage: parserPairs.flatMap(([_, p]) => p.usage),
|
|
686
383
|
initialState,
|
|
687
384
|
parse(context) {
|
|
688
|
-
if (
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
if (valueResult.success) result[field] = valueResult.value;
|
|
697
|
-
else return {
|
|
698
|
-
success: false,
|
|
699
|
-
error: valueResult.error
|
|
700
|
-
};
|
|
385
|
+
if (!options.allowDuplicates) {
|
|
386
|
+
const optionNameSources = /* @__PURE__ */ new Map();
|
|
387
|
+
for (const [field, parser] of parserPairs) {
|
|
388
|
+
const names = require_usage.extractOptionNames(parser.usage);
|
|
389
|
+
for (const name of names) {
|
|
390
|
+
if (!optionNameSources.has(name)) optionNameSources.set(name, []);
|
|
391
|
+
optionNameSources.get(name).push(field);
|
|
392
|
+
}
|
|
701
393
|
}
|
|
702
|
-
return {
|
|
703
|
-
success:
|
|
704
|
-
|
|
394
|
+
for (const [name, sources] of optionNameSources) if (sources.length > 1) return {
|
|
395
|
+
success: false,
|
|
396
|
+
consumed: 0,
|
|
397
|
+
error: require_message.message`Duplicate option name ${require_message.optionName(name)} found in fields: ${require_message.values(sources.map((s) => typeof s === "symbol" ? s.description ?? s.toString() : s))}. Each option name must be unique within a parser combinator.`
|
|
705
398
|
};
|
|
706
399
|
}
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
const
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
400
|
+
let error = {
|
|
401
|
+
consumed: 0,
|
|
402
|
+
error: context.buffer.length > 0 ? (() => {
|
|
403
|
+
const token = context.buffer[0];
|
|
404
|
+
const customMessage = options.errors?.unexpectedInput;
|
|
405
|
+
if (customMessage) return typeof customMessage === "function" ? customMessage(token) : customMessage;
|
|
406
|
+
const baseError = require_message.message`Unexpected option or argument: ${token}.`;
|
|
407
|
+
return require_suggestion.createErrorWithSuggestions(baseError, token, context.usage, "both", options.errors?.suggestions);
|
|
408
|
+
})() : (() => {
|
|
409
|
+
const customEndOfInput = options.errors?.endOfInput;
|
|
410
|
+
return customEndOfInput ? typeof customEndOfInput === "function" ? customEndOfInput(noMatchContext) : customEndOfInput : generateNoMatchError(noMatchContext);
|
|
411
|
+
})()
|
|
412
|
+
};
|
|
413
|
+
let currentContext = context;
|
|
414
|
+
let anySuccess = false;
|
|
415
|
+
const allConsumed = [];
|
|
416
|
+
let madeProgress = true;
|
|
417
|
+
while (madeProgress && currentContext.buffer.length > 0) {
|
|
418
|
+
madeProgress = false;
|
|
419
|
+
for (const [field, parser] of parserPairs) {
|
|
420
|
+
const result = parser.parse({
|
|
421
|
+
...currentContext,
|
|
422
|
+
state: currentContext.state && typeof currentContext.state === "object" && field in currentContext.state ? currentContext.state[field] : parser.initialState
|
|
423
|
+
});
|
|
424
|
+
if (result.success && result.consumed.length > 0) {
|
|
425
|
+
currentContext = {
|
|
426
|
+
...currentContext,
|
|
427
|
+
buffer: result.next.buffer,
|
|
428
|
+
optionsTerminated: result.next.optionsTerminated,
|
|
429
|
+
state: {
|
|
430
|
+
...currentContext.state,
|
|
431
|
+
[field]: result.next.state
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
allConsumed.push(...result.consumed);
|
|
435
|
+
anySuccess = true;
|
|
436
|
+
madeProgress = true;
|
|
437
|
+
break;
|
|
438
|
+
} else if (!result.success && error.consumed < result.consumed) error = result;
|
|
716
439
|
}
|
|
717
|
-
|
|
440
|
+
}
|
|
441
|
+
if (anySuccess) return {
|
|
442
|
+
success: true,
|
|
443
|
+
next: currentContext,
|
|
444
|
+
consumed: allConsumed
|
|
445
|
+
};
|
|
446
|
+
if (context.buffer.length === 0) {
|
|
447
|
+
let allCanComplete = true;
|
|
448
|
+
for (const [field, parser] of parserPairs) {
|
|
449
|
+
const fieldState = context.state && typeof context.state === "object" && field in context.state ? context.state[field] : parser.initialState;
|
|
450
|
+
const completeResult = parser.complete(fieldState);
|
|
451
|
+
if (!completeResult.success) {
|
|
452
|
+
allCanComplete = false;
|
|
453
|
+
break;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
if (allCanComplete) return {
|
|
718
457
|
success: true,
|
|
719
|
-
|
|
458
|
+
next: context,
|
|
459
|
+
consumed: []
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
return {
|
|
463
|
+
...error,
|
|
464
|
+
success: false
|
|
465
|
+
};
|
|
466
|
+
},
|
|
467
|
+
complete(state) {
|
|
468
|
+
const result = {};
|
|
469
|
+
for (const field of parserKeys) {
|
|
470
|
+
const valueResult = parsers[field].complete(state[field]);
|
|
471
|
+
if (valueResult.success) result[field] = valueResult.value;
|
|
472
|
+
else return {
|
|
473
|
+
success: false,
|
|
474
|
+
error: valueResult.error
|
|
720
475
|
};
|
|
721
|
-
}
|
|
476
|
+
}
|
|
477
|
+
return {
|
|
478
|
+
success: true,
|
|
479
|
+
value: result
|
|
480
|
+
};
|
|
722
481
|
},
|
|
723
482
|
suggest(context, prefix) {
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
483
|
+
const suggestions = [];
|
|
484
|
+
if (context.buffer.length > 0) {
|
|
485
|
+
const lastToken = context.buffer[context.buffer.length - 1];
|
|
486
|
+
for (const [field, parser] of parserPairs) if (isOptionRequiringValue(parser.usage, lastToken)) {
|
|
487
|
+
const fieldState = context.state && typeof context.state === "object" && field in context.state ? context.state[field] : parser.initialState;
|
|
488
|
+
return Array.from(parser.suggest({
|
|
489
|
+
...context,
|
|
490
|
+
state: fieldState
|
|
491
|
+
}, prefix));
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
for (const [field, parser] of parserPairs) {
|
|
495
|
+
const fieldState = context.state && typeof context.state === "object" && field in context.state ? context.state[field] : parser.initialState;
|
|
496
|
+
const fieldSuggestions = parser.suggest({
|
|
497
|
+
...context,
|
|
498
|
+
state: fieldState
|
|
499
|
+
}, prefix);
|
|
500
|
+
suggestions.push(...fieldSuggestions);
|
|
501
|
+
}
|
|
502
|
+
return require_suggestion.deduplicateSuggestions(suggestions);
|
|
727
503
|
},
|
|
728
504
|
getDocFragments(state, defaultValue) {
|
|
729
505
|
const fragments = parserPairs.flatMap(([field, p]) => {
|
|
@@ -752,35 +528,6 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
752
528
|
}
|
|
753
529
|
};
|
|
754
530
|
}
|
|
755
|
-
function suggestTupleSync(context, prefix, parsers) {
|
|
756
|
-
const suggestions = [];
|
|
757
|
-
const stateArray = context.state;
|
|
758
|
-
for (let i = 0; i < parsers.length; i++) {
|
|
759
|
-
const parser = parsers[i];
|
|
760
|
-
const parserState = stateArray && Array.isArray(stateArray) ? stateArray[i] : parser.initialState;
|
|
761
|
-
const parserSuggestions = parser.suggest({
|
|
762
|
-
...context,
|
|
763
|
-
state: parserState
|
|
764
|
-
}, prefix);
|
|
765
|
-
suggestions.push(...parserSuggestions);
|
|
766
|
-
}
|
|
767
|
-
return require_suggestion.deduplicateSuggestions(suggestions);
|
|
768
|
-
}
|
|
769
|
-
async function* suggestTupleAsync(context, prefix, parsers) {
|
|
770
|
-
const suggestions = [];
|
|
771
|
-
const stateArray = context.state;
|
|
772
|
-
for (let i = 0; i < parsers.length; i++) {
|
|
773
|
-
const parser = parsers[i];
|
|
774
|
-
const parserState = stateArray && Array.isArray(stateArray) ? stateArray[i] : parser.initialState;
|
|
775
|
-
const parserSuggestions = parser.suggest({
|
|
776
|
-
...context,
|
|
777
|
-
state: parserState
|
|
778
|
-
}, prefix);
|
|
779
|
-
if (parser.$mode === "async") for await (const s of parserSuggestions) suggestions.push(s);
|
|
780
|
-
else suggestions.push(...parserSuggestions);
|
|
781
|
-
}
|
|
782
|
-
yield* require_suggestion.deduplicateSuggestions(suggestions);
|
|
783
|
-
}
|
|
784
531
|
function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
785
532
|
const label = typeof labelOrParsers === "string" ? labelOrParsers : void 0;
|
|
786
533
|
let parsers;
|
|
@@ -792,187 +539,102 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
792
539
|
parsers = labelOrParsers;
|
|
793
540
|
options = maybeParsersOrOptions ?? {};
|
|
794
541
|
}
|
|
795
|
-
const combinedMode = parsers.some((p) => p.$mode === "async") ? "async" : "sync";
|
|
796
|
-
const isAsync = combinedMode === "async";
|
|
797
|
-
const syncParsers = parsers;
|
|
798
542
|
if (!options.allowDuplicates) checkDuplicateOptionNames(parsers.map((parser, index) => [String(index), parser.usage]));
|
|
799
|
-
const parseSync = (context) => {
|
|
800
|
-
let currentContext = context;
|
|
801
|
-
const allConsumed = [];
|
|
802
|
-
const matchedParsers = /* @__PURE__ */ new Set();
|
|
803
|
-
while (matchedParsers.size < syncParsers.length) {
|
|
804
|
-
let foundMatch = false;
|
|
805
|
-
let error = {
|
|
806
|
-
consumed: 0,
|
|
807
|
-
error: require_message.message`No remaining parsers could match the input.`
|
|
808
|
-
};
|
|
809
|
-
const stateArray = currentContext.state;
|
|
810
|
-
const remainingParsers = syncParsers.map((parser, index) => [parser, index]).filter(([_, index]) => !matchedParsers.has(index)).sort(([parserA], [parserB]) => parserB.priority - parserA.priority);
|
|
811
|
-
for (const [parser, index] of remainingParsers) {
|
|
812
|
-
const result = parser.parse({
|
|
813
|
-
...currentContext,
|
|
814
|
-
state: stateArray[index]
|
|
815
|
-
});
|
|
816
|
-
if (result.success && result.consumed.length > 0) {
|
|
817
|
-
const newStateArray = stateArray.map((s, idx) => idx === index ? result.next.state : s);
|
|
818
|
-
currentContext = {
|
|
819
|
-
...currentContext,
|
|
820
|
-
buffer: result.next.buffer,
|
|
821
|
-
optionsTerminated: result.next.optionsTerminated,
|
|
822
|
-
state: newStateArray
|
|
823
|
-
};
|
|
824
|
-
allConsumed.push(...result.consumed);
|
|
825
|
-
matchedParsers.add(index);
|
|
826
|
-
foundMatch = true;
|
|
827
|
-
break;
|
|
828
|
-
} else if (!result.success && error.consumed < result.consumed) error = result;
|
|
829
|
-
}
|
|
830
|
-
if (!foundMatch) for (const [parser, index] of remainingParsers) {
|
|
831
|
-
const result = parser.parse({
|
|
832
|
-
...currentContext,
|
|
833
|
-
state: stateArray[index]
|
|
834
|
-
});
|
|
835
|
-
if (result.success && result.consumed.length < 1) {
|
|
836
|
-
const newStateArray = stateArray.map((s, idx) => idx === index ? result.next.state : s);
|
|
837
|
-
currentContext = {
|
|
838
|
-
...currentContext,
|
|
839
|
-
state: newStateArray
|
|
840
|
-
};
|
|
841
|
-
matchedParsers.add(index);
|
|
842
|
-
foundMatch = true;
|
|
843
|
-
break;
|
|
844
|
-
} else if (!result.success && result.consumed < 1) {
|
|
845
|
-
matchedParsers.add(index);
|
|
846
|
-
foundMatch = true;
|
|
847
|
-
break;
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
if (!foundMatch) return {
|
|
851
|
-
...error,
|
|
852
|
-
success: false
|
|
853
|
-
};
|
|
854
|
-
}
|
|
855
|
-
return {
|
|
856
|
-
success: true,
|
|
857
|
-
next: currentContext,
|
|
858
|
-
consumed: allConsumed
|
|
859
|
-
};
|
|
860
|
-
};
|
|
861
|
-
const parseAsync = async (context) => {
|
|
862
|
-
let currentContext = context;
|
|
863
|
-
const allConsumed = [];
|
|
864
|
-
const matchedParsers = /* @__PURE__ */ new Set();
|
|
865
|
-
while (matchedParsers.size < parsers.length) {
|
|
866
|
-
let foundMatch = false;
|
|
867
|
-
let error = {
|
|
868
|
-
consumed: 0,
|
|
869
|
-
error: require_message.message`No remaining parsers could match the input.`
|
|
870
|
-
};
|
|
871
|
-
const stateArray = currentContext.state;
|
|
872
|
-
const remainingParsers = parsers.map((parser, index) => [parser, index]).filter(([_, index]) => !matchedParsers.has(index)).sort(([parserA], [parserB]) => parserB.priority - parserA.priority);
|
|
873
|
-
for (const [parser, index] of remainingParsers) {
|
|
874
|
-
const resultOrPromise = parser.parse({
|
|
875
|
-
...currentContext,
|
|
876
|
-
state: stateArray[index]
|
|
877
|
-
});
|
|
878
|
-
const result = await resultOrPromise;
|
|
879
|
-
if (result.success && result.consumed.length > 0) {
|
|
880
|
-
const newStateArray = stateArray.map((s, idx) => idx === index ? result.next.state : s);
|
|
881
|
-
currentContext = {
|
|
882
|
-
...currentContext,
|
|
883
|
-
buffer: result.next.buffer,
|
|
884
|
-
optionsTerminated: result.next.optionsTerminated,
|
|
885
|
-
state: newStateArray
|
|
886
|
-
};
|
|
887
|
-
allConsumed.push(...result.consumed);
|
|
888
|
-
matchedParsers.add(index);
|
|
889
|
-
foundMatch = true;
|
|
890
|
-
break;
|
|
891
|
-
} else if (!result.success && error.consumed < result.consumed) error = result;
|
|
892
|
-
}
|
|
893
|
-
if (!foundMatch) for (const [parser, index] of remainingParsers) {
|
|
894
|
-
const resultOrPromise = parser.parse({
|
|
895
|
-
...currentContext,
|
|
896
|
-
state: stateArray[index]
|
|
897
|
-
});
|
|
898
|
-
const result = await resultOrPromise;
|
|
899
|
-
if (result.success && result.consumed.length < 1) {
|
|
900
|
-
const newStateArray = stateArray.map((s, idx) => idx === index ? result.next.state : s);
|
|
901
|
-
currentContext = {
|
|
902
|
-
...currentContext,
|
|
903
|
-
state: newStateArray
|
|
904
|
-
};
|
|
905
|
-
matchedParsers.add(index);
|
|
906
|
-
foundMatch = true;
|
|
907
|
-
break;
|
|
908
|
-
} else if (!result.success && result.consumed < 1) {
|
|
909
|
-
matchedParsers.add(index);
|
|
910
|
-
foundMatch = true;
|
|
911
|
-
break;
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
if (!foundMatch) return {
|
|
915
|
-
...error,
|
|
916
|
-
success: false
|
|
917
|
-
};
|
|
918
|
-
}
|
|
919
|
-
return {
|
|
920
|
-
success: true,
|
|
921
|
-
next: currentContext,
|
|
922
|
-
consumed: allConsumed
|
|
923
|
-
};
|
|
924
|
-
};
|
|
925
543
|
return {
|
|
926
|
-
$mode: combinedMode,
|
|
927
544
|
$valueType: [],
|
|
928
545
|
$stateType: [],
|
|
929
546
|
usage: parsers.toSorted((a, b) => b.priority - a.priority).flatMap((p) => p.usage),
|
|
930
547
|
priority: parsers.length > 0 ? Math.max(...parsers.map((p) => p.priority)) : 0,
|
|
931
548
|
initialState: parsers.map((parser) => parser.initialState),
|
|
932
549
|
parse(context) {
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
550
|
+
let currentContext = context;
|
|
551
|
+
const allConsumed = [];
|
|
552
|
+
const matchedParsers = /* @__PURE__ */ new Set();
|
|
553
|
+
while (matchedParsers.size < parsers.length) {
|
|
554
|
+
let foundMatch = false;
|
|
555
|
+
let error = {
|
|
556
|
+
consumed: 0,
|
|
557
|
+
error: require_message.message`No remaining parsers could match the input.`
|
|
558
|
+
};
|
|
559
|
+
const remainingParsers = parsers.map((parser, index) => [parser, index]).filter(([_, index]) => !matchedParsers.has(index)).sort(([parserA], [parserB]) => parserB.priority - parserA.priority);
|
|
560
|
+
for (const [parser, index] of remainingParsers) {
|
|
561
|
+
const result = parser.parse({
|
|
562
|
+
...currentContext,
|
|
563
|
+
state: currentContext.state[index]
|
|
564
|
+
});
|
|
565
|
+
if (result.success && result.consumed.length > 0) {
|
|
566
|
+
currentContext = {
|
|
567
|
+
...currentContext,
|
|
568
|
+
buffer: result.next.buffer,
|
|
569
|
+
optionsTerminated: result.next.optionsTerminated,
|
|
570
|
+
state: currentContext.state.map((s, idx) => idx === index ? result.next.state : s)
|
|
571
|
+
};
|
|
572
|
+
allConsumed.push(...result.consumed);
|
|
573
|
+
matchedParsers.add(index);
|
|
574
|
+
foundMatch = true;
|
|
575
|
+
break;
|
|
576
|
+
} else if (!result.success && error.consumed < result.consumed) error = result;
|
|
947
577
|
}
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
578
|
+
if (!foundMatch) for (const [parser, index] of remainingParsers) {
|
|
579
|
+
const result = parser.parse({
|
|
580
|
+
...currentContext,
|
|
581
|
+
state: currentContext.state[index]
|
|
582
|
+
});
|
|
583
|
+
if (result.success && result.consumed.length < 1) {
|
|
584
|
+
currentContext = {
|
|
585
|
+
...currentContext,
|
|
586
|
+
state: currentContext.state.map((s, idx) => idx === index ? result.next.state : s)
|
|
587
|
+
};
|
|
588
|
+
matchedParsers.add(index);
|
|
589
|
+
foundMatch = true;
|
|
590
|
+
break;
|
|
591
|
+
} else if (!result.success && result.consumed < 1) {
|
|
592
|
+
matchedParsers.add(index);
|
|
593
|
+
foundMatch = true;
|
|
594
|
+
break;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
if (!foundMatch) return {
|
|
598
|
+
...error,
|
|
599
|
+
success: false
|
|
951
600
|
};
|
|
952
601
|
}
|
|
953
|
-
return
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
return {
|
|
965
|
-
success:
|
|
966
|
-
|
|
602
|
+
return {
|
|
603
|
+
success: true,
|
|
604
|
+
next: currentContext,
|
|
605
|
+
consumed: allConsumed
|
|
606
|
+
};
|
|
607
|
+
},
|
|
608
|
+
complete(state) {
|
|
609
|
+
const result = [];
|
|
610
|
+
for (let i = 0; i < parsers.length; i++) {
|
|
611
|
+
const valueResult = parsers[i].complete(state[i]);
|
|
612
|
+
if (valueResult.success) result[i] = valueResult.value;
|
|
613
|
+
else return {
|
|
614
|
+
success: false,
|
|
615
|
+
error: valueResult.error
|
|
967
616
|
};
|
|
968
|
-
}
|
|
617
|
+
}
|
|
618
|
+
return {
|
|
619
|
+
success: true,
|
|
620
|
+
value: result
|
|
621
|
+
};
|
|
969
622
|
},
|
|
970
623
|
suggest(context, prefix) {
|
|
971
|
-
|
|
972
|
-
|
|
624
|
+
const suggestions = [];
|
|
625
|
+
for (let i = 0; i < parsers.length; i++) {
|
|
626
|
+
const parser = parsers[i];
|
|
627
|
+
const parserState = context.state && Array.isArray(context.state) ? context.state[i] : parser.initialState;
|
|
628
|
+
const parserSuggestions = parser.suggest({
|
|
629
|
+
...context,
|
|
630
|
+
state: parserState
|
|
631
|
+
}, prefix);
|
|
632
|
+
suggestions.push(...parserSuggestions);
|
|
633
|
+
}
|
|
634
|
+
return require_suggestion.deduplicateSuggestions(suggestions);
|
|
973
635
|
},
|
|
974
636
|
getDocFragments(state, defaultValue) {
|
|
975
|
-
const fragments =
|
|
637
|
+
const fragments = parsers.flatMap((p, i) => {
|
|
976
638
|
const indexState = state.kind === "unavailable" ? { kind: "unavailable" } : {
|
|
977
639
|
kind: "available",
|
|
978
640
|
state: state.state[i]
|
|
@@ -1009,235 +671,127 @@ function merge(...args) {
|
|
|
1009
671
|
const startIndex = typeof args[0] === "string" ? 1 : 0;
|
|
1010
672
|
const endIndex = lastArg && typeof lastArg === "object" && !("parse" in lastArg) && !("complete" in lastArg) ? args.length - 1 : args.length;
|
|
1011
673
|
const rawParsers = args.slice(startIndex, endIndex);
|
|
1012
|
-
const combinedMode = rawParsers.some((p) => p.$mode === "async") ? "async" : "sync";
|
|
1013
|
-
const isAsync = combinedMode === "async";
|
|
1014
|
-
const syncRawParsers = rawParsers;
|
|
1015
674
|
const withIndex = rawParsers.map((p, i) => [p, i]);
|
|
1016
675
|
const sorted = withIndex.toSorted(([a], [b]) => b.priority - a.priority);
|
|
1017
676
|
const parsers = sorted.map(([p]) => p);
|
|
1018
|
-
const syncWithIndex = syncRawParsers.map((p, i) => [p, i]);
|
|
1019
|
-
const syncSorted = syncWithIndex.toSorted(([a], [b]) => b.priority - a.priority);
|
|
1020
|
-
const syncParsers = syncSorted.map(([p]) => p);
|
|
1021
677
|
if (!options.allowDuplicates) checkDuplicateOptionNames(sorted.map(([parser, originalIndex]) => [String(originalIndex), parser.usage]));
|
|
1022
678
|
const initialState = {};
|
|
1023
679
|
for (const parser of parsers) if (parser.initialState && typeof parser.initialState === "object") for (const field in parser.initialState) initialState[field] = parser.initialState[field];
|
|
1024
|
-
const extractParserState = (parser, context, index) => {
|
|
1025
|
-
if (parser.initialState === void 0) {
|
|
1026
|
-
const key = `__parser_${index}`;
|
|
1027
|
-
if (context.state && typeof context.state === "object" && key in context.state) return context.state[key];
|
|
1028
|
-
return void 0;
|
|
1029
|
-
} else if (parser.initialState && typeof parser.initialState === "object") {
|
|
1030
|
-
if (context.state && typeof context.state === "object") {
|
|
1031
|
-
const extractedState = {};
|
|
1032
|
-
for (const field in parser.initialState) extractedState[field] = field in context.state ? context.state[field] : parser.initialState[field];
|
|
1033
|
-
return extractedState;
|
|
1034
|
-
}
|
|
1035
|
-
return parser.initialState;
|
|
1036
|
-
}
|
|
1037
|
-
return parser.initialState;
|
|
1038
|
-
};
|
|
1039
|
-
const mergeResultState = (parser, context, result, index) => {
|
|
1040
|
-
if (parser.initialState === void 0) {
|
|
1041
|
-
const key = `__parser_${index}`;
|
|
1042
|
-
if (result.success) {
|
|
1043
|
-
if (result.consumed.length > 0 || result.next.state !== void 0) return {
|
|
1044
|
-
...context.state,
|
|
1045
|
-
[key]: result.next.state
|
|
1046
|
-
};
|
|
1047
|
-
}
|
|
1048
|
-
return { ...context.state };
|
|
1049
|
-
}
|
|
1050
|
-
return result.success ? {
|
|
1051
|
-
...context.state,
|
|
1052
|
-
...result.next.state
|
|
1053
|
-
} : { ...context.state };
|
|
1054
|
-
};
|
|
1055
|
-
const parseSync = (context) => {
|
|
1056
|
-
let currentContext = context;
|
|
1057
|
-
let zeroConsumedSuccess = null;
|
|
1058
|
-
for (let i = 0; i < syncParsers.length; i++) {
|
|
1059
|
-
const parser = syncParsers[i];
|
|
1060
|
-
const parserState = extractParserState(parser, currentContext, i);
|
|
1061
|
-
const result = parser.parse({
|
|
1062
|
-
...currentContext,
|
|
1063
|
-
state: parserState
|
|
1064
|
-
});
|
|
1065
|
-
if (result.success) {
|
|
1066
|
-
const newState = mergeResultState(parser, currentContext, result, i);
|
|
1067
|
-
const newContext = {
|
|
1068
|
-
...currentContext,
|
|
1069
|
-
buffer: result.next.buffer,
|
|
1070
|
-
optionsTerminated: result.next.optionsTerminated,
|
|
1071
|
-
state: newState
|
|
1072
|
-
};
|
|
1073
|
-
if (result.consumed.length > 0) return {
|
|
1074
|
-
success: true,
|
|
1075
|
-
next: newContext,
|
|
1076
|
-
consumed: result.consumed
|
|
1077
|
-
};
|
|
1078
|
-
currentContext = newContext;
|
|
1079
|
-
if (zeroConsumedSuccess === null) zeroConsumedSuccess = {
|
|
1080
|
-
context: newContext,
|
|
1081
|
-
consumed: []
|
|
1082
|
-
};
|
|
1083
|
-
else zeroConsumedSuccess.context = newContext;
|
|
1084
|
-
} else if (result.consumed < 1) continue;
|
|
1085
|
-
else return result;
|
|
1086
|
-
}
|
|
1087
|
-
if (zeroConsumedSuccess !== null) return {
|
|
1088
|
-
success: true,
|
|
1089
|
-
next: zeroConsumedSuccess.context,
|
|
1090
|
-
consumed: zeroConsumedSuccess.consumed
|
|
1091
|
-
};
|
|
1092
|
-
return {
|
|
1093
|
-
success: false,
|
|
1094
|
-
consumed: 0,
|
|
1095
|
-
error: require_message.message`No matching option or argument found.`
|
|
1096
|
-
};
|
|
1097
|
-
};
|
|
1098
|
-
const parseAsync = async (context) => {
|
|
1099
|
-
let currentContext = context;
|
|
1100
|
-
let zeroConsumedSuccess = null;
|
|
1101
|
-
for (let i = 0; i < parsers.length; i++) {
|
|
1102
|
-
const parser = parsers[i];
|
|
1103
|
-
const parserState = extractParserState(parser, currentContext, i);
|
|
1104
|
-
const resultOrPromise = parser.parse({
|
|
1105
|
-
...currentContext,
|
|
1106
|
-
state: parserState
|
|
1107
|
-
});
|
|
1108
|
-
const result = await resultOrPromise;
|
|
1109
|
-
if (result.success) {
|
|
1110
|
-
const newState = mergeResultState(parser, currentContext, result, i);
|
|
1111
|
-
const newContext = {
|
|
1112
|
-
...currentContext,
|
|
1113
|
-
buffer: result.next.buffer,
|
|
1114
|
-
optionsTerminated: result.next.optionsTerminated,
|
|
1115
|
-
state: newState
|
|
1116
|
-
};
|
|
1117
|
-
if (result.consumed.length > 0) return {
|
|
1118
|
-
success: true,
|
|
1119
|
-
next: newContext,
|
|
1120
|
-
consumed: result.consumed
|
|
1121
|
-
};
|
|
1122
|
-
currentContext = newContext;
|
|
1123
|
-
if (zeroConsumedSuccess === null) zeroConsumedSuccess = {
|
|
1124
|
-
context: newContext,
|
|
1125
|
-
consumed: []
|
|
1126
|
-
};
|
|
1127
|
-
else zeroConsumedSuccess.context = newContext;
|
|
1128
|
-
} else if (result.consumed < 1) continue;
|
|
1129
|
-
else return result;
|
|
1130
|
-
}
|
|
1131
|
-
if (zeroConsumedSuccess !== null) return {
|
|
1132
|
-
success: true,
|
|
1133
|
-
next: zeroConsumedSuccess.context,
|
|
1134
|
-
consumed: zeroConsumedSuccess.consumed
|
|
1135
|
-
};
|
|
1136
|
-
return {
|
|
1137
|
-
success: false,
|
|
1138
|
-
consumed: 0,
|
|
1139
|
-
error: require_message.message`No matching option or argument found.`
|
|
1140
|
-
};
|
|
1141
|
-
};
|
|
1142
680
|
return {
|
|
1143
|
-
$mode: combinedMode,
|
|
1144
681
|
$valueType: [],
|
|
1145
682
|
$stateType: [],
|
|
1146
683
|
priority: Math.max(...parsers.map((p) => p.priority)),
|
|
1147
684
|
usage: parsers.flatMap((p) => p.usage),
|
|
1148
685
|
initialState,
|
|
1149
686
|
parse(context) {
|
|
1150
|
-
|
|
1151
|
-
|
|
687
|
+
let zeroConsumedSuccess = null;
|
|
688
|
+
for (let i = 0; i < parsers.length; i++) {
|
|
689
|
+
const parser = parsers[i];
|
|
690
|
+
let parserState;
|
|
691
|
+
if (parser.initialState === void 0) {
|
|
692
|
+
const key = `__parser_${i}`;
|
|
693
|
+
if (context.state && typeof context.state === "object" && key in context.state) parserState = context.state[key];
|
|
694
|
+
else parserState = void 0;
|
|
695
|
+
} else if (parser.initialState && typeof parser.initialState === "object") if (context.state && typeof context.state === "object") {
|
|
696
|
+
const extractedState = {};
|
|
697
|
+
for (const field in parser.initialState) extractedState[field] = field in context.state ? context.state[field] : parser.initialState[field];
|
|
698
|
+
parserState = extractedState;
|
|
699
|
+
} else parserState = parser.initialState;
|
|
700
|
+
else parserState = parser.initialState;
|
|
701
|
+
const result = parser.parse({
|
|
702
|
+
...context,
|
|
703
|
+
state: parserState
|
|
704
|
+
});
|
|
705
|
+
if (result.success) {
|
|
706
|
+
let newState;
|
|
707
|
+
if (parser.initialState === void 0) {
|
|
708
|
+
const key = `__parser_${i}`;
|
|
709
|
+
if (result.consumed.length > 0 || result.next.state !== void 0) newState = {
|
|
710
|
+
...context.state,
|
|
711
|
+
[key]: result.next.state
|
|
712
|
+
};
|
|
713
|
+
else newState = { ...context.state };
|
|
714
|
+
} else newState = {
|
|
715
|
+
...context.state,
|
|
716
|
+
...result.next.state
|
|
717
|
+
};
|
|
718
|
+
const newContext = {
|
|
719
|
+
...context,
|
|
720
|
+
buffer: result.next.buffer,
|
|
721
|
+
optionsTerminated: result.next.optionsTerminated,
|
|
722
|
+
state: newState
|
|
723
|
+
};
|
|
724
|
+
if (result.consumed.length > 0) return {
|
|
725
|
+
success: true,
|
|
726
|
+
next: newContext,
|
|
727
|
+
consumed: result.consumed
|
|
728
|
+
};
|
|
729
|
+
context = newContext;
|
|
730
|
+
if (zeroConsumedSuccess === null) zeroConsumedSuccess = {
|
|
731
|
+
context: newContext,
|
|
732
|
+
consumed: []
|
|
733
|
+
};
|
|
734
|
+
else zeroConsumedSuccess.context = newContext;
|
|
735
|
+
} else if (result.consumed < 1) continue;
|
|
736
|
+
else return result;
|
|
737
|
+
}
|
|
738
|
+
if (zeroConsumedSuccess !== null) return {
|
|
739
|
+
success: true,
|
|
740
|
+
next: zeroConsumedSuccess.context,
|
|
741
|
+
consumed: zeroConsumedSuccess.consumed
|
|
742
|
+
};
|
|
743
|
+
return {
|
|
744
|
+
success: false,
|
|
745
|
+
consumed: 0,
|
|
746
|
+
error: require_message.message`No matching option or argument found.`
|
|
747
|
+
};
|
|
1152
748
|
},
|
|
1153
749
|
complete(state) {
|
|
1154
|
-
const
|
|
750
|
+
const object$1 = {};
|
|
751
|
+
for (let i = 0; i < parsers.length; i++) {
|
|
752
|
+
const parser = parsers[i];
|
|
753
|
+
let parserState;
|
|
1155
754
|
if (parser.initialState === void 0) {
|
|
1156
|
-
const key = `__parser_${
|
|
1157
|
-
if (state && typeof state === "object" && key in state)
|
|
1158
|
-
|
|
1159
|
-
} else if (parser.initialState && typeof parser.initialState === "object") {
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
};
|
|
1169
|
-
if (!isAsync) {
|
|
1170
|
-
const object$1 = {};
|
|
1171
|
-
for (let i = 0; i < syncParsers.length; i++) {
|
|
1172
|
-
const parser = syncParsers[i];
|
|
1173
|
-
const parserState = extractCompleteState(parser, i);
|
|
1174
|
-
const result = parser.complete(parserState);
|
|
1175
|
-
if (!result.success) return result;
|
|
1176
|
-
for (const field in result.value) object$1[field] = result.value[field];
|
|
1177
|
-
}
|
|
1178
|
-
return {
|
|
1179
|
-
success: true,
|
|
1180
|
-
value: object$1
|
|
1181
|
-
};
|
|
755
|
+
const key = `__parser_${i}`;
|
|
756
|
+
if (state && typeof state === "object" && key in state) parserState = state[key];
|
|
757
|
+
else parserState = void 0;
|
|
758
|
+
} else if (parser.initialState && typeof parser.initialState === "object") if (state && typeof state === "object") {
|
|
759
|
+
const extractedState = {};
|
|
760
|
+
for (const field in parser.initialState) extractedState[field] = field in state ? state[field] : parser.initialState[field];
|
|
761
|
+
parserState = extractedState;
|
|
762
|
+
} else parserState = parser.initialState;
|
|
763
|
+
else parserState = parser.initialState;
|
|
764
|
+
const result = parser.complete(parserState);
|
|
765
|
+
if (!result.success) return result;
|
|
766
|
+
for (const field in result.value) object$1[field] = result.value[field];
|
|
1182
767
|
}
|
|
1183
|
-
return
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
const parserState = extractCompleteState(parser, i);
|
|
1188
|
-
const result = await parser.complete(parserState);
|
|
1189
|
-
if (!result.success) return result;
|
|
1190
|
-
for (const field in result.value) object$1[field] = result.value[field];
|
|
1191
|
-
}
|
|
1192
|
-
return {
|
|
1193
|
-
success: true,
|
|
1194
|
-
value: object$1
|
|
1195
|
-
};
|
|
1196
|
-
})();
|
|
768
|
+
return {
|
|
769
|
+
success: true,
|
|
770
|
+
value: object$1
|
|
771
|
+
};
|
|
1197
772
|
},
|
|
1198
773
|
suggest(context, prefix) {
|
|
1199
|
-
const
|
|
1200
|
-
|
|
774
|
+
const suggestions = [];
|
|
775
|
+
for (let i = 0; i < parsers.length; i++) {
|
|
776
|
+
const parser = parsers[i];
|
|
777
|
+
let parserState;
|
|
778
|
+
if (parser.initialState === void 0) {
|
|
1201
779
|
const key = `__parser_${i}`;
|
|
1202
|
-
if (context.state && typeof context.state === "object" && key in context.state)
|
|
1203
|
-
|
|
1204
|
-
} else if (
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
const parser = parsers[i];
|
|
1218
|
-
const parserState = extractState(parser, i);
|
|
1219
|
-
const parserSuggestions = parser.suggest({
|
|
1220
|
-
...context,
|
|
1221
|
-
state: parserState
|
|
1222
|
-
}, prefix);
|
|
1223
|
-
if (parser.$mode === "async") for await (const s of parserSuggestions) suggestions.push(s);
|
|
1224
|
-
else suggestions.push(...parserSuggestions);
|
|
1225
|
-
}
|
|
1226
|
-
yield* require_suggestion.deduplicateSuggestions(suggestions);
|
|
1227
|
-
}();
|
|
1228
|
-
return function* () {
|
|
1229
|
-
const suggestions = [];
|
|
1230
|
-
for (let i = 0; i < syncParsers.length; i++) {
|
|
1231
|
-
const parser = syncParsers[i];
|
|
1232
|
-
const parserState = extractState(parser, i);
|
|
1233
|
-
const parserSuggestions = parser.suggest({
|
|
1234
|
-
...context,
|
|
1235
|
-
state: parserState
|
|
1236
|
-
}, prefix);
|
|
1237
|
-
suggestions.push(...parserSuggestions);
|
|
1238
|
-
}
|
|
1239
|
-
yield* require_suggestion.deduplicateSuggestions(suggestions);
|
|
1240
|
-
}();
|
|
780
|
+
if (context.state && typeof context.state === "object" && key in context.state) parserState = context.state[key];
|
|
781
|
+
else parserState = void 0;
|
|
782
|
+
} else if (parser.initialState && typeof parser.initialState === "object") if (context.state && typeof context.state === "object") {
|
|
783
|
+
const extractedState = {};
|
|
784
|
+
for (const field in parser.initialState) extractedState[field] = field in context.state ? context.state[field] : parser.initialState[field];
|
|
785
|
+
parserState = extractedState;
|
|
786
|
+
} else parserState = parser.initialState;
|
|
787
|
+
else parserState = parser.initialState;
|
|
788
|
+
const parserSuggestions = parser.suggest({
|
|
789
|
+
...context,
|
|
790
|
+
state: parserState
|
|
791
|
+
}, prefix);
|
|
792
|
+
suggestions.push(...parserSuggestions);
|
|
793
|
+
}
|
|
794
|
+
return require_suggestion.deduplicateSuggestions(suggestions);
|
|
1241
795
|
},
|
|
1242
796
|
getDocFragments(state, _defaultValue) {
|
|
1243
797
|
const fragments = parsers.flatMap((p, i) => {
|
|
@@ -1284,213 +838,102 @@ function merge(...args) {
|
|
|
1284
838
|
};
|
|
1285
839
|
}
|
|
1286
840
|
function concat(...parsers) {
|
|
1287
|
-
const combinedMode = parsers.some((p) => p.$mode === "async") ? "async" : "sync";
|
|
1288
|
-
const isAsync = combinedMode === "async";
|
|
1289
|
-
const syncParsers = parsers;
|
|
1290
841
|
const initialState = parsers.map((parser) => parser.initialState);
|
|
1291
|
-
const parseSync = (context) => {
|
|
1292
|
-
let currentContext = context;
|
|
1293
|
-
const allConsumed = [];
|
|
1294
|
-
const matchedParsers = /* @__PURE__ */ new Set();
|
|
1295
|
-
while (matchedParsers.size < syncParsers.length) {
|
|
1296
|
-
let foundMatch = false;
|
|
1297
|
-
let error = {
|
|
1298
|
-
consumed: 0,
|
|
1299
|
-
error: require_message.message`No remaining parsers could match the input.`
|
|
1300
|
-
};
|
|
1301
|
-
const stateArray = currentContext.state;
|
|
1302
|
-
const remainingParsers = syncParsers.map((parser, index) => [parser, index]).filter(([_, index]) => !matchedParsers.has(index)).sort(([parserA], [parserB]) => parserB.priority - parserA.priority);
|
|
1303
|
-
for (const [parser, index] of remainingParsers) {
|
|
1304
|
-
const result = parser.parse({
|
|
1305
|
-
...currentContext,
|
|
1306
|
-
state: stateArray[index]
|
|
1307
|
-
});
|
|
1308
|
-
if (result.success && result.consumed.length > 0) {
|
|
1309
|
-
const newStateArray = stateArray.map((s, idx) => idx === index ? result.next.state : s);
|
|
1310
|
-
currentContext = {
|
|
1311
|
-
...currentContext,
|
|
1312
|
-
buffer: result.next.buffer,
|
|
1313
|
-
optionsTerminated: result.next.optionsTerminated,
|
|
1314
|
-
state: newStateArray
|
|
1315
|
-
};
|
|
1316
|
-
allConsumed.push(...result.consumed);
|
|
1317
|
-
matchedParsers.add(index);
|
|
1318
|
-
foundMatch = true;
|
|
1319
|
-
break;
|
|
1320
|
-
} else if (!result.success && error.consumed < result.consumed) error = result;
|
|
1321
|
-
}
|
|
1322
|
-
if (!foundMatch) for (const [parser, index] of remainingParsers) {
|
|
1323
|
-
const result = parser.parse({
|
|
1324
|
-
...currentContext,
|
|
1325
|
-
state: stateArray[index]
|
|
1326
|
-
});
|
|
1327
|
-
if (result.success && result.consumed.length < 1) {
|
|
1328
|
-
const newStateArray = stateArray.map((s, idx) => idx === index ? result.next.state : s);
|
|
1329
|
-
currentContext = {
|
|
1330
|
-
...currentContext,
|
|
1331
|
-
state: newStateArray
|
|
1332
|
-
};
|
|
1333
|
-
matchedParsers.add(index);
|
|
1334
|
-
foundMatch = true;
|
|
1335
|
-
break;
|
|
1336
|
-
} else if (!result.success && result.consumed < 1) {
|
|
1337
|
-
matchedParsers.add(index);
|
|
1338
|
-
foundMatch = true;
|
|
1339
|
-
break;
|
|
1340
|
-
}
|
|
1341
|
-
}
|
|
1342
|
-
if (!foundMatch) return {
|
|
1343
|
-
...error,
|
|
1344
|
-
success: false
|
|
1345
|
-
};
|
|
1346
|
-
}
|
|
1347
|
-
return {
|
|
1348
|
-
success: true,
|
|
1349
|
-
next: currentContext,
|
|
1350
|
-
consumed: allConsumed
|
|
1351
|
-
};
|
|
1352
|
-
};
|
|
1353
|
-
const parseAsync = async (context) => {
|
|
1354
|
-
let currentContext = context;
|
|
1355
|
-
const allConsumed = [];
|
|
1356
|
-
const matchedParsers = /* @__PURE__ */ new Set();
|
|
1357
|
-
while (matchedParsers.size < parsers.length) {
|
|
1358
|
-
let foundMatch = false;
|
|
1359
|
-
let error = {
|
|
1360
|
-
consumed: 0,
|
|
1361
|
-
error: require_message.message`No remaining parsers could match the input.`
|
|
1362
|
-
};
|
|
1363
|
-
const stateArray = currentContext.state;
|
|
1364
|
-
const remainingParsers = parsers.map((parser, index) => [parser, index]).filter(([_, index]) => !matchedParsers.has(index)).sort(([parserA], [parserB]) => parserB.priority - parserA.priority);
|
|
1365
|
-
for (const [parser, index] of remainingParsers) {
|
|
1366
|
-
const result = await parser.parse({
|
|
1367
|
-
...currentContext,
|
|
1368
|
-
state: stateArray[index]
|
|
1369
|
-
});
|
|
1370
|
-
if (result.success && result.consumed.length > 0) {
|
|
1371
|
-
const newStateArray = stateArray.map((s, idx) => idx === index ? result.next.state : s);
|
|
1372
|
-
currentContext = {
|
|
1373
|
-
...currentContext,
|
|
1374
|
-
buffer: result.next.buffer,
|
|
1375
|
-
optionsTerminated: result.next.optionsTerminated,
|
|
1376
|
-
state: newStateArray
|
|
1377
|
-
};
|
|
1378
|
-
allConsumed.push(...result.consumed);
|
|
1379
|
-
matchedParsers.add(index);
|
|
1380
|
-
foundMatch = true;
|
|
1381
|
-
break;
|
|
1382
|
-
} else if (!result.success && error.consumed < result.consumed) error = result;
|
|
1383
|
-
}
|
|
1384
|
-
if (!foundMatch) for (const [parser, index] of remainingParsers) {
|
|
1385
|
-
const result = await parser.parse({
|
|
1386
|
-
...currentContext,
|
|
1387
|
-
state: stateArray[index]
|
|
1388
|
-
});
|
|
1389
|
-
if (result.success && result.consumed.length < 1) {
|
|
1390
|
-
const newStateArray = stateArray.map((s, idx) => idx === index ? result.next.state : s);
|
|
1391
|
-
currentContext = {
|
|
1392
|
-
...currentContext,
|
|
1393
|
-
state: newStateArray
|
|
1394
|
-
};
|
|
1395
|
-
matchedParsers.add(index);
|
|
1396
|
-
foundMatch = true;
|
|
1397
|
-
break;
|
|
1398
|
-
} else if (!result.success && result.consumed < 1) {
|
|
1399
|
-
matchedParsers.add(index);
|
|
1400
|
-
foundMatch = true;
|
|
1401
|
-
break;
|
|
1402
|
-
}
|
|
1403
|
-
}
|
|
1404
|
-
if (!foundMatch) return {
|
|
1405
|
-
...error,
|
|
1406
|
-
success: false
|
|
1407
|
-
};
|
|
1408
|
-
}
|
|
1409
|
-
return {
|
|
1410
|
-
success: true,
|
|
1411
|
-
next: currentContext,
|
|
1412
|
-
consumed: allConsumed
|
|
1413
|
-
};
|
|
1414
|
-
};
|
|
1415
|
-
const completeSync = (state) => {
|
|
1416
|
-
const results = [];
|
|
1417
|
-
const stateArray = state;
|
|
1418
|
-
for (let i = 0; i < syncParsers.length; i++) {
|
|
1419
|
-
const parser = syncParsers[i];
|
|
1420
|
-
const parserState = stateArray[i];
|
|
1421
|
-
const result = parser.complete(parserState);
|
|
1422
|
-
if (!result.success) return result;
|
|
1423
|
-
if (Array.isArray(result.value)) results.push(...result.value);
|
|
1424
|
-
else results.push(result.value);
|
|
1425
|
-
}
|
|
1426
|
-
return {
|
|
1427
|
-
success: true,
|
|
1428
|
-
value: results
|
|
1429
|
-
};
|
|
1430
|
-
};
|
|
1431
|
-
const completeAsync = async (state) => {
|
|
1432
|
-
const results = [];
|
|
1433
|
-
const stateArray = state;
|
|
1434
|
-
for (let i = 0; i < parsers.length; i++) {
|
|
1435
|
-
const parser = parsers[i];
|
|
1436
|
-
const parserState = stateArray[i];
|
|
1437
|
-
const result = await parser.complete(parserState);
|
|
1438
|
-
if (!result.success) return result;
|
|
1439
|
-
if (Array.isArray(result.value)) results.push(...result.value);
|
|
1440
|
-
else results.push(result.value);
|
|
1441
|
-
}
|
|
1442
|
-
return {
|
|
1443
|
-
success: true,
|
|
1444
|
-
value: results
|
|
1445
|
-
};
|
|
1446
|
-
};
|
|
1447
842
|
return {
|
|
1448
|
-
$mode: combinedMode,
|
|
1449
843
|
$valueType: [],
|
|
1450
844
|
$stateType: [],
|
|
1451
845
|
priority: parsers.length > 0 ? Math.max(...parsers.map((p) => p.priority)) : 0,
|
|
1452
846
|
usage: parsers.flatMap((p) => p.usage),
|
|
1453
847
|
initialState,
|
|
1454
848
|
parse(context) {
|
|
1455
|
-
|
|
1456
|
-
|
|
849
|
+
let currentContext = context;
|
|
850
|
+
const allConsumed = [];
|
|
851
|
+
const matchedParsers = /* @__PURE__ */ new Set();
|
|
852
|
+
while (matchedParsers.size < parsers.length) {
|
|
853
|
+
let foundMatch = false;
|
|
854
|
+
let error = {
|
|
855
|
+
consumed: 0,
|
|
856
|
+
error: require_message.message`No remaining parsers could match the input.`
|
|
857
|
+
};
|
|
858
|
+
const remainingParsers = parsers.map((parser, index) => [parser, index]).filter(([_, index]) => !matchedParsers.has(index)).sort(([parserA], [parserB]) => parserB.priority - parserA.priority);
|
|
859
|
+
for (const [parser, index] of remainingParsers) {
|
|
860
|
+
const result = parser.parse({
|
|
861
|
+
...currentContext,
|
|
862
|
+
state: currentContext.state[index]
|
|
863
|
+
});
|
|
864
|
+
if (result.success && result.consumed.length > 0) {
|
|
865
|
+
currentContext = {
|
|
866
|
+
...currentContext,
|
|
867
|
+
buffer: result.next.buffer,
|
|
868
|
+
optionsTerminated: result.next.optionsTerminated,
|
|
869
|
+
state: currentContext.state.map((s, idx) => idx === index ? result.next.state : s)
|
|
870
|
+
};
|
|
871
|
+
allConsumed.push(...result.consumed);
|
|
872
|
+
matchedParsers.add(index);
|
|
873
|
+
foundMatch = true;
|
|
874
|
+
break;
|
|
875
|
+
} else if (!result.success && error.consumed < result.consumed) error = result;
|
|
876
|
+
}
|
|
877
|
+
if (!foundMatch) for (const [parser, index] of remainingParsers) {
|
|
878
|
+
const result = parser.parse({
|
|
879
|
+
...currentContext,
|
|
880
|
+
state: currentContext.state[index]
|
|
881
|
+
});
|
|
882
|
+
if (result.success && result.consumed.length < 1) {
|
|
883
|
+
currentContext = {
|
|
884
|
+
...currentContext,
|
|
885
|
+
state: currentContext.state.map((s, idx) => idx === index ? result.next.state : s)
|
|
886
|
+
};
|
|
887
|
+
matchedParsers.add(index);
|
|
888
|
+
foundMatch = true;
|
|
889
|
+
break;
|
|
890
|
+
} else if (!result.success && result.consumed < 1) {
|
|
891
|
+
matchedParsers.add(index);
|
|
892
|
+
foundMatch = true;
|
|
893
|
+
break;
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
if (!foundMatch) return {
|
|
897
|
+
...error,
|
|
898
|
+
success: false
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
return {
|
|
902
|
+
success: true,
|
|
903
|
+
next: currentContext,
|
|
904
|
+
consumed: allConsumed
|
|
905
|
+
};
|
|
1457
906
|
},
|
|
1458
907
|
complete(state) {
|
|
1459
|
-
|
|
1460
|
-
|
|
908
|
+
const results = [];
|
|
909
|
+
for (let i = 0; i < parsers.length; i++) {
|
|
910
|
+
const parser = parsers[i];
|
|
911
|
+
const parserState = state[i];
|
|
912
|
+
const result = parser.complete(parserState);
|
|
913
|
+
if (!result.success) return result;
|
|
914
|
+
if (Array.isArray(result.value)) results.push(...result.value);
|
|
915
|
+
else results.push(result.value);
|
|
916
|
+
}
|
|
917
|
+
return {
|
|
918
|
+
success: true,
|
|
919
|
+
value: results
|
|
920
|
+
};
|
|
1461
921
|
},
|
|
1462
922
|
suggest(context, prefix) {
|
|
1463
|
-
const
|
|
1464
|
-
|
|
1465
|
-
const
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
else suggestions.push(...parserSuggestions);
|
|
1475
|
-
}
|
|
1476
|
-
yield* require_suggestion.deduplicateSuggestions(suggestions);
|
|
1477
|
-
}();
|
|
1478
|
-
return function* () {
|
|
1479
|
-
const suggestions = [];
|
|
1480
|
-
for (let i = 0; i < syncParsers.length; i++) {
|
|
1481
|
-
const parser = syncParsers[i];
|
|
1482
|
-
const parserState = stateArray && Array.isArray(stateArray) ? stateArray[i] : parser.initialState;
|
|
1483
|
-
const parserSuggestions = parser.suggest({
|
|
1484
|
-
...context,
|
|
1485
|
-
state: parserState
|
|
1486
|
-
}, prefix);
|
|
1487
|
-
suggestions.push(...parserSuggestions);
|
|
1488
|
-
}
|
|
1489
|
-
yield* require_suggestion.deduplicateSuggestions(suggestions);
|
|
1490
|
-
}();
|
|
923
|
+
const suggestions = [];
|
|
924
|
+
for (let i = 0; i < parsers.length; i++) {
|
|
925
|
+
const parser = parsers[i];
|
|
926
|
+
const parserState = context.state && Array.isArray(context.state) ? context.state[i] : parser.initialState;
|
|
927
|
+
const parserSuggestions = parser.suggest({
|
|
928
|
+
...context,
|
|
929
|
+
state: parserState
|
|
930
|
+
}, prefix);
|
|
931
|
+
suggestions.push(...parserSuggestions);
|
|
932
|
+
}
|
|
933
|
+
return require_suggestion.deduplicateSuggestions(suggestions);
|
|
1491
934
|
},
|
|
1492
935
|
getDocFragments(state, _defaultValue) {
|
|
1493
|
-
const fragments =
|
|
936
|
+
const fragments = parsers.flatMap((p, index) => {
|
|
1494
937
|
const indexState = state.kind === "unavailable" ? { kind: "unavailable" } : {
|
|
1495
938
|
kind: "available",
|
|
1496
939
|
state: state.state[index]
|
|
@@ -1560,7 +1003,6 @@ function concat(...parsers) {
|
|
|
1560
1003
|
*/
|
|
1561
1004
|
function group(label, parser) {
|
|
1562
1005
|
return {
|
|
1563
|
-
$mode: parser.$mode,
|
|
1564
1006
|
$valueType: parser.$valueType,
|
|
1565
1007
|
$stateType: parser.$stateType,
|
|
1566
1008
|
priority: parser.priority,
|
|
@@ -1626,8 +1068,6 @@ function group(label, parser) {
|
|
|
1626
1068
|
function conditional(discriminator, branches, defaultBranch, options) {
|
|
1627
1069
|
const branchParsers = Object.entries(branches);
|
|
1628
1070
|
const allBranchParsers = defaultBranch ? [...branchParsers.map(([_, p]) => p), defaultBranch] : branchParsers.map(([_, p]) => p);
|
|
1629
|
-
const combinedMode = discriminator.$mode === "async" || allBranchParsers.some((p) => p.$mode === "async") ? "async" : "sync";
|
|
1630
|
-
const isAsync = combinedMode === "async";
|
|
1631
1071
|
const maxPriority = Math.max(discriminator.priority, ...allBranchParsers.map((p) => p.priority));
|
|
1632
1072
|
function appendLiteralToUsage(usage$1, literalValue) {
|
|
1633
1073
|
const result = [];
|
|
@@ -1665,334 +1105,164 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
1665
1105
|
selectedBranch: void 0,
|
|
1666
1106
|
branchState: void 0
|
|
1667
1107
|
};
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
}
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
return branchResult;
|
|
1696
|
-
}
|
|
1697
|
-
const discriminatorResult = syncDiscriminator.parse({
|
|
1698
|
-
...context,
|
|
1699
|
-
state: state.discriminatorState
|
|
1700
|
-
});
|
|
1701
|
-
if (discriminatorResult.success && discriminatorResult.consumed.length > 0) {
|
|
1702
|
-
const completionResult = syncDiscriminator.complete(discriminatorResult.next.state);
|
|
1703
|
-
if (completionResult.success) {
|
|
1704
|
-
const value = completionResult.value;
|
|
1705
|
-
const branchParser = syncBranches[value];
|
|
1706
|
-
if (branchParser) {
|
|
1707
|
-
const branchParseResult = branchParser.parse({
|
|
1708
|
-
...context,
|
|
1709
|
-
buffer: discriminatorResult.next.buffer,
|
|
1710
|
-
optionsTerminated: discriminatorResult.next.optionsTerminated,
|
|
1711
|
-
state: branchParser.initialState,
|
|
1712
|
-
usage: branchParser.usage
|
|
1713
|
-
});
|
|
1714
|
-
if (branchParseResult.success) return {
|
|
1715
|
-
success: true,
|
|
1716
|
-
next: {
|
|
1717
|
-
...branchParseResult.next,
|
|
1718
|
-
state: {
|
|
1719
|
-
discriminatorState: discriminatorResult.next.state,
|
|
1720
|
-
discriminatorValue: value,
|
|
1721
|
-
selectedBranch: {
|
|
1722
|
-
kind: "branch",
|
|
1723
|
-
key: value
|
|
1724
|
-
},
|
|
1725
|
-
branchState: branchParseResult.next.state
|
|
1726
|
-
}
|
|
1727
|
-
},
|
|
1728
|
-
consumed: [...discriminatorResult.consumed, ...branchParseResult.consumed]
|
|
1729
|
-
};
|
|
1730
|
-
return {
|
|
1731
|
-
success: true,
|
|
1732
|
-
next: {
|
|
1733
|
-
...discriminatorResult.next,
|
|
1734
|
-
state: {
|
|
1735
|
-
discriminatorState: discriminatorResult.next.state,
|
|
1736
|
-
discriminatorValue: value,
|
|
1737
|
-
selectedBranch: {
|
|
1738
|
-
kind: "branch",
|
|
1739
|
-
key: value
|
|
1740
|
-
},
|
|
1741
|
-
branchState: branchParser.initialState
|
|
1742
|
-
}
|
|
1743
|
-
},
|
|
1744
|
-
consumed: discriminatorResult.consumed
|
|
1745
|
-
};
|
|
1746
|
-
}
|
|
1108
|
+
return {
|
|
1109
|
+
$valueType: [],
|
|
1110
|
+
$stateType: [],
|
|
1111
|
+
priority: maxPriority,
|
|
1112
|
+
usage,
|
|
1113
|
+
initialState,
|
|
1114
|
+
parse(context) {
|
|
1115
|
+
const state = context.state ?? initialState;
|
|
1116
|
+
if (state.selectedBranch !== void 0) {
|
|
1117
|
+
const branchParser = state.selectedBranch.kind === "default" ? defaultBranch : branches[state.selectedBranch.key];
|
|
1118
|
+
const branchResult = branchParser.parse({
|
|
1119
|
+
...context,
|
|
1120
|
+
state: state.branchState,
|
|
1121
|
+
usage: branchParser.usage
|
|
1122
|
+
});
|
|
1123
|
+
if (branchResult.success) return {
|
|
1124
|
+
success: true,
|
|
1125
|
+
next: {
|
|
1126
|
+
...branchResult.next,
|
|
1127
|
+
state: {
|
|
1128
|
+
...state,
|
|
1129
|
+
branchState: branchResult.next.state
|
|
1130
|
+
}
|
|
1131
|
+
},
|
|
1132
|
+
consumed: branchResult.consumed
|
|
1133
|
+
};
|
|
1134
|
+
return branchResult;
|
|
1747
1135
|
}
|
|
1748
|
-
|
|
1749
|
-
if (syncDefaultBranch !== void 0) {
|
|
1750
|
-
const defaultResult = syncDefaultBranch.parse({
|
|
1751
|
-
...context,
|
|
1752
|
-
state: state.branchState ?? syncDefaultBranch.initialState,
|
|
1753
|
-
usage: syncDefaultBranch.usage
|
|
1754
|
-
});
|
|
1755
|
-
if (defaultResult.success && defaultResult.consumed.length > 0) return {
|
|
1756
|
-
success: true,
|
|
1757
|
-
next: {
|
|
1758
|
-
...defaultResult.next,
|
|
1759
|
-
state: {
|
|
1760
|
-
...state,
|
|
1761
|
-
selectedBranch: { kind: "default" },
|
|
1762
|
-
branchState: defaultResult.next.state
|
|
1763
|
-
}
|
|
1764
|
-
},
|
|
1765
|
-
consumed: defaultResult.consumed
|
|
1766
|
-
};
|
|
1767
|
-
}
|
|
1768
|
-
return {
|
|
1769
|
-
success: false,
|
|
1770
|
-
consumed: 0,
|
|
1771
|
-
error: getNoMatchError$1()
|
|
1772
|
-
};
|
|
1773
|
-
};
|
|
1774
|
-
const parseAsync = async (context) => {
|
|
1775
|
-
const state = context.state ?? initialState;
|
|
1776
|
-
if (state.selectedBranch !== void 0) {
|
|
1777
|
-
const branchParser = state.selectedBranch.kind === "default" ? defaultBranch : branches[state.selectedBranch.key];
|
|
1778
|
-
const branchResult = await branchParser.parse({
|
|
1136
|
+
const discriminatorResult = discriminator.parse({
|
|
1779
1137
|
...context,
|
|
1780
|
-
state: state.
|
|
1781
|
-
usage: branchParser.usage
|
|
1138
|
+
state: state.discriminatorState
|
|
1782
1139
|
});
|
|
1783
|
-
if (
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1140
|
+
if (discriminatorResult.success && discriminatorResult.consumed.length > 0) {
|
|
1141
|
+
const completionResult = discriminator.complete(discriminatorResult.next.state);
|
|
1142
|
+
if (completionResult.success) {
|
|
1143
|
+
const value = completionResult.value;
|
|
1144
|
+
const branchParser = branches[value];
|
|
1145
|
+
if (branchParser) {
|
|
1146
|
+
const branchParseResult = branchParser.parse({
|
|
1147
|
+
...context,
|
|
1148
|
+
buffer: discriminatorResult.next.buffer,
|
|
1149
|
+
optionsTerminated: discriminatorResult.next.optionsTerminated,
|
|
1150
|
+
state: branchParser.initialState,
|
|
1151
|
+
usage: branchParser.usage
|
|
1152
|
+
});
|
|
1153
|
+
if (branchParseResult.success) return {
|
|
1154
|
+
success: true,
|
|
1155
|
+
next: {
|
|
1156
|
+
...branchParseResult.next,
|
|
1157
|
+
state: {
|
|
1158
|
+
discriminatorState: discriminatorResult.next.state,
|
|
1159
|
+
discriminatorValue: value,
|
|
1160
|
+
selectedBranch: {
|
|
1161
|
+
kind: "branch",
|
|
1162
|
+
key: value
|
|
1163
|
+
},
|
|
1164
|
+
branchState: branchParseResult.next.state
|
|
1165
|
+
}
|
|
1166
|
+
},
|
|
1167
|
+
consumed: [...discriminatorResult.consumed, ...branchParseResult.consumed]
|
|
1168
|
+
};
|
|
1169
|
+
return {
|
|
1170
|
+
success: true,
|
|
1171
|
+
next: {
|
|
1172
|
+
...discriminatorResult.next,
|
|
1173
|
+
state: {
|
|
1174
|
+
discriminatorState: discriminatorResult.next.state,
|
|
1175
|
+
discriminatorValue: value,
|
|
1176
|
+
selectedBranch: {
|
|
1177
|
+
kind: "branch",
|
|
1178
|
+
key: value
|
|
1179
|
+
},
|
|
1180
|
+
branchState: branchParser.initialState
|
|
1181
|
+
}
|
|
1182
|
+
},
|
|
1183
|
+
consumed: discriminatorResult.consumed
|
|
1184
|
+
};
|
|
1790
1185
|
}
|
|
1791
|
-
},
|
|
1792
|
-
consumed: branchResult.consumed
|
|
1793
|
-
};
|
|
1794
|
-
return branchResult;
|
|
1795
|
-
}
|
|
1796
|
-
const discriminatorResult = await discriminator.parse({
|
|
1797
|
-
...context,
|
|
1798
|
-
state: state.discriminatorState
|
|
1799
|
-
});
|
|
1800
|
-
if (discriminatorResult.success && discriminatorResult.consumed.length > 0) {
|
|
1801
|
-
const completionResult = await discriminator.complete(discriminatorResult.next.state);
|
|
1802
|
-
if (completionResult.success) {
|
|
1803
|
-
const value = completionResult.value;
|
|
1804
|
-
const branchParser = branches[value];
|
|
1805
|
-
if (branchParser) {
|
|
1806
|
-
const branchParseResult = await branchParser.parse({
|
|
1807
|
-
...context,
|
|
1808
|
-
buffer: discriminatorResult.next.buffer,
|
|
1809
|
-
optionsTerminated: discriminatorResult.next.optionsTerminated,
|
|
1810
|
-
state: branchParser.initialState,
|
|
1811
|
-
usage: branchParser.usage
|
|
1812
|
-
});
|
|
1813
|
-
if (branchParseResult.success) return {
|
|
1814
|
-
success: true,
|
|
1815
|
-
next: {
|
|
1816
|
-
...branchParseResult.next,
|
|
1817
|
-
state: {
|
|
1818
|
-
discriminatorState: discriminatorResult.next.state,
|
|
1819
|
-
discriminatorValue: value,
|
|
1820
|
-
selectedBranch: {
|
|
1821
|
-
kind: "branch",
|
|
1822
|
-
key: value
|
|
1823
|
-
},
|
|
1824
|
-
branchState: branchParseResult.next.state
|
|
1825
|
-
}
|
|
1826
|
-
},
|
|
1827
|
-
consumed: [...discriminatorResult.consumed, ...branchParseResult.consumed]
|
|
1828
|
-
};
|
|
1829
|
-
return {
|
|
1830
|
-
success: true,
|
|
1831
|
-
next: {
|
|
1832
|
-
...discriminatorResult.next,
|
|
1833
|
-
state: {
|
|
1834
|
-
discriminatorState: discriminatorResult.next.state,
|
|
1835
|
-
discriminatorValue: value,
|
|
1836
|
-
selectedBranch: {
|
|
1837
|
-
kind: "branch",
|
|
1838
|
-
key: value
|
|
1839
|
-
},
|
|
1840
|
-
branchState: branchParser.initialState
|
|
1841
|
-
}
|
|
1842
|
-
},
|
|
1843
|
-
consumed: discriminatorResult.consumed
|
|
1844
|
-
};
|
|
1845
1186
|
}
|
|
1846
1187
|
}
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
if (defaultResult.success && defaultResult.consumed.length > 0) return {
|
|
1855
|
-
success: true,
|
|
1856
|
-
next: {
|
|
1857
|
-
...defaultResult.next,
|
|
1858
|
-
state: {
|
|
1859
|
-
...state,
|
|
1860
|
-
selectedBranch: { kind: "default" },
|
|
1861
|
-
branchState: defaultResult.next.state
|
|
1862
|
-
}
|
|
1863
|
-
},
|
|
1864
|
-
consumed: defaultResult.consumed
|
|
1865
|
-
};
|
|
1866
|
-
}
|
|
1867
|
-
return {
|
|
1868
|
-
success: false,
|
|
1869
|
-
consumed: 0,
|
|
1870
|
-
error: getNoMatchError$1()
|
|
1871
|
-
};
|
|
1872
|
-
};
|
|
1873
|
-
const completeSync = (state) => {
|
|
1874
|
-
const syncDefaultBranch = defaultBranch;
|
|
1875
|
-
const syncBranches = branches;
|
|
1876
|
-
if (state.selectedBranch === void 0) {
|
|
1877
|
-
if (syncDefaultBranch !== void 0) {
|
|
1878
|
-
const branchState = state.branchState ?? syncDefaultBranch.initialState;
|
|
1879
|
-
const defaultResult = syncDefaultBranch.complete(branchState);
|
|
1880
|
-
if (!defaultResult.success) return defaultResult;
|
|
1881
|
-
return {
|
|
1188
|
+
if (defaultBranch !== void 0) {
|
|
1189
|
+
const defaultResult = defaultBranch.parse({
|
|
1190
|
+
...context,
|
|
1191
|
+
state: state.branchState ?? defaultBranch.initialState,
|
|
1192
|
+
usage: defaultBranch.usage
|
|
1193
|
+
});
|
|
1194
|
+
if (defaultResult.success && defaultResult.consumed.length > 0) return {
|
|
1882
1195
|
success: true,
|
|
1883
|
-
|
|
1196
|
+
next: {
|
|
1197
|
+
...defaultResult.next,
|
|
1198
|
+
state: {
|
|
1199
|
+
...state,
|
|
1200
|
+
selectedBranch: { kind: "default" },
|
|
1201
|
+
branchState: defaultResult.next.state
|
|
1202
|
+
}
|
|
1203
|
+
},
|
|
1204
|
+
consumed: defaultResult.consumed
|
|
1884
1205
|
};
|
|
1885
1206
|
}
|
|
1207
|
+
const noMatchContext = analyzeNoMatchContext([discriminator, ...allBranchParsers]);
|
|
1208
|
+
const errorMessage = options?.errors?.noMatch ? typeof options.errors.noMatch === "function" ? options.errors.noMatch(noMatchContext) : options.errors.noMatch : generateNoMatchError(noMatchContext);
|
|
1886
1209
|
return {
|
|
1887
1210
|
success: false,
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
}
|
|
1891
|
-
const branchParser = state.selectedBranch.kind === "default" ? syncDefaultBranch : syncBranches[state.selectedBranch.key];
|
|
1892
|
-
const branchResult = branchParser.complete(state.branchState);
|
|
1893
|
-
if (!branchResult.success) {
|
|
1894
|
-
if (state.discriminatorValue !== void 0 && options?.errors?.branchError) return {
|
|
1895
|
-
success: false,
|
|
1896
|
-
error: options.errors.branchError(state.discriminatorValue, branchResult.error)
|
|
1211
|
+
consumed: 0,
|
|
1212
|
+
error: errorMessage
|
|
1897
1213
|
};
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
const defaultResult = await defaultBranch.complete(branchState);
|
|
1911
|
-
if (!defaultResult.success) return defaultResult;
|
|
1214
|
+
},
|
|
1215
|
+
complete(state) {
|
|
1216
|
+
if (state.selectedBranch === void 0) {
|
|
1217
|
+
if (defaultBranch !== void 0) {
|
|
1218
|
+
const branchState = state.branchState ?? defaultBranch.initialState;
|
|
1219
|
+
const defaultResult = defaultBranch.complete(branchState);
|
|
1220
|
+
if (!defaultResult.success) return defaultResult;
|
|
1221
|
+
return {
|
|
1222
|
+
success: true,
|
|
1223
|
+
value: [void 0, defaultResult.value]
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
1912
1226
|
return {
|
|
1913
|
-
success:
|
|
1914
|
-
|
|
1227
|
+
success: false,
|
|
1228
|
+
error: require_message.message`Missing required discriminator option.`
|
|
1229
|
+
};
|
|
1230
|
+
}
|
|
1231
|
+
const branchParser = state.selectedBranch.kind === "default" ? defaultBranch : branches[state.selectedBranch.key];
|
|
1232
|
+
const branchResult = branchParser.complete(state.branchState);
|
|
1233
|
+
if (!branchResult.success) {
|
|
1234
|
+
if (state.discriminatorValue !== void 0 && options?.errors?.branchError) return {
|
|
1235
|
+
success: false,
|
|
1236
|
+
error: options.errors.branchError(state.discriminatorValue, branchResult.error)
|
|
1915
1237
|
};
|
|
1238
|
+
return branchResult;
|
|
1916
1239
|
}
|
|
1240
|
+
const discriminatorValue = state.selectedBranch.kind === "default" ? void 0 : state.selectedBranch.key;
|
|
1917
1241
|
return {
|
|
1918
|
-
success:
|
|
1919
|
-
|
|
1920
|
-
};
|
|
1921
|
-
}
|
|
1922
|
-
const branchParser = state.selectedBranch.kind === "default" ? defaultBranch : branches[state.selectedBranch.key];
|
|
1923
|
-
const branchResult = await branchParser.complete(state.branchState);
|
|
1924
|
-
if (!branchResult.success) {
|
|
1925
|
-
if (state.discriminatorValue !== void 0 && options?.errors?.branchError) return {
|
|
1926
|
-
success: false,
|
|
1927
|
-
error: options.errors.branchError(state.discriminatorValue, branchResult.error)
|
|
1242
|
+
success: true,
|
|
1243
|
+
value: [discriminatorValue, branchResult.value]
|
|
1928
1244
|
};
|
|
1929
|
-
return branchResult;
|
|
1930
|
-
}
|
|
1931
|
-
const discriminatorValue = state.selectedBranch.kind === "default" ? void 0 : state.selectedBranch.key;
|
|
1932
|
-
return {
|
|
1933
|
-
success: true,
|
|
1934
|
-
value: [discriminatorValue, branchResult.value]
|
|
1935
|
-
};
|
|
1936
|
-
};
|
|
1937
|
-
function* suggestSync(context, prefix) {
|
|
1938
|
-
const state = context.state ?? initialState;
|
|
1939
|
-
const syncDiscriminator = discriminator;
|
|
1940
|
-
const syncBranches = branches;
|
|
1941
|
-
const syncDefaultBranch = defaultBranch;
|
|
1942
|
-
if (state.selectedBranch === void 0) {
|
|
1943
|
-
yield* syncDiscriminator.suggest({
|
|
1944
|
-
...context,
|
|
1945
|
-
state: state.discriminatorState
|
|
1946
|
-
}, prefix);
|
|
1947
|
-
if (syncDefaultBranch !== void 0) yield* syncDefaultBranch.suggest({
|
|
1948
|
-
...context,
|
|
1949
|
-
state: state.branchState ?? syncDefaultBranch.initialState
|
|
1950
|
-
}, prefix);
|
|
1951
|
-
} else {
|
|
1952
|
-
const branchParser = state.selectedBranch.kind === "default" ? syncDefaultBranch : syncBranches[state.selectedBranch.key];
|
|
1953
|
-
yield* branchParser.suggest({
|
|
1954
|
-
...context,
|
|
1955
|
-
state: state.branchState
|
|
1956
|
-
}, prefix);
|
|
1957
|
-
}
|
|
1958
|
-
}
|
|
1959
|
-
async function* suggestAsync(context, prefix) {
|
|
1960
|
-
const state = context.state ?? initialState;
|
|
1961
|
-
if (state.selectedBranch === void 0) {
|
|
1962
|
-
yield* discriminator.suggest({
|
|
1963
|
-
...context,
|
|
1964
|
-
state: state.discriminatorState
|
|
1965
|
-
}, prefix);
|
|
1966
|
-
if (defaultBranch !== void 0) yield* defaultBranch.suggest({
|
|
1967
|
-
...context,
|
|
1968
|
-
state: state.branchState ?? defaultBranch.initialState
|
|
1969
|
-
}, prefix);
|
|
1970
|
-
} else {
|
|
1971
|
-
const branchParser = state.selectedBranch.kind === "default" ? defaultBranch : branches[state.selectedBranch.key];
|
|
1972
|
-
yield* branchParser.suggest({
|
|
1973
|
-
...context,
|
|
1974
|
-
state: state.branchState
|
|
1975
|
-
}, prefix);
|
|
1976
|
-
}
|
|
1977
|
-
}
|
|
1978
|
-
return {
|
|
1979
|
-
$mode: combinedMode,
|
|
1980
|
-
$valueType: [],
|
|
1981
|
-
$stateType: [],
|
|
1982
|
-
priority: maxPriority,
|
|
1983
|
-
usage,
|
|
1984
|
-
initialState,
|
|
1985
|
-
parse(context) {
|
|
1986
|
-
if (isAsync) return parseAsync(context);
|
|
1987
|
-
return parseSync(context);
|
|
1988
|
-
},
|
|
1989
|
-
complete(state) {
|
|
1990
|
-
if (isAsync) return completeAsync(state);
|
|
1991
|
-
return completeSync(state);
|
|
1992
1245
|
},
|
|
1993
1246
|
suggest(context, prefix) {
|
|
1994
|
-
|
|
1995
|
-
|
|
1247
|
+
const state = context.state ?? initialState;
|
|
1248
|
+
const suggestions = [];
|
|
1249
|
+
if (state.selectedBranch === void 0) {
|
|
1250
|
+
suggestions.push(...discriminator.suggest({
|
|
1251
|
+
...context,
|
|
1252
|
+
state: state.discriminatorState
|
|
1253
|
+
}, prefix));
|
|
1254
|
+
if (defaultBranch !== void 0) suggestions.push(...defaultBranch.suggest({
|
|
1255
|
+
...context,
|
|
1256
|
+
state: state.branchState ?? defaultBranch.initialState
|
|
1257
|
+
}, prefix));
|
|
1258
|
+
} else {
|
|
1259
|
+
const branchParser = state.selectedBranch.kind === "default" ? defaultBranch : branches[state.selectedBranch.key];
|
|
1260
|
+
suggestions.push(...branchParser.suggest({
|
|
1261
|
+
...context,
|
|
1262
|
+
state: state.branchState
|
|
1263
|
+
}, prefix));
|
|
1264
|
+
}
|
|
1265
|
+
return require_suggestion.deduplicateSuggestions(suggestions);
|
|
1996
1266
|
},
|
|
1997
1267
|
getDocFragments(_state, _defaultValue) {
|
|
1998
1268
|
const fragments = [];
|