@optique/core 1.1.0-dev.2087 → 1.1.0-dev.2146
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/annotation-state.cjs +26 -26
- package/dist/annotation-state.d.cts +133 -1
- package/dist/annotation-state.d.ts +133 -1
- package/dist/annotations.cjs +2 -2
- package/dist/constructs.cjs +873 -73
- package/dist/constructs.d.cts +72 -1
- package/dist/constructs.d.ts +72 -1
- package/dist/constructs.js +808 -9
- package/dist/dependency-metadata.cjs +12 -12
- package/dist/dependency-metadata.d.cts +34 -3
- package/dist/dependency-metadata.d.ts +34 -3
- package/dist/dependency-runtime.cjs +37 -13
- package/dist/dependency-runtime.d.cts +197 -2
- package/dist/dependency-runtime.d.ts +197 -2
- package/dist/dependency-runtime.js +22 -1
- package/dist/dependency.cjs +7 -7
- package/dist/displaywidth.d.cts +12 -0
- package/dist/displaywidth.d.ts +12 -0
- package/dist/doc.cjs +3 -0
- package/dist/doc.js +3 -0
- package/dist/execution-context.d.cts +23 -0
- package/dist/execution-context.d.ts +23 -0
- package/dist/extension.cjs +14 -14
- package/dist/facade.cjs +49 -37
- package/dist/facade.js +34 -22
- package/dist/index.cjs +23 -21
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +4 -4
- package/dist/input-trace.d.cts +2 -1
- package/dist/input-trace.d.ts +2 -1
- package/dist/internal/annotations.cjs +3 -0
- package/dist/internal/annotations.d.cts +47 -5
- package/dist/internal/annotations.d.ts +47 -5
- package/dist/internal/annotations.js +1 -1
- package/dist/internal/command-alias.cjs +16 -0
- package/dist/internal/command-alias.js +14 -0
- package/dist/internal/dependency.cjs +131 -0
- package/dist/internal/dependency.d.cts +311 -2
- package/dist/internal/dependency.d.ts +311 -2
- package/dist/internal/dependency.js +119 -1
- package/dist/internal/parser.cjs +108 -23
- package/dist/internal/parser.d.cts +58 -3
- package/dist/internal/parser.d.ts +58 -3
- package/dist/internal/parser.js +101 -16
- package/dist/modifiers.cjs +74 -44
- package/dist/modifiers.js +34 -4
- package/dist/parser.cjs +11 -11
- package/dist/phase2-seed.cjs +2 -2
- package/dist/phase2-seed.d.cts +50 -0
- package/dist/phase2-seed.d.ts +50 -0
- package/dist/primitives.cjs +104 -33
- package/dist/primitives.d.cts +10 -0
- package/dist/primitives.d.ts +10 -0
- package/dist/primitives.js +84 -13
- package/dist/suggestion.cjs +72 -2
- package/dist/suggestion.d.cts +188 -0
- package/dist/suggestion.d.ts +188 -0
- package/dist/suggestion.js +71 -3
- package/dist/usage-internals.cjs +14 -6
- package/dist/usage-internals.js +14 -6
- package/dist/usage.cjs +33 -8
- package/dist/usage.d.cts +31 -0
- package/dist/usage.d.ts +31 -0
- package/dist/usage.js +33 -8
- package/dist/validate.cjs +1 -0
- package/dist/validate.d.cts +99 -0
- package/dist/validate.d.ts +99 -0
- package/dist/validate.js +1 -1
- package/dist/valueparser.cjs +333 -79
- package/dist/valueparser.d.cts +197 -1
- package/dist/valueparser.d.ts +197 -1
- package/dist/valueparser.js +334 -81
- package/package.json +19 -4
package/dist/constructs.cjs
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_internal_annotations = require('./internal/annotations.cjs');
|
|
2
2
|
const require_message = require('./message.cjs');
|
|
3
3
|
const require_validate = require('./validate.cjs');
|
|
4
4
|
const require_usage = require('./usage.cjs');
|
|
5
5
|
const require_doc = require('./doc.cjs');
|
|
6
6
|
const require_mode_dispatch = require('./internal/mode-dispatch.cjs');
|
|
7
|
-
const
|
|
7
|
+
const require_internal_dependency = require('./internal/dependency.cjs');
|
|
8
8
|
const require_dependency_runtime = require('./dependency-runtime.cjs');
|
|
9
|
-
const
|
|
9
|
+
const require_internal_parser = require('./internal/parser.cjs');
|
|
10
10
|
const require_annotation_state = require('./annotation-state.cjs');
|
|
11
|
+
const require_command_alias = require('./internal/command-alias.cjs');
|
|
11
12
|
const require_execution_context = require('./execution-context.cjs');
|
|
12
13
|
const require_phase2_seed = require('./phase2-seed.cjs');
|
|
13
14
|
const require_suggestion = require('./suggestion.cjs');
|
|
@@ -20,7 +21,7 @@ const require_usage_internals = require('./usage-internals.cjs');
|
|
|
20
21
|
*/
|
|
21
22
|
const EMPTY_LEADING_NAMES = /* @__PURE__ */ new Set();
|
|
22
23
|
function isNonCliBoundSourceState(state, parser) {
|
|
23
|
-
return parser[
|
|
24
|
+
return parser[require_internal_parser.unmatchedNonCliDependencySourceStateMarker] === true && state != null && typeof state === "object" && Object.hasOwn(state, "hasCliValue") && state.hasCliValue === false;
|
|
24
25
|
}
|
|
25
26
|
function withDependencyRuntimeExec(usage, exec, runtime) {
|
|
26
27
|
if (exec == null) return {
|
|
@@ -43,8 +44,8 @@ function withChildContext$1(context, segment, state, parser, usage) {
|
|
|
43
44
|
}
|
|
44
45
|
function isUnmatchedDependencyState(state, parser) {
|
|
45
46
|
if (state === void 0) return true;
|
|
46
|
-
if (Array.isArray(state) && state.length === 1 &&
|
|
47
|
-
if (
|
|
47
|
+
if (Array.isArray(state) && state.length === 1 && require_internal_dependency.isPendingDependencySourceState(state[0])) return true;
|
|
48
|
+
if (require_internal_dependency.isPendingDependencySourceState(state)) return true;
|
|
48
49
|
if (isNonCliBoundSourceState(state, parser)) return true;
|
|
49
50
|
return state === parser.initialState;
|
|
50
51
|
}
|
|
@@ -61,7 +62,7 @@ function buildIndexedParserPairs(parsers) {
|
|
|
61
62
|
}
|
|
62
63
|
function createAnnotatedArrayStateRecord(stateArray) {
|
|
63
64
|
const stateRecord = Object.fromEntries(stateArray.map((state, index) => [String(index), state]));
|
|
64
|
-
return
|
|
65
|
+
return require_internal_annotations.inheritAnnotations(stateArray, stateRecord);
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
67
68
|
* Computes the union of `leadingNames` from all given parsers.
|
|
@@ -173,7 +174,7 @@ function unwrapNestedAnnotationViews(value, seen = /* @__PURE__ */ new WeakMap()
|
|
|
173
174
|
return clone;
|
|
174
175
|
}
|
|
175
176
|
function unwrapCompleteResult(result) {
|
|
176
|
-
const unwrappedResult =
|
|
177
|
+
const unwrappedResult = require_internal_dependency.isDependencySourceState(result) ? result.result : result;
|
|
177
178
|
if (!unwrappedResult.success || !containsAnnotationView(unwrappedResult.value)) return unwrappedResult;
|
|
178
179
|
const value = unwrapNestedAnnotationViews(unwrappedResult.value);
|
|
179
180
|
return value === unwrappedResult.value ? unwrappedResult : {
|
|
@@ -257,8 +258,8 @@ function combineTuplePhase2Seeds(first, second) {
|
|
|
257
258
|
*/
|
|
258
259
|
function prepareStateForCompletion(fieldState, parser) {
|
|
259
260
|
if (fieldState !== void 0) return fieldState;
|
|
260
|
-
if (
|
|
261
|
-
if (
|
|
261
|
+
if (require_internal_dependency.isPendingDependencySourceState(parser.initialState)) return [parser.initialState];
|
|
262
|
+
if (require_internal_dependency.isWrappedDependencySource(parser)) return [parser[require_internal_dependency.wrappedDependencySourceMarker]];
|
|
262
263
|
return fieldState;
|
|
263
264
|
}
|
|
264
265
|
/**
|
|
@@ -281,7 +282,7 @@ function buildSuggestRuntimeNodesFromPairs(pairs, state, parentPath) {
|
|
|
281
282
|
const nodes = [];
|
|
282
283
|
for (const [field, parser] of pairs) {
|
|
283
284
|
const fieldState = Object.hasOwn(state, field) ? state[field] : parser.initialState;
|
|
284
|
-
nodes.push(...
|
|
285
|
+
nodes.push(...require_internal_parser.getParserSuggestRuntimeNodes(parser, require_annotation_state.getWrappedChildState(state, fieldState, parser), [...prefix, field]));
|
|
285
286
|
}
|
|
286
287
|
return nodes;
|
|
287
288
|
}
|
|
@@ -291,7 +292,7 @@ function buildSuggestRuntimeNodesFromArray(parsers, stateArray, parentPath) {
|
|
|
291
292
|
for (let i = 0; i < parsers.length; i++) {
|
|
292
293
|
const parser = parsers[i];
|
|
293
294
|
const elementState = i < stateArray.length ? stateArray[i] : void 0;
|
|
294
|
-
nodes.push(...
|
|
295
|
+
nodes.push(...require_internal_parser.getParserSuggestRuntimeNodes(parser, require_annotation_state.getWrappedChildState(stateArray, elementState, parser), [...prefix, i]));
|
|
295
296
|
}
|
|
296
297
|
return nodes;
|
|
297
298
|
}
|
|
@@ -301,7 +302,12 @@ function createUnexpectedInputErrorWithScopedSuggestions(baseError, invalidInput
|
|
|
301
302
|
for (const parser of parsers) require_usage_internals.collectLeadingCandidates(parser.usage, options, commands);
|
|
302
303
|
const candidates = new Set([...options, ...commands]);
|
|
303
304
|
const suggestions = require_suggestion.findSimilar(invalidInput, candidates, require_suggestion.DEFAULT_FIND_SIMILAR_OPTIONS);
|
|
304
|
-
const
|
|
305
|
+
const aliasUsage = [{
|
|
306
|
+
type: "exclusive",
|
|
307
|
+
terms: parsers.map((parser) => parser.usage)
|
|
308
|
+
}];
|
|
309
|
+
const displaySuggestions = require_suggestion.expandCommandAliasSuggestions(aliasUsage, suggestions);
|
|
310
|
+
const suggestionMsg = customFormatter ? customFormatter(displaySuggestions) : require_suggestion.createSuggestionMessage(displaySuggestions);
|
|
305
311
|
return suggestionMsg.length > 0 ? [
|
|
306
312
|
...baseError,
|
|
307
313
|
require_message.text("\n\n"),
|
|
@@ -319,6 +325,10 @@ function applyHiddenToUsageTerm(term, hidden) {
|
|
|
319
325
|
terms: applyHiddenToUsage(term.terms, hidden),
|
|
320
326
|
min: term.min
|
|
321
327
|
};
|
|
328
|
+
if (term.type === "sequence") return {
|
|
329
|
+
type: "sequence",
|
|
330
|
+
terms: applyHiddenToUsage(term.terms, hidden)
|
|
331
|
+
};
|
|
322
332
|
if (term.type === "exclusive") return {
|
|
323
333
|
type: "exclusive",
|
|
324
334
|
terms: term.terms.map((u) => applyHiddenToUsage(u, hidden))
|
|
@@ -374,7 +384,7 @@ function isOptionRequiringValue(usage, token) {
|
|
|
374
384
|
if (!terms || !Array.isArray(terms)) return false;
|
|
375
385
|
for (const term of terms) if (term.type === "option") {
|
|
376
386
|
if (term.metavar && term.names.includes(token)) return true;
|
|
377
|
-
} else if (term.type === "optional" || term.type === "multiple") {
|
|
387
|
+
} else if (term.type === "optional" || term.type === "multiple" || term.type === "sequence") {
|
|
378
388
|
if (traverse(term.terms)) return true;
|
|
379
389
|
} else if (term.type === "exclusive") {
|
|
380
390
|
for (const exclusiveUsage of term.terms) if (traverse(exclusiveUsage)) return true;
|
|
@@ -453,6 +463,18 @@ var DuplicateOptionError = class extends Error {
|
|
|
453
463
|
}
|
|
454
464
|
};
|
|
455
465
|
/**
|
|
466
|
+
* Error class thrown when duplicate command names or aliases are detected
|
|
467
|
+
* during parser construction. This is a programmer error, not a user error.
|
|
468
|
+
*/
|
|
469
|
+
var DuplicateCommandNameError = class extends TypeError {
|
|
470
|
+
constructor(commandName, sources) {
|
|
471
|
+
const sourceNames = sources.map((s) => typeof s === "symbol" ? s.description ?? s.toString() : s);
|
|
472
|
+
super(`Duplicate command name "${commandName}" found in parsers: ${sourceNames.join(", ")}. Each command name or alias must be unique within active parser alternatives.`);
|
|
473
|
+
this.commandName = commandName;
|
|
474
|
+
this.sources = sources;
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
/**
|
|
456
478
|
* Checks for duplicate option names across parser sources and throws an error
|
|
457
479
|
* if duplicates are found. This should be called at construction time.
|
|
458
480
|
* @param parserSources Array of [source, usage] tuples
|
|
@@ -469,6 +491,48 @@ function checkDuplicateOptionNames(parserSources) {
|
|
|
469
491
|
}
|
|
470
492
|
for (const [name, sources] of optionNameSources) if (sources.length > 1) throw new DuplicateOptionError(name, sources);
|
|
471
493
|
}
|
|
494
|
+
function checkDuplicateLeadingCommandNames(parserSources) {
|
|
495
|
+
const commandNameSources = /* @__PURE__ */ new Map();
|
|
496
|
+
for (const [source, parser] of parserSources) {
|
|
497
|
+
const commandNames = require_usage.extractCommandNames(parser.usage, true);
|
|
498
|
+
for (const name of parser.leadingNames) {
|
|
499
|
+
if (!commandNames.has(name)) continue;
|
|
500
|
+
const sources = commandNameSources.get(name);
|
|
501
|
+
commandNameSources.set(name, sources == null ? [source] : [...sources, source]);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
for (const [name, sources] of commandNameSources) if (sources.length > 1) throw new DuplicateCommandNameError(name, sources);
|
|
505
|
+
}
|
|
506
|
+
function checkDuplicateReachableLeadingCommandNames(parserSources) {
|
|
507
|
+
const commandNameSources = /* @__PURE__ */ new Map();
|
|
508
|
+
const sortedSources = [...parserSources].sort(([, parserA], [, parserB]) => parserB.priority - parserA.priority);
|
|
509
|
+
const blockedNames = /* @__PURE__ */ new Set();
|
|
510
|
+
let positionalBlocked = false;
|
|
511
|
+
for (let i = 0; i < sortedSources.length;) {
|
|
512
|
+
const priority = sortedSources[i][1].priority;
|
|
513
|
+
const priorityGroup = [];
|
|
514
|
+
while (i < sortedSources.length && sortedSources[i][1].priority === priority) {
|
|
515
|
+
priorityGroup.push(sortedSources[i]);
|
|
516
|
+
i++;
|
|
517
|
+
}
|
|
518
|
+
const groupNames = /* @__PURE__ */ new Set();
|
|
519
|
+
let groupAcceptsAnyToken = false;
|
|
520
|
+
for (const [source, parser] of priorityGroup) {
|
|
521
|
+
if (parser.acceptingAnyToken) groupAcceptsAnyToken = true;
|
|
522
|
+
const commandNames = require_usage.extractCommandNames(parser.usage, true);
|
|
523
|
+
for (const name of parser.leadingNames) {
|
|
524
|
+
if (!commandNames.has(name)) continue;
|
|
525
|
+
if (positionalBlocked || blockedNames.has(name)) continue;
|
|
526
|
+
groupNames.add(name);
|
|
527
|
+
const sources = commandNameSources.get(name);
|
|
528
|
+
commandNameSources.set(name, sources == null ? [source] : [...sources, source]);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
for (const name of groupNames) blockedNames.add(name);
|
|
532
|
+
if (groupAcceptsAnyToken) positionalBlocked = true;
|
|
533
|
+
}
|
|
534
|
+
for (const [name, sources] of commandNameSources) if (sources.length > 1) throw new DuplicateCommandNameError(name, sources);
|
|
535
|
+
}
|
|
472
536
|
/**
|
|
473
537
|
* Extracts option names that participate in CLI syntax.
|
|
474
538
|
*
|
|
@@ -514,7 +578,7 @@ function annotateExclusiveParserResult(parentState, parser, result) {
|
|
|
514
578
|
}
|
|
515
579
|
function createExclusiveState(parentState, index, parser, result) {
|
|
516
580
|
const annotatedResult = annotateExclusiveParserResult(parentState, parser, result);
|
|
517
|
-
return
|
|
581
|
+
return require_internal_annotations.annotateFreshArray(parentState, [index, annotatedResult]);
|
|
518
582
|
}
|
|
519
583
|
/**
|
|
520
584
|
* Creates a complete() method shared by or() and longestMatch().
|
|
@@ -610,7 +674,7 @@ function getExclusiveSuggestRuntimeNodes(parsers, state, path) {
|
|
|
610
674
|
const [index, parserResult] = activeState;
|
|
611
675
|
if (!parserResult?.success || index < 0 || index >= parsers.length) return [];
|
|
612
676
|
const parser = parsers[index];
|
|
613
|
-
return
|
|
677
|
+
return require_internal_parser.getParserSuggestRuntimeNodes(parser, parserResult.next.state, [...path, index]);
|
|
614
678
|
}
|
|
615
679
|
function findExclusiveZeroInputCandidateSync(parsers, state, exec) {
|
|
616
680
|
const emptyCtx = {
|
|
@@ -733,6 +797,7 @@ function or(...args) {
|
|
|
733
797
|
}
|
|
734
798
|
if (parsers.length < 1) throw new TypeError("or() requires at least one parser argument.");
|
|
735
799
|
assertParsers(parsers, "or()");
|
|
800
|
+
checkDuplicateLeadingCommandNames(parsers.map((parser, index) => [String(index), parser]));
|
|
736
801
|
const noMatchContext = analyzeNoMatchContext(parsers);
|
|
737
802
|
const combinedMode = parsers.some((p) => p.mode === "async") ? "async" : "sync";
|
|
738
803
|
const syncParsers = parsers;
|
|
@@ -1152,6 +1217,15 @@ function or(...args) {
|
|
|
1152
1217
|
leadingNames: unionLeadingNames(parsers),
|
|
1153
1218
|
acceptingAnyToken: parsers.some((p) => p.acceptingAnyToken),
|
|
1154
1219
|
initialState: void 0,
|
|
1220
|
+
canSkip(state, exec) {
|
|
1221
|
+
const activeState = normalizeExclusiveState(state);
|
|
1222
|
+
if (activeState != null) {
|
|
1223
|
+
const [index, result] = activeState;
|
|
1224
|
+
const parser = parsers[index];
|
|
1225
|
+
return result.success && parser?.canSkip?.(result.next.state, exec) === true;
|
|
1226
|
+
}
|
|
1227
|
+
return parsers.some((parser) => parser.canSkip?.(parser.initialState, exec) === true);
|
|
1228
|
+
},
|
|
1155
1229
|
complete: createExclusiveComplete(parsers, options, noMatchContext, combinedMode),
|
|
1156
1230
|
[require_phase2_seed.extractPhase2SeedKey](state, exec) {
|
|
1157
1231
|
return extractExclusivePhase2Seed(parsers, state, exec, combinedMode);
|
|
@@ -1192,13 +1266,16 @@ function or(...args) {
|
|
|
1192
1266
|
};
|
|
1193
1267
|
const singleDependencyMetadata = composeExclusiveDependencyMetadata(parsers);
|
|
1194
1268
|
if (singleDependencyMetadata != null) singleResult.dependencyMetadata = singleDependencyMetadata;
|
|
1195
|
-
|
|
1269
|
+
require_internal_parser.defineInheritedAnnotationParser(singleResult);
|
|
1196
1270
|
return singleResult;
|
|
1197
1271
|
}
|
|
1198
1272
|
/**
|
|
1199
1273
|
* @since 0.5.0
|
|
1200
1274
|
*/
|
|
1201
1275
|
function longestMatch(...args) {
|
|
1276
|
+
return createLongestMatch(...args);
|
|
1277
|
+
}
|
|
1278
|
+
function createLongestMatch(...args) {
|
|
1202
1279
|
let parsers;
|
|
1203
1280
|
let options;
|
|
1204
1281
|
if (args.length > 0 && args[args.length - 1] && typeof args[args.length - 1] === "object" && !("$valueType" in args[args.length - 1])) {
|
|
@@ -1210,6 +1287,8 @@ function longestMatch(...args) {
|
|
|
1210
1287
|
}
|
|
1211
1288
|
if (parsers.length < 1) throw new TypeError("longestMatch() requires at least one parser argument.");
|
|
1212
1289
|
assertParsers(parsers, "longestMatch()");
|
|
1290
|
+
const allowDuplicateLeadingCommandNames = options?.[require_command_alias.allowDuplicateLeadingCommandNamesKey] === true;
|
|
1291
|
+
if (!allowDuplicateLeadingCommandNames) checkDuplicateLeadingCommandNames(parsers.map((parser, index) => [String(index), parser]));
|
|
1213
1292
|
const noMatchContext = analyzeNoMatchContext(parsers);
|
|
1214
1293
|
const combinedMode = parsers.some((p) => p.mode === "async") ? "async" : "sync";
|
|
1215
1294
|
const syncParsers = parsers;
|
|
@@ -1362,7 +1441,7 @@ function longestMatch(...args) {
|
|
|
1362
1441
|
};
|
|
1363
1442
|
const multiDependencyMetadata = composeExclusiveDependencyMetadata(parsers);
|
|
1364
1443
|
if (multiDependencyMetadata != null) multiResult.dependencyMetadata = multiDependencyMetadata;
|
|
1365
|
-
|
|
1444
|
+
require_internal_parser.defineInheritedAnnotationParser(multiResult);
|
|
1366
1445
|
return multiResult;
|
|
1367
1446
|
}
|
|
1368
1447
|
/**
|
|
@@ -1445,7 +1524,7 @@ async function* suggestObjectAsync(context, prefix, parserPairs) {
|
|
|
1445
1524
|
* @internal
|
|
1446
1525
|
*/
|
|
1447
1526
|
function registerCompletedDependency(completed, registry) {
|
|
1448
|
-
if (
|
|
1527
|
+
if (require_internal_dependency.isDependencySourceState(completed) && completed.result.success && !registry.has(completed[require_internal_dependency.dependencyId])) registry.set(completed[require_internal_dependency.dependencyId], completed.result.value);
|
|
1449
1528
|
}
|
|
1450
1529
|
/**
|
|
1451
1530
|
* Yields `(parser, state)` pairs for dependency source parsers whose field
|
|
@@ -1456,7 +1535,7 @@ function registerCompletedDependency(completed, registry) {
|
|
|
1456
1535
|
*/
|
|
1457
1536
|
function* pendingDependencyDefaults(context, parserPairs, registry) {
|
|
1458
1537
|
for (const [field, fieldParser] of parserPairs) {
|
|
1459
|
-
const sourceId = fieldParser.dependencyMetadata?.source?.sourceId ?? (
|
|
1538
|
+
const sourceId = fieldParser.dependencyMetadata?.source?.sourceId ?? (require_internal_dependency.isWrappedDependencySource(fieldParser) ? fieldParser[require_internal_dependency.wrappedDependencySourceMarker][require_internal_dependency.dependencyId] : require_internal_dependency.isPendingDependencySourceState(fieldParser.initialState) ? fieldParser.initialState[require_internal_dependency.dependencyId] : void 0);
|
|
1460
1539
|
if (sourceId != null && registry?.has(sourceId)) continue;
|
|
1461
1540
|
const fieldState = context.state != null && typeof context.state === "object" && field in context.state ? context.state[field] : void 0;
|
|
1462
1541
|
const annotatedFieldState = getAnnotatedFieldState(context.state, field, fieldParser);
|
|
@@ -1475,19 +1554,19 @@ function* pendingDependencyDefaults(context, parserPairs, registry) {
|
|
|
1475
1554
|
continue;
|
|
1476
1555
|
}
|
|
1477
1556
|
if (fieldState != null) {
|
|
1478
|
-
if (!Array.isArray(fieldState) && !
|
|
1557
|
+
if (!Array.isArray(fieldState) && !require_internal_dependency.isDependencySourceState(fieldState) && (require_internal_dependency.isWrappedDependencySource(fieldParser) || require_internal_dependency.isPendingDependencySourceState(fieldParser.initialState))) yield {
|
|
1479
1558
|
parser: fieldParser,
|
|
1480
1559
|
state: getAnnotatedFieldState(context.state, field, fieldParser)
|
|
1481
1560
|
};
|
|
1482
1561
|
continue;
|
|
1483
1562
|
}
|
|
1484
|
-
if (
|
|
1563
|
+
if (require_internal_dependency.isPendingDependencySourceState(fieldParser.initialState)) yield {
|
|
1485
1564
|
parser: fieldParser,
|
|
1486
1565
|
state: fieldParser.initialState
|
|
1487
1566
|
};
|
|
1488
|
-
else if (
|
|
1567
|
+
else if (require_internal_dependency.isWrappedDependencySource(fieldParser)) yield {
|
|
1489
1568
|
parser: fieldParser,
|
|
1490
|
-
state: [fieldParser[
|
|
1569
|
+
state: [fieldParser[require_internal_dependency.wrappedDependencySourceMarker]]
|
|
1491
1570
|
};
|
|
1492
1571
|
}
|
|
1493
1572
|
}
|
|
@@ -1519,13 +1598,13 @@ function completeDependencySourceDefaults(context, parserPairs, registry, exec)
|
|
|
1519
1598
|
* @internal
|
|
1520
1599
|
*/
|
|
1521
1600
|
function wrapAsDependencySourceState(completed, parser) {
|
|
1522
|
-
if (
|
|
1601
|
+
if (require_internal_dependency.isDependencySourceState(completed)) return completed;
|
|
1523
1602
|
const metadataSource = parser.dependencyMetadata?.source;
|
|
1524
1603
|
if (metadataSource?.preservesSourceValue === false) return void 0;
|
|
1525
|
-
const hasDep = metadataSource != null ||
|
|
1604
|
+
const hasDep = metadataSource != null || require_internal_dependency.isWrappedDependencySource(parser) || require_internal_dependency.isPendingDependencySourceState(parser.initialState);
|
|
1526
1605
|
if (hasDep && typeof completed === "object" && completed !== null && "success" in completed && completed.success && "value" in completed && completed.value !== void 0) {
|
|
1527
|
-
const depId = metadataSource?.sourceId ?? (
|
|
1528
|
-
return
|
|
1606
|
+
const depId = metadataSource?.sourceId ?? (require_internal_dependency.isWrappedDependencySource(parser) ? parser[require_internal_dependency.wrappedDependencySourceMarker][require_internal_dependency.dependencyId] : parser.initialState[require_internal_dependency.dependencyId]);
|
|
1607
|
+
return require_internal_dependency.createDependencySourceState(completed, depId);
|
|
1529
1608
|
}
|
|
1530
1609
|
return void 0;
|
|
1531
1610
|
}
|
|
@@ -1635,20 +1714,20 @@ function preCompleteAndRegisterDependencies(state, fieldParserPairs, registry, e
|
|
|
1635
1714
|
if (depState) registerCompletedDependency(depState, registry);
|
|
1636
1715
|
continue;
|
|
1637
1716
|
}
|
|
1638
|
-
if (Array.isArray(fieldState) && fieldState.length === 1 &&
|
|
1717
|
+
if (Array.isArray(fieldState) && fieldState.length === 1 && require_internal_dependency.isPendingDependencySourceState(fieldState[0])) {
|
|
1639
1718
|
const completed = fieldParser.complete(fieldState, require_execution_context.withChildExecPath(exec, field));
|
|
1640
1719
|
preCompleted.set(field, completed);
|
|
1641
|
-
if (
|
|
1642
|
-
} else if (fieldState === void 0 &&
|
|
1720
|
+
if (require_internal_dependency.isDependencySourceState(completed)) registerCompletedDependency(completed, registry);
|
|
1721
|
+
} else if (fieldState === void 0 && require_internal_dependency.isPendingDependencySourceState(fieldParser.initialState)) {
|
|
1643
1722
|
const completed = fieldParser.complete([fieldParser.initialState], require_execution_context.withChildExecPath(exec, field));
|
|
1644
1723
|
preCompleted.set(field, completed);
|
|
1645
|
-
if (
|
|
1646
|
-
} else if (fieldState === void 0 &&
|
|
1647
|
-
const pendingState = fieldParser[
|
|
1724
|
+
if (require_internal_dependency.isDependencySourceState(completed)) registerCompletedDependency(completed, registry);
|
|
1725
|
+
} else if (fieldState === void 0 && require_internal_dependency.isWrappedDependencySource(fieldParser)) {
|
|
1726
|
+
const pendingState = fieldParser[require_internal_dependency.wrappedDependencySourceMarker];
|
|
1648
1727
|
const completed = fieldParser.complete([pendingState], require_execution_context.withChildExecPath(exec, field));
|
|
1649
1728
|
preCompleted.set(field, completed);
|
|
1650
|
-
if (
|
|
1651
|
-
} else if (fieldState != null && !Array.isArray(fieldState) && !
|
|
1729
|
+
if (require_internal_dependency.isDependencySourceState(completed)) registerCompletedDependency(completed, registry);
|
|
1730
|
+
} else if (fieldState != null && !Array.isArray(fieldState) && !require_internal_dependency.isDependencySourceState(fieldState) && (require_internal_dependency.isWrappedDependencySource(fieldParser) || require_internal_dependency.isPendingDependencySourceState(fieldParser.initialState))) {
|
|
1652
1731
|
const annotatedFieldState$1 = getAnnotatedFieldState(state, field, fieldParser);
|
|
1653
1732
|
const completed = fieldParser.complete(annotatedFieldState$1, require_execution_context.withChildExecPath(exec, field));
|
|
1654
1733
|
preCompleted.set(field, completed);
|
|
@@ -1688,20 +1767,20 @@ async function preCompleteAndRegisterDependenciesAsync(state, fieldParserPairs,
|
|
|
1688
1767
|
if (depState) registerCompletedDependency(depState, registry);
|
|
1689
1768
|
continue;
|
|
1690
1769
|
}
|
|
1691
|
-
if (Array.isArray(fieldState) && fieldState.length === 1 &&
|
|
1770
|
+
if (Array.isArray(fieldState) && fieldState.length === 1 && require_internal_dependency.isPendingDependencySourceState(fieldState[0])) {
|
|
1692
1771
|
const completed = await fieldParser.complete(fieldState, require_execution_context.withChildExecPath(exec, field));
|
|
1693
1772
|
preCompleted.set(field, completed);
|
|
1694
|
-
if (
|
|
1695
|
-
} else if (fieldState === void 0 &&
|
|
1773
|
+
if (require_internal_dependency.isDependencySourceState(completed)) registerCompletedDependency(completed, registry);
|
|
1774
|
+
} else if (fieldState === void 0 && require_internal_dependency.isPendingDependencySourceState(fieldParser.initialState)) {
|
|
1696
1775
|
const completed = await fieldParser.complete([fieldParser.initialState], require_execution_context.withChildExecPath(exec, field));
|
|
1697
1776
|
preCompleted.set(field, completed);
|
|
1698
|
-
if (
|
|
1699
|
-
} else if (fieldState === void 0 &&
|
|
1700
|
-
const pendingState = fieldParser[
|
|
1777
|
+
if (require_internal_dependency.isDependencySourceState(completed)) registerCompletedDependency(completed, registry);
|
|
1778
|
+
} else if (fieldState === void 0 && require_internal_dependency.isWrappedDependencySource(fieldParser)) {
|
|
1779
|
+
const pendingState = fieldParser[require_internal_dependency.wrappedDependencySourceMarker];
|
|
1701
1780
|
const completed = await fieldParser.complete([pendingState], require_execution_context.withChildExecPath(exec, field));
|
|
1702
1781
|
preCompleted.set(field, completed);
|
|
1703
|
-
if (
|
|
1704
|
-
} else if (fieldState != null && !Array.isArray(fieldState) && !
|
|
1782
|
+
if (require_internal_dependency.isDependencySourceState(completed)) registerCompletedDependency(completed, registry);
|
|
1783
|
+
} else if (fieldState != null && !Array.isArray(fieldState) && !require_internal_dependency.isDependencySourceState(fieldState) && (require_internal_dependency.isWrappedDependencySource(fieldParser) || require_internal_dependency.isPendingDependencySourceState(fieldParser.initialState))) {
|
|
1705
1784
|
const annotatedFieldState$1 = getAnnotatedFieldState(state, field, fieldParser);
|
|
1706
1785
|
const completed = await fieldParser.complete(annotatedFieldState$1, require_execution_context.withChildExecPath(exec, field));
|
|
1707
1786
|
preCompleted.set(field, completed);
|
|
@@ -1755,6 +1834,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
1755
1834
|
};
|
|
1756
1835
|
};
|
|
1757
1836
|
if (!options.allowDuplicates) checkDuplicateOptionNames(parserPairs.map(([field, parser]) => [field, parser.usage]));
|
|
1837
|
+
checkDuplicateReachableLeadingCommandNames(parserPairs.map(([field, parser]) => [field, parser]));
|
|
1758
1838
|
const noMatchContext = analyzeNoMatchContext(parserKeys.map((k) => parsers[k]));
|
|
1759
1839
|
const combinedMode = parserKeys.some((k) => parsers[k].mode === "async") ? "async" : "sync";
|
|
1760
1840
|
const getInitialError = (context) => ({
|
|
@@ -1992,6 +2072,13 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
1992
2072
|
usage: applyHiddenToUsage(parserPairs.flatMap(([_, p]) => p.usage), options.hidden),
|
|
1993
2073
|
leadingNames: sharedBufferLeadingNames(parserPairs.map(([_, p]) => p)),
|
|
1994
2074
|
acceptingAnyToken: parserPairs.some(([_, p]) => p.acceptingAnyToken),
|
|
2075
|
+
canSkip(state, exec) {
|
|
2076
|
+
const getFieldState = createFieldStateGetter(state);
|
|
2077
|
+
return parserKeys.every((field) => {
|
|
2078
|
+
const parser = parsers[field];
|
|
2079
|
+
return parser.canSkip?.(getFieldState(field, parser), require_execution_context.withChildExecPath(exec, field)) === true;
|
|
2080
|
+
});
|
|
2081
|
+
},
|
|
1995
2082
|
get initialState() {
|
|
1996
2083
|
return createInitialState();
|
|
1997
2084
|
},
|
|
@@ -2281,9 +2368,372 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
2281
2368
|
configurable: true,
|
|
2282
2369
|
enumerable: false
|
|
2283
2370
|
});
|
|
2284
|
-
|
|
2371
|
+
require_internal_parser.defineInheritedAnnotationParser(objectParser);
|
|
2285
2372
|
return objectParser;
|
|
2286
2373
|
}
|
|
2374
|
+
function isParserLike(value) {
|
|
2375
|
+
return value != null && (typeof value === "object" || typeof value === "function") && "parse" in value && "$valueType" in value && "$stateType" in value;
|
|
2376
|
+
}
|
|
2377
|
+
function tokenMatchesLeadingName(token, candidates) {
|
|
2378
|
+
if (token == null) return false;
|
|
2379
|
+
for (const name of candidates.optionNames) if (token === name) return true;
|
|
2380
|
+
for (const name of candidates.joinedOptionNames) if (name.startsWith("/") && token.startsWith(`${name}:`) || (name.startsWith("--") || name.startsWith("-") && name.length > 2) && token.startsWith(`${name}=`)) return true;
|
|
2381
|
+
for (const name of candidates.commandNames) if (token === name) return true;
|
|
2382
|
+
return false;
|
|
2383
|
+
}
|
|
2384
|
+
function parserCanSkipAt(parser, state, exec, index) {
|
|
2385
|
+
return parser.canSkip?.(require_annotation_state.getWrappedChildState(void 0, state, parser), require_execution_context.withChildExecPath(exec, index)) === true;
|
|
2386
|
+
}
|
|
2387
|
+
function collectLeadingJoinedOptionNames(terms, optionNames) {
|
|
2388
|
+
for (const term of terms) {
|
|
2389
|
+
if (term.type === "option") {
|
|
2390
|
+
if (term.metavar != null) for (const name of term.names) optionNames.add(name);
|
|
2391
|
+
return false;
|
|
2392
|
+
}
|
|
2393
|
+
if (term.type === "command" || term.type === "argument") return false;
|
|
2394
|
+
if (term.type === "optional") {
|
|
2395
|
+
collectLeadingJoinedOptionNames(term.terms, optionNames);
|
|
2396
|
+
continue;
|
|
2397
|
+
}
|
|
2398
|
+
if (term.type === "multiple") {
|
|
2399
|
+
collectLeadingJoinedOptionNames(term.terms, optionNames);
|
|
2400
|
+
if (term.min === 0) continue;
|
|
2401
|
+
return false;
|
|
2402
|
+
}
|
|
2403
|
+
if (term.type === "sequence") {
|
|
2404
|
+
if (collectLeadingJoinedOptionNames(term.terms, optionNames)) continue;
|
|
2405
|
+
return false;
|
|
2406
|
+
}
|
|
2407
|
+
if (term.type === "exclusive") {
|
|
2408
|
+
let allSkippable = true;
|
|
2409
|
+
for (const branch of term.terms) {
|
|
2410
|
+
const branchSkippable = collectLeadingJoinedOptionNames(branch, optionNames);
|
|
2411
|
+
allSkippable = allSkippable && branchSkippable;
|
|
2412
|
+
}
|
|
2413
|
+
if (allSkippable) continue;
|
|
2414
|
+
return false;
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
return true;
|
|
2418
|
+
}
|
|
2419
|
+
function sequenceLeadingCandidates(parsers) {
|
|
2420
|
+
const optionNames = /* @__PURE__ */ new Set();
|
|
2421
|
+
const joinedOptionNames = /* @__PURE__ */ new Set();
|
|
2422
|
+
const commandNames = /* @__PURE__ */ new Set();
|
|
2423
|
+
let positionalBlocked = false;
|
|
2424
|
+
for (let i = 0; i < parsers.length; i++) {
|
|
2425
|
+
const parser = parsers[i];
|
|
2426
|
+
const parserOptions = /* @__PURE__ */ new Set();
|
|
2427
|
+
const parserJoinedOptions = /* @__PURE__ */ new Set();
|
|
2428
|
+
const parserCommands = /* @__PURE__ */ new Set();
|
|
2429
|
+
require_usage_internals.collectLeadingCandidates(parser.usage, parserOptions, parserCommands);
|
|
2430
|
+
collectLeadingJoinedOptionNames(parser.usage, parserJoinedOptions);
|
|
2431
|
+
for (const name of parserOptions) optionNames.add(name);
|
|
2432
|
+
for (const name of parserJoinedOptions) joinedOptionNames.add(name);
|
|
2433
|
+
if (!positionalBlocked) {
|
|
2434
|
+
for (const name of parserCommands) commandNames.add(name);
|
|
2435
|
+
for (const name of parser.leadingNames) if (!parserOptions.has(name)) commandNames.add(name);
|
|
2436
|
+
} else for (const name of parser.leadingNames) if (!parserOptions.has(name) && name.startsWith("-")) commandNames.add(name);
|
|
2437
|
+
if (parser.acceptingAnyToken) positionalBlocked = true;
|
|
2438
|
+
if (!parserCanSkipAt(parser, parser.initialState, void 0, i)) break;
|
|
2439
|
+
}
|
|
2440
|
+
return {
|
|
2441
|
+
optionNames: optionNames.size === 0 ? EMPTY_LEADING_NAMES : optionNames,
|
|
2442
|
+
joinedOptionNames: joinedOptionNames.size === 0 ? EMPTY_LEADING_NAMES : joinedOptionNames,
|
|
2443
|
+
commandNames: commandNames.size === 0 ? EMPTY_LEADING_NAMES : commandNames
|
|
2444
|
+
};
|
|
2445
|
+
}
|
|
2446
|
+
function sequenceLeadingNames(parsers) {
|
|
2447
|
+
const candidates = sequenceLeadingCandidates(parsers);
|
|
2448
|
+
const names = new Set([
|
|
2449
|
+
...candidates.optionNames,
|
|
2450
|
+
...candidates.joinedOptionNames,
|
|
2451
|
+
...candidates.commandNames
|
|
2452
|
+
]);
|
|
2453
|
+
return names.size === 0 ? EMPTY_LEADING_NAMES : names;
|
|
2454
|
+
}
|
|
2455
|
+
function sequenceAcceptingAnyToken(parsers) {
|
|
2456
|
+
for (let i = 0; i < parsers.length; i++) {
|
|
2457
|
+
const parser = parsers[i];
|
|
2458
|
+
if (parser.acceptingAnyToken) return true;
|
|
2459
|
+
if (!parserCanSkipAt(parser, parser.initialState, void 0, i)) break;
|
|
2460
|
+
}
|
|
2461
|
+
return false;
|
|
2462
|
+
}
|
|
2463
|
+
function sequencePriority(parsers) {
|
|
2464
|
+
let priority = 0;
|
|
2465
|
+
for (let i = 0; i < parsers.length; i++) {
|
|
2466
|
+
const parser = parsers[i];
|
|
2467
|
+
priority = Math.max(priority, parser.priority);
|
|
2468
|
+
if (!parserCanSkipAt(parser, parser.initialState, void 0, i)) break;
|
|
2469
|
+
}
|
|
2470
|
+
return priority;
|
|
2471
|
+
}
|
|
2472
|
+
function leadingCandidatesAfter(parsers, startIndex) {
|
|
2473
|
+
return sequenceLeadingCandidates(parsers.slice(startIndex));
|
|
2474
|
+
}
|
|
2475
|
+
function checkSequentialDuplicateOptionNames(parsers) {
|
|
2476
|
+
const active = /* @__PURE__ */ new Map();
|
|
2477
|
+
for (let i = 0; i < parsers.length; i++) {
|
|
2478
|
+
const parser = parsers[i];
|
|
2479
|
+
const optionNames = /* @__PURE__ */ new Set();
|
|
2480
|
+
require_usage_internals.collectLeadingCandidates(parser.usage, optionNames, /* @__PURE__ */ new Set(), true);
|
|
2481
|
+
const retainedOptionNames = collectRetainedLeadingCandidates(parser.usage).optionNames;
|
|
2482
|
+
for (const name of optionNames) {
|
|
2483
|
+
const sources = active.get(name);
|
|
2484
|
+
if (sources != null) throw new DuplicateOptionError(name, [...sources, String(i)]);
|
|
2485
|
+
}
|
|
2486
|
+
for (const name of optionNames) {
|
|
2487
|
+
const sources = active.get(name);
|
|
2488
|
+
active.set(name, sources == null ? [String(i)] : [...sources, String(i)]);
|
|
2489
|
+
}
|
|
2490
|
+
if (!parserCanSkipAt(parser, parser.initialState, void 0, i)) active.clear();
|
|
2491
|
+
for (const name of retainedOptionNames) {
|
|
2492
|
+
const sources = active.get(name);
|
|
2493
|
+
active.set(name, sources == null ? [String(i)] : [...sources, String(i)]);
|
|
2494
|
+
}
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
function collectRetainedLeadingCandidates(terms) {
|
|
2498
|
+
const optionNames = /* @__PURE__ */ new Set();
|
|
2499
|
+
const joinedOptionNames = /* @__PURE__ */ new Set();
|
|
2500
|
+
collectRetainedLeadingCandidatesInto(terms, optionNames, joinedOptionNames);
|
|
2501
|
+
return {
|
|
2502
|
+
optionNames,
|
|
2503
|
+
joinedOptionNames,
|
|
2504
|
+
commandNames: EMPTY_LEADING_NAMES
|
|
2505
|
+
};
|
|
2506
|
+
}
|
|
2507
|
+
function collectRetainedLeadingCandidatesInto(terms, optionNames, joinedOptionNames) {
|
|
2508
|
+
for (const term of terms) {
|
|
2509
|
+
if (term.type === "optional") {
|
|
2510
|
+
collectLeadingOptionCandidates(term.terms, optionNames, joinedOptionNames);
|
|
2511
|
+
collectRetainedLeadingCandidatesInto(term.terms, optionNames, joinedOptionNames);
|
|
2512
|
+
continue;
|
|
2513
|
+
}
|
|
2514
|
+
if (term.type === "multiple") {
|
|
2515
|
+
collectLeadingOptionCandidates(term.terms, optionNames, joinedOptionNames);
|
|
2516
|
+
collectRetainedLeadingCandidatesInto(term.terms, optionNames, joinedOptionNames);
|
|
2517
|
+
continue;
|
|
2518
|
+
}
|
|
2519
|
+
if (term.type === "sequence") {
|
|
2520
|
+
collectRetainedLeadingCandidatesInto(term.terms, optionNames, joinedOptionNames);
|
|
2521
|
+
continue;
|
|
2522
|
+
}
|
|
2523
|
+
if (term.type === "exclusive") {
|
|
2524
|
+
let canSkipBranch = false;
|
|
2525
|
+
const branchOptionNames = [];
|
|
2526
|
+
const branchJoinedOptionNames = [];
|
|
2527
|
+
for (const branch of term.terms) {
|
|
2528
|
+
const branchOptions = /* @__PURE__ */ new Set();
|
|
2529
|
+
const branchJoinedOptions = /* @__PURE__ */ new Set();
|
|
2530
|
+
const branchCanSkip = require_usage_internals.collectLeadingCandidates(branch, branchOptions, /* @__PURE__ */ new Set(), true);
|
|
2531
|
+
collectLeadingJoinedOptionNames(branch, branchJoinedOptions);
|
|
2532
|
+
canSkipBranch = canSkipBranch || branchCanSkip;
|
|
2533
|
+
branchOptionNames.push(branchOptions);
|
|
2534
|
+
branchJoinedOptionNames.push(branchJoinedOptions);
|
|
2535
|
+
collectRetainedLeadingCandidatesInto(branch, optionNames, joinedOptionNames);
|
|
2536
|
+
}
|
|
2537
|
+
if (canSkipBranch) {
|
|
2538
|
+
for (const branchOptions of branchOptionNames) for (const name of branchOptions) optionNames.add(name);
|
|
2539
|
+
for (const branchJoinedOptions of branchJoinedOptionNames) for (const name of branchJoinedOptions) joinedOptionNames.add(name);
|
|
2540
|
+
}
|
|
2541
|
+
}
|
|
2542
|
+
}
|
|
2543
|
+
}
|
|
2544
|
+
function collectLeadingOptionCandidates(terms, optionNames, joinedOptionNames) {
|
|
2545
|
+
require_usage_internals.collectLeadingCandidates(terms, optionNames, /* @__PURE__ */ new Set(), true);
|
|
2546
|
+
collectLeadingJoinedOptionNames(terms, joinedOptionNames);
|
|
2547
|
+
}
|
|
2548
|
+
function collectRetainedLeadingCandidatesAtState(terms, state) {
|
|
2549
|
+
if (terms.length === 1 && terms[0].type === "optional" && Array.isArray(state)) return collectRetainedLeadingCandidates(terms[0].terms);
|
|
2550
|
+
return collectRetainedLeadingCandidates(terms);
|
|
2551
|
+
}
|
|
2552
|
+
function createSeqState(sourceState, index, states) {
|
|
2553
|
+
const seqState = {
|
|
2554
|
+
index,
|
|
2555
|
+
states: require_internal_annotations.annotateFreshArray(sourceState, states)
|
|
2556
|
+
};
|
|
2557
|
+
return require_internal_annotations.inheritAnnotations(sourceState, seqState);
|
|
2558
|
+
}
|
|
2559
|
+
function getSeqChildState(seqState, index, parser) {
|
|
2560
|
+
return require_annotation_state.getWrappedChildState(seqState, seqState.states[index], parser);
|
|
2561
|
+
}
|
|
2562
|
+
function updateSeqChildState(sourceState, index, childState, parser) {
|
|
2563
|
+
return require_internal_annotations.annotateFreshArray(sourceState.states, sourceState.states.map((state, stateIndex) => stateIndex === index ? require_annotation_state.getWrappedChildState(sourceState.states, childState, parser) : state));
|
|
2564
|
+
}
|
|
2565
|
+
function shouldAdvanceSeqBeforeParse(parser, parserState, initialParserState, currentContext, index, parsers) {
|
|
2566
|
+
const token = currentContext.buffer[0];
|
|
2567
|
+
if (token !== "--") {
|
|
2568
|
+
const laterLeadingCandidates = leadingCandidatesAfter(parsers, index + 1);
|
|
2569
|
+
if (!tokenMatchesLeadingName(token, laterLeadingCandidates)) return false;
|
|
2570
|
+
}
|
|
2571
|
+
if (!parserCanSkipAt(parser, parserState, currentContext.exec, index)) return false;
|
|
2572
|
+
if (token === "--") return true;
|
|
2573
|
+
if (currentContext.state.states[index] === initialParserState) {
|
|
2574
|
+
const currentLeadingCandidates = sequenceLeadingCandidates([parser]);
|
|
2575
|
+
return !tokenMatchesLeadingName(token, currentLeadingCandidates);
|
|
2576
|
+
}
|
|
2577
|
+
return !tokenMatchesLeadingName(token, collectRetainedLeadingCandidatesAtState(parser.usage, currentContext.state.states[index]));
|
|
2578
|
+
}
|
|
2579
|
+
function advanceSeqContext(currentContext, nextIndex, consumedTerminator) {
|
|
2580
|
+
return {
|
|
2581
|
+
...currentContext,
|
|
2582
|
+
buffer: consumedTerminator ? currentContext.buffer.slice(1) : currentContext.buffer,
|
|
2583
|
+
optionsTerminated: consumedTerminator ? true : currentContext.optionsTerminated,
|
|
2584
|
+
state: createSeqState(currentContext.state, nextIndex, currentContext.state.states)
|
|
2585
|
+
};
|
|
2586
|
+
}
|
|
2587
|
+
function updateSeqContextFromChildResult(currentContext, index, parser, result, nextIndex) {
|
|
2588
|
+
const states = updateSeqChildState(currentContext.state, index, result.next.state, parser);
|
|
2589
|
+
const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
|
|
2590
|
+
return {
|
|
2591
|
+
...currentContext,
|
|
2592
|
+
buffer: result.next.buffer,
|
|
2593
|
+
optionsTerminated: result.next.optionsTerminated,
|
|
2594
|
+
state: createSeqState(currentContext.state, nextIndex, states),
|
|
2595
|
+
...mergedExec != null ? {
|
|
2596
|
+
exec: mergedExec,
|
|
2597
|
+
dependencyRegistry: mergedExec.dependencyRegistry
|
|
2598
|
+
} : {}
|
|
2599
|
+
};
|
|
2600
|
+
}
|
|
2601
|
+
function advanceSeqSuggestContextSync(context, parsers, initialStates) {
|
|
2602
|
+
let currentContext = context;
|
|
2603
|
+
while (currentContext.state.index < parsers.length) {
|
|
2604
|
+
const index = currentContext.state.index;
|
|
2605
|
+
const parser = parsers[index];
|
|
2606
|
+
const parserState = getSeqChildState(currentContext.state, index, parser);
|
|
2607
|
+
if (currentContext.buffer.length < 1) break;
|
|
2608
|
+
if (shouldAdvanceSeqBeforeParse(parser, parserState, initialStates[index], currentContext, index, parsers)) {
|
|
2609
|
+
const consumedTerminator = currentContext.buffer[0] === "--";
|
|
2610
|
+
currentContext = advanceSeqContext(currentContext, index + 1, consumedTerminator);
|
|
2611
|
+
continue;
|
|
2612
|
+
}
|
|
2613
|
+
const result = parser.parse(withChildContext$1(currentContext, index, parserState, parser));
|
|
2614
|
+
if (!result.success) {
|
|
2615
|
+
if (result.consumed > 0) break;
|
|
2616
|
+
if (parserCanSkipAt(parser, parserState, currentContext.exec, index)) {
|
|
2617
|
+
currentContext = advanceSeqContext(currentContext, index + 1, false);
|
|
2618
|
+
continue;
|
|
2619
|
+
}
|
|
2620
|
+
break;
|
|
2621
|
+
}
|
|
2622
|
+
const nextIndex = result.consumed.length > 0 ? index : index + 1;
|
|
2623
|
+
currentContext = updateSeqContextFromChildResult(currentContext, index, parser, result, nextIndex);
|
|
2624
|
+
}
|
|
2625
|
+
return currentContext;
|
|
2626
|
+
}
|
|
2627
|
+
async function advanceSeqSuggestContextAsync(context, parsers, initialStates) {
|
|
2628
|
+
let currentContext = context;
|
|
2629
|
+
while (currentContext.state.index < parsers.length) {
|
|
2630
|
+
const index = currentContext.state.index;
|
|
2631
|
+
const parser = parsers[index];
|
|
2632
|
+
const parserState = getSeqChildState(currentContext.state, index, parser);
|
|
2633
|
+
if (currentContext.buffer.length < 1) break;
|
|
2634
|
+
if (shouldAdvanceSeqBeforeParse(parser, parserState, initialStates[index], currentContext, index, parsers)) {
|
|
2635
|
+
const consumedTerminator = currentContext.buffer[0] === "--";
|
|
2636
|
+
currentContext = advanceSeqContext(currentContext, index + 1, consumedTerminator);
|
|
2637
|
+
continue;
|
|
2638
|
+
}
|
|
2639
|
+
const result = await parser.parse(withChildContext$1(currentContext, index, parserState, parser));
|
|
2640
|
+
if (!result.success) {
|
|
2641
|
+
if (result.consumed > 0) break;
|
|
2642
|
+
if (parserCanSkipAt(parser, parserState, currentContext.exec, index)) {
|
|
2643
|
+
currentContext = advanceSeqContext(currentContext, index + 1, false);
|
|
2644
|
+
continue;
|
|
2645
|
+
}
|
|
2646
|
+
break;
|
|
2647
|
+
}
|
|
2648
|
+
const nextIndex = result.consumed.length > 0 ? index : index + 1;
|
|
2649
|
+
currentContext = updateSeqContextFromChildResult(currentContext, index, parser, result, nextIndex);
|
|
2650
|
+
}
|
|
2651
|
+
return currentContext;
|
|
2652
|
+
}
|
|
2653
|
+
function createSeqComplete(parsers, combinedMode) {
|
|
2654
|
+
const syncParsers = parsers;
|
|
2655
|
+
return (state, exec) => require_mode_dispatch.dispatchByMode(combinedMode, () => {
|
|
2656
|
+
const stateArray = require_internal_annotations.annotateFreshArray(state, state.states);
|
|
2657
|
+
const runtime = exec?.dependencyRuntime ?? require_dependency_runtime.createDependencyRuntimeContext(exec?.dependencyRegistry);
|
|
2658
|
+
const childExec = {
|
|
2659
|
+
...exec,
|
|
2660
|
+
dependencyRuntime: runtime
|
|
2661
|
+
};
|
|
2662
|
+
const pairs = buildIndexedParserPairs(syncParsers);
|
|
2663
|
+
const stateRecord = createAnnotatedArrayStateRecord(stateArray);
|
|
2664
|
+
const preCompleted = preCompleteAndRegisterDependencies(stateRecord, pairs, runtime.registry, childExec);
|
|
2665
|
+
require_dependency_runtime.collectExplicitSourceValues(filterPreCompletedRuntimeNodes(require_dependency_runtime.buildRuntimeNodesFromArray(syncParsers, stateArray, exec?.path), new Set(preCompleted.keys())), runtime);
|
|
2666
|
+
const phase3Exec = {
|
|
2667
|
+
...childExec,
|
|
2668
|
+
preCompletedByParser: void 0
|
|
2669
|
+
};
|
|
2670
|
+
const resolvedArray = require_dependency_runtime.resolveStateWithRuntime(stateArray, runtime);
|
|
2671
|
+
const result = [];
|
|
2672
|
+
const deferredKeys = /* @__PURE__ */ new Map();
|
|
2673
|
+
let hasDeferred = false;
|
|
2674
|
+
for (let i = 0; i < syncParsers.length; i++) {
|
|
2675
|
+
const elementParser = syncParsers[i];
|
|
2676
|
+
const preCompletedResult = preCompleted.get(String(i));
|
|
2677
|
+
const valueResult = preCompletedResult !== void 0 ? unwrapCompleteResult(preCompletedResult) : unwrapCompleteResult(elementParser.complete(prepareStateForCompletion(require_annotation_state.getWrappedChildState(stateArray, resolvedArray[i], elementParser), elementParser), require_execution_context.withChildExecPath(phase3Exec, i)));
|
|
2678
|
+
if (!valueResult.success) return {
|
|
2679
|
+
success: false,
|
|
2680
|
+
error: valueResult.error
|
|
2681
|
+
};
|
|
2682
|
+
result[i] = valueResult.value;
|
|
2683
|
+
if (valueResult.deferred) if (valueResult.deferredKeys) deferredKeys.set(i, valueResult.deferredKeys);
|
|
2684
|
+
else if (valueResult.value == null || typeof valueResult.value !== "object") deferredKeys.set(i, null);
|
|
2685
|
+
else hasDeferred = true;
|
|
2686
|
+
}
|
|
2687
|
+
return {
|
|
2688
|
+
success: true,
|
|
2689
|
+
value: result,
|
|
2690
|
+
...deferredKeys.size > 0 || hasDeferred ? {
|
|
2691
|
+
deferred: true,
|
|
2692
|
+
...deferredKeys.size > 0 ? { deferredKeys } : {}
|
|
2693
|
+
} : {}
|
|
2694
|
+
};
|
|
2695
|
+
}, async () => {
|
|
2696
|
+
const stateArray = require_internal_annotations.annotateFreshArray(state, state.states);
|
|
2697
|
+
const runtime = exec?.dependencyRuntime ?? require_dependency_runtime.createDependencyRuntimeContext(exec?.dependencyRegistry);
|
|
2698
|
+
const childExec = {
|
|
2699
|
+
...exec,
|
|
2700
|
+
dependencyRuntime: runtime
|
|
2701
|
+
};
|
|
2702
|
+
const pairs = buildIndexedParserPairs(parsers);
|
|
2703
|
+
const stateRecord = createAnnotatedArrayStateRecord(stateArray);
|
|
2704
|
+
const preCompleted = await preCompleteAndRegisterDependenciesAsync(stateRecord, pairs, runtime.registry, childExec);
|
|
2705
|
+
await require_dependency_runtime.collectExplicitSourceValuesAsync(filterPreCompletedRuntimeNodes(require_dependency_runtime.buildRuntimeNodesFromArray(parsers, stateArray, exec?.path), new Set(preCompleted.keys())), runtime);
|
|
2706
|
+
const phase3Exec = {
|
|
2707
|
+
...childExec,
|
|
2708
|
+
preCompletedByParser: void 0
|
|
2709
|
+
};
|
|
2710
|
+
const resolvedArray = await require_dependency_runtime.resolveStateWithRuntimeAsync(stateArray, runtime);
|
|
2711
|
+
const result = [];
|
|
2712
|
+
const deferredKeys = /* @__PURE__ */ new Map();
|
|
2713
|
+
let hasDeferred = false;
|
|
2714
|
+
for (let i = 0; i < parsers.length; i++) {
|
|
2715
|
+
const elementParser = parsers[i];
|
|
2716
|
+
const preCompletedResult = preCompleted.get(String(i));
|
|
2717
|
+
const valueResult = preCompletedResult !== void 0 ? unwrapCompleteResult(preCompletedResult) : unwrapCompleteResult(await elementParser.complete(prepareStateForCompletion(require_annotation_state.getWrappedChildState(stateArray, resolvedArray[i], elementParser), elementParser), require_execution_context.withChildExecPath(phase3Exec, i)));
|
|
2718
|
+
if (!valueResult.success) return {
|
|
2719
|
+
success: false,
|
|
2720
|
+
error: valueResult.error
|
|
2721
|
+
};
|
|
2722
|
+
result[i] = valueResult.value;
|
|
2723
|
+
if (valueResult.deferred) if (valueResult.deferredKeys) deferredKeys.set(i, valueResult.deferredKeys);
|
|
2724
|
+
else if (valueResult.value == null || typeof valueResult.value !== "object") deferredKeys.set(i, null);
|
|
2725
|
+
else hasDeferred = true;
|
|
2726
|
+
}
|
|
2727
|
+
return {
|
|
2728
|
+
success: true,
|
|
2729
|
+
value: result,
|
|
2730
|
+
...deferredKeys.size > 0 || hasDeferred ? {
|
|
2731
|
+
deferred: true,
|
|
2732
|
+
...deferredKeys.size > 0 ? { deferredKeys } : {}
|
|
2733
|
+
} : {}
|
|
2734
|
+
};
|
|
2735
|
+
});
|
|
2736
|
+
}
|
|
2287
2737
|
function suggestTupleSync(context, prefix, parsers) {
|
|
2288
2738
|
const suggestions = [];
|
|
2289
2739
|
const advanced = advanceTupleSuggestContextSync(context, parsers);
|
|
@@ -2365,7 +2815,7 @@ function advanceTupleSuggestContextSync(context, parsers) {
|
|
|
2365
2815
|
for (const [parser, index] of remainingParsers) {
|
|
2366
2816
|
const result = parser.parse(withChildContext$1(currentContext, index, stateArray[index], parser));
|
|
2367
2817
|
if (result.success && result.consumed.length > 0) {
|
|
2368
|
-
const newStateArray =
|
|
2818
|
+
const newStateArray = require_internal_annotations.annotateFreshArray(currentContext.state, stateArray.map((state, idx) => idx === index ? require_annotation_state.getWrappedChildState(currentContext.state, result.next.state, parser) : state));
|
|
2369
2819
|
const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
|
|
2370
2820
|
currentContext = {
|
|
2371
2821
|
...currentContext,
|
|
@@ -2390,7 +2840,7 @@ function advanceTupleSuggestContextSync(context, parsers) {
|
|
|
2390
2840
|
if (!foundMatch) for (const [parser, index] of remainingParsers) {
|
|
2391
2841
|
const result = parser.parse(withChildContext$1(currentContext, index, stateArray[index], parser));
|
|
2392
2842
|
if (result.success && result.consumed.length < 1) {
|
|
2393
|
-
const newStateArray =
|
|
2843
|
+
const newStateArray = require_internal_annotations.annotateFreshArray(currentContext.state, stateArray.map((state, idx) => idx === index ? require_annotation_state.getWrappedChildState(currentContext.state, result.next.state, parser) : state));
|
|
2394
2844
|
const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
|
|
2395
2845
|
currentContext = {
|
|
2396
2846
|
...currentContext,
|
|
@@ -2431,7 +2881,7 @@ async function advanceTupleSuggestContextAsync(context, parsers) {
|
|
|
2431
2881
|
for (const [parser, index] of remainingParsers) {
|
|
2432
2882
|
const result = await parser.parse(withChildContext$1(currentContext, index, stateArray[index], parser));
|
|
2433
2883
|
if (result.success && result.consumed.length > 0) {
|
|
2434
|
-
const newStateArray =
|
|
2884
|
+
const newStateArray = require_internal_annotations.annotateFreshArray(currentContext.state, stateArray.map((state, idx) => idx === index ? require_annotation_state.getWrappedChildState(currentContext.state, result.next.state, parser) : state));
|
|
2435
2885
|
const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
|
|
2436
2886
|
currentContext = {
|
|
2437
2887
|
...currentContext,
|
|
@@ -2456,7 +2906,7 @@ async function advanceTupleSuggestContextAsync(context, parsers) {
|
|
|
2456
2906
|
if (!foundMatch) for (const [parser, index] of remainingParsers) {
|
|
2457
2907
|
const result = await parser.parse(withChildContext$1(currentContext, index, stateArray[index], parser));
|
|
2458
2908
|
if (result.success && result.consumed.length < 1) {
|
|
2459
|
-
const newStateArray =
|
|
2909
|
+
const newStateArray = require_internal_annotations.annotateFreshArray(currentContext.state, stateArray.map((state, idx) => idx === index ? require_annotation_state.getWrappedChildState(currentContext.state, result.next.state, parser) : state));
|
|
2460
2910
|
const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
|
|
2461
2911
|
currentContext = {
|
|
2462
2912
|
...currentContext,
|
|
@@ -2492,7 +2942,7 @@ function markFailedTupleSuggestSources(parsers, stateArray, failedParserIndexes,
|
|
|
2492
2942
|
const parser = parsers[index];
|
|
2493
2943
|
if (parser == null) continue;
|
|
2494
2944
|
const parserState = stateArray && Array.isArray(stateArray) ? stateArray[index] : parser.initialState;
|
|
2495
|
-
const nodes =
|
|
2945
|
+
const nodes = require_internal_parser.getParserSuggestRuntimeNodes(parser, require_annotation_state.getWrappedChildState(stateArray, parserState, parser), [...prefix, index]);
|
|
2496
2946
|
if (nodes.length < 1) continue;
|
|
2497
2947
|
const failedRuntime = require_dependency_runtime.createDependencyRuntimeContext();
|
|
2498
2948
|
require_dependency_runtime.collectExplicitSourceValues(nodes, failedRuntime);
|
|
@@ -2509,7 +2959,7 @@ async function markFailedTupleSuggestSourcesAsync(parsers, stateArray, failedPar
|
|
|
2509
2959
|
const parser = parsers[index];
|
|
2510
2960
|
if (parser == null) continue;
|
|
2511
2961
|
const parserState = stateArray && Array.isArray(stateArray) ? stateArray[index] : parser.initialState;
|
|
2512
|
-
const nodes =
|
|
2962
|
+
const nodes = require_internal_parser.getParserSuggestRuntimeNodes(parser, require_annotation_state.getWrappedChildState(stateArray, parserState, parser), [...prefix, index]);
|
|
2513
2963
|
if (nodes.length < 1) continue;
|
|
2514
2964
|
const failedRuntime = require_dependency_runtime.createDependencyRuntimeContext();
|
|
2515
2965
|
await require_dependency_runtime.collectExplicitSourceValuesAsync(nodes, failedRuntime);
|
|
@@ -2549,7 +2999,7 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
2549
2999
|
for (const [parser, index] of remainingParsers) {
|
|
2550
3000
|
const result = parser.parse(withChildContext$1(currentContext, index, stateArray[index], parser));
|
|
2551
3001
|
if (result.success && result.consumed.length > 0) {
|
|
2552
|
-
const newStateArray =
|
|
3002
|
+
const newStateArray = require_internal_annotations.annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? require_annotation_state.getWrappedChildState(currentContext.state, result.next.state, parser) : s));
|
|
2553
3003
|
const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
|
|
2554
3004
|
currentContext = {
|
|
2555
3005
|
...currentContext,
|
|
@@ -2570,7 +3020,7 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
2570
3020
|
if (!foundMatch) for (const [parser, index] of remainingParsers) {
|
|
2571
3021
|
const result = parser.parse(withChildContext$1(currentContext, index, stateArray[index], parser));
|
|
2572
3022
|
if (result.success && result.consumed.length < 1) {
|
|
2573
|
-
const newStateArray =
|
|
3023
|
+
const newStateArray = require_internal_annotations.annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? require_annotation_state.getWrappedChildState(currentContext.state, result.next.state, parser) : s));
|
|
2574
3024
|
const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
|
|
2575
3025
|
currentContext = {
|
|
2576
3026
|
...currentContext,
|
|
@@ -2616,7 +3066,7 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
2616
3066
|
const resultOrPromise = parser.parse(withChildContext$1(currentContext, index, stateArray[index], parser));
|
|
2617
3067
|
const result = await resultOrPromise;
|
|
2618
3068
|
if (result.success && result.consumed.length > 0) {
|
|
2619
|
-
const newStateArray =
|
|
3069
|
+
const newStateArray = require_internal_annotations.annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? require_annotation_state.getWrappedChildState(currentContext.state, result.next.state, parser) : s));
|
|
2620
3070
|
const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
|
|
2621
3071
|
currentContext = {
|
|
2622
3072
|
...currentContext,
|
|
@@ -2638,7 +3088,7 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
2638
3088
|
const resultOrPromise = parser.parse(withChildContext$1(currentContext, index, stateArray[index], parser));
|
|
2639
3089
|
const result = await resultOrPromise;
|
|
2640
3090
|
if (result.success && result.consumed.length < 1) {
|
|
2641
|
-
const newStateArray =
|
|
3091
|
+
const newStateArray = require_internal_annotations.annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? require_annotation_state.getWrappedChildState(currentContext.state, result.next.state, parser) : s));
|
|
2642
3092
|
const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
|
|
2643
3093
|
currentContext = {
|
|
2644
3094
|
...currentContext,
|
|
@@ -2678,6 +3128,10 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
2678
3128
|
acceptingAnyToken: parsers.some((p) => p.acceptingAnyToken),
|
|
2679
3129
|
priority: parsers.length > 0 ? Math.max(...parsers.map((p) => p.priority)) : 0,
|
|
2680
3130
|
initialState: parsers.map((parser) => parser.initialState),
|
|
3131
|
+
canSkip(state, exec) {
|
|
3132
|
+
const stateArray = state;
|
|
3133
|
+
return parsers.every((parser, index) => parser.canSkip?.(require_annotation_state.getWrappedChildState(stateArray, stateArray[index], parser), require_execution_context.withChildExecPath(exec, index)) === true);
|
|
3134
|
+
},
|
|
2681
3135
|
parse(context) {
|
|
2682
3136
|
return require_mode_dispatch.dispatchByMode(combinedMode, () => parseSync(context), () => parseAsync(context));
|
|
2683
3137
|
},
|
|
@@ -2912,9 +3366,337 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
2912
3366
|
configurable: true,
|
|
2913
3367
|
enumerable: false
|
|
2914
3368
|
});
|
|
2915
|
-
|
|
3369
|
+
require_internal_parser.defineInheritedAnnotationParser(tupleParser);
|
|
2916
3370
|
return tupleParser;
|
|
2917
3371
|
}
|
|
3372
|
+
function seq(...rawArgs) {
|
|
3373
|
+
const label = typeof rawArgs[0] === "string" ? rawArgs[0] : void 0;
|
|
3374
|
+
if (label != null) require_validate.validateLabel(label);
|
|
3375
|
+
const args = label == null ? rawArgs : rawArgs.slice(1);
|
|
3376
|
+
const lastArg = args.at(-1);
|
|
3377
|
+
const hasOptions = lastArg != null && !isParserLike(lastArg);
|
|
3378
|
+
const options = hasOptions ? lastArg : {};
|
|
3379
|
+
const parsers = hasOptions ? args.slice(0, -1) : args;
|
|
3380
|
+
const combinedMode = parsers.some((p) => p.mode === "async") ? "async" : "sync";
|
|
3381
|
+
const syncParsers = parsers;
|
|
3382
|
+
if (!options.allowDuplicates) checkSequentialDuplicateOptionNames(parsers);
|
|
3383
|
+
const initialState = createSeqState(void 0, 0, parsers.map((parser) => parser.initialState));
|
|
3384
|
+
const withSeqConsumedDepth = (result, consumed) => ({
|
|
3385
|
+
...result,
|
|
3386
|
+
consumed: consumed.length + result.consumed
|
|
3387
|
+
});
|
|
3388
|
+
const parseSync = (context) => {
|
|
3389
|
+
let currentContext = context;
|
|
3390
|
+
const allConsumed = [];
|
|
3391
|
+
while (currentContext.state.index < syncParsers.length) {
|
|
3392
|
+
const index = currentContext.state.index;
|
|
3393
|
+
const parser = syncParsers[index];
|
|
3394
|
+
const parserState = getSeqChildState(currentContext.state, index, parser);
|
|
3395
|
+
if (currentContext.buffer.length < 1) break;
|
|
3396
|
+
if (shouldAdvanceSeqBeforeParse(parser, parserState, initialState.states[index], currentContext, index, syncParsers)) {
|
|
3397
|
+
const consumedTerminator = currentContext.buffer[0] === "--";
|
|
3398
|
+
if (consumedTerminator) allConsumed.push("--");
|
|
3399
|
+
currentContext = advanceSeqContext(currentContext, index + 1, consumedTerminator);
|
|
3400
|
+
continue;
|
|
3401
|
+
}
|
|
3402
|
+
const result = parser.parse(withChildContext$1(currentContext, index, parserState, parser));
|
|
3403
|
+
if (!result.success) {
|
|
3404
|
+
if (result.consumed > 0) return withSeqConsumedDepth(result, allConsumed);
|
|
3405
|
+
if (!parserCanSkipAt(parser, parserState, currentContext.exec, index)) return withSeqConsumedDepth(result, allConsumed);
|
|
3406
|
+
currentContext = advanceSeqContext(currentContext, index + 1, false);
|
|
3407
|
+
continue;
|
|
3408
|
+
}
|
|
3409
|
+
const states = updateSeqChildState(currentContext.state, index, result.next.state, parser);
|
|
3410
|
+
const nextIndex = result.consumed.length > 0 ? index : index + 1;
|
|
3411
|
+
const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
|
|
3412
|
+
currentContext = {
|
|
3413
|
+
...currentContext,
|
|
3414
|
+
buffer: result.next.buffer,
|
|
3415
|
+
optionsTerminated: result.next.optionsTerminated,
|
|
3416
|
+
state: createSeqState(currentContext.state, nextIndex, states),
|
|
3417
|
+
...mergedExec != null ? {
|
|
3418
|
+
exec: mergedExec,
|
|
3419
|
+
dependencyRegistry: mergedExec.dependencyRegistry
|
|
3420
|
+
} : {}
|
|
3421
|
+
};
|
|
3422
|
+
allConsumed.push(...result.consumed);
|
|
3423
|
+
}
|
|
3424
|
+
return {
|
|
3425
|
+
success: true,
|
|
3426
|
+
next: currentContext,
|
|
3427
|
+
consumed: allConsumed
|
|
3428
|
+
};
|
|
3429
|
+
};
|
|
3430
|
+
const parseAsync = async (context) => {
|
|
3431
|
+
let currentContext = context;
|
|
3432
|
+
const allConsumed = [];
|
|
3433
|
+
while (currentContext.state.index < parsers.length) {
|
|
3434
|
+
const index = currentContext.state.index;
|
|
3435
|
+
const parser = parsers[index];
|
|
3436
|
+
const parserState = getSeqChildState(currentContext.state, index, parser);
|
|
3437
|
+
if (currentContext.buffer.length < 1) break;
|
|
3438
|
+
if (shouldAdvanceSeqBeforeParse(parser, parserState, initialState.states[index], currentContext, index, parsers)) {
|
|
3439
|
+
const consumedTerminator = currentContext.buffer[0] === "--";
|
|
3440
|
+
if (consumedTerminator) allConsumed.push("--");
|
|
3441
|
+
currentContext = advanceSeqContext(currentContext, index + 1, consumedTerminator);
|
|
3442
|
+
continue;
|
|
3443
|
+
}
|
|
3444
|
+
const result = await parser.parse(withChildContext$1(currentContext, index, parserState, parser));
|
|
3445
|
+
if (!result.success) {
|
|
3446
|
+
if (result.consumed > 0) return withSeqConsumedDepth(result, allConsumed);
|
|
3447
|
+
if (!parserCanSkipAt(parser, parserState, currentContext.exec, index)) return withSeqConsumedDepth(result, allConsumed);
|
|
3448
|
+
currentContext = advanceSeqContext(currentContext, index + 1, false);
|
|
3449
|
+
continue;
|
|
3450
|
+
}
|
|
3451
|
+
const states = updateSeqChildState(currentContext.state, index, result.next.state, parser);
|
|
3452
|
+
const nextIndex = result.consumed.length > 0 ? index : index + 1;
|
|
3453
|
+
const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
|
|
3454
|
+
currentContext = {
|
|
3455
|
+
...currentContext,
|
|
3456
|
+
buffer: result.next.buffer,
|
|
3457
|
+
optionsTerminated: result.next.optionsTerminated,
|
|
3458
|
+
state: createSeqState(currentContext.state, nextIndex, states),
|
|
3459
|
+
...mergedExec != null ? {
|
|
3460
|
+
exec: mergedExec,
|
|
3461
|
+
dependencyRegistry: mergedExec.dependencyRegistry
|
|
3462
|
+
} : {}
|
|
3463
|
+
};
|
|
3464
|
+
allConsumed.push(...result.consumed);
|
|
3465
|
+
}
|
|
3466
|
+
return {
|
|
3467
|
+
success: true,
|
|
3468
|
+
next: currentContext,
|
|
3469
|
+
consumed: allConsumed
|
|
3470
|
+
};
|
|
3471
|
+
};
|
|
3472
|
+
const leadingNames = sequenceLeadingNames(parsers);
|
|
3473
|
+
const seqParser = {
|
|
3474
|
+
mode: combinedMode,
|
|
3475
|
+
$valueType: [],
|
|
3476
|
+
$stateType: [],
|
|
3477
|
+
[fieldParsersKey]: parsers.map((parser, index) => [String(index), parser]),
|
|
3478
|
+
usage: [{
|
|
3479
|
+
type: "sequence",
|
|
3480
|
+
terms: parsers.flatMap((parser) => parser.usage)
|
|
3481
|
+
}],
|
|
3482
|
+
leadingNames,
|
|
3483
|
+
acceptingAnyToken: sequenceAcceptingAnyToken(parsers),
|
|
3484
|
+
priority: sequencePriority(parsers),
|
|
3485
|
+
initialState,
|
|
3486
|
+
canSkip(state, exec) {
|
|
3487
|
+
for (let i = state.index; i < parsers.length; i++) {
|
|
3488
|
+
const parser = parsers[i];
|
|
3489
|
+
if (parser.canSkip?.(getSeqChildState(state, i, parser), require_execution_context.withChildExecPath(exec, i)) !== true) return false;
|
|
3490
|
+
}
|
|
3491
|
+
return true;
|
|
3492
|
+
},
|
|
3493
|
+
parse(context) {
|
|
3494
|
+
return require_mode_dispatch.dispatchByMode(combinedMode, () => parseSync(context), () => parseAsync(context));
|
|
3495
|
+
},
|
|
3496
|
+
complete: void 0,
|
|
3497
|
+
[require_phase2_seed.extractPhase2SeedKey](state, exec) {
|
|
3498
|
+
return require_mode_dispatch.dispatchByMode(combinedMode, () => {
|
|
3499
|
+
const stateArray = state.states;
|
|
3500
|
+
const runtime = exec?.dependencyRuntime ?? require_dependency_runtime.createDependencyRuntimeContext(exec?.dependencyRegistry);
|
|
3501
|
+
const childExec = withDependencyRuntimeExec(seqParser.usage, exec, runtime);
|
|
3502
|
+
const pairs = buildIndexedParserPairs(syncParsers);
|
|
3503
|
+
const stateRecord = createAnnotatedArrayStateRecord(stateArray);
|
|
3504
|
+
const preCompleted = preCompleteAndRegisterDependencies(stateRecord, pairs, runtime.registry, childExec);
|
|
3505
|
+
require_dependency_runtime.collectExplicitSourceValues(filterPreCompletedRuntimeNodes(require_dependency_runtime.buildRuntimeNodesFromArray(syncParsers, stateArray, exec?.path), new Set(preCompleted.keys())), runtime);
|
|
3506
|
+
const phase3Exec = {
|
|
3507
|
+
...childExec,
|
|
3508
|
+
preCompletedByParser: void 0
|
|
3509
|
+
};
|
|
3510
|
+
const resolvedArray = require_dependency_runtime.resolveStateWithRuntime(stateArray, runtime);
|
|
3511
|
+
const result = [];
|
|
3512
|
+
const deferredKeys = /* @__PURE__ */ new Map();
|
|
3513
|
+
let hasDeferred = false;
|
|
3514
|
+
let hasAnySeed = false;
|
|
3515
|
+
for (let i = 0; i < syncParsers.length; i++) {
|
|
3516
|
+
const elementParser = syncParsers[i];
|
|
3517
|
+
const childExec$1 = require_execution_context.withChildExecPath(phase3Exec, i);
|
|
3518
|
+
const preCompletedResult = preCompleted.get(String(i));
|
|
3519
|
+
const seed = preCompletedResult !== void 0 ? reusePreCompletedPhase2Seed(elementParser, prepareStateForCompletion(resolvedArray[i], elementParser), preCompletedResult, childExec$1) : require_phase2_seed.completeOrExtractPhase2Seed(elementParser, prepareStateForCompletion(resolvedArray[i], elementParser), childExec$1);
|
|
3520
|
+
if (seed == null) continue;
|
|
3521
|
+
hasAnySeed = true;
|
|
3522
|
+
result[i] = seed.value;
|
|
3523
|
+
if (seed.deferred) if (seed.deferredKeys) deferredKeys.set(i, seed.deferredKeys);
|
|
3524
|
+
else if (seed.value == null || typeof seed.value !== "object") deferredKeys.set(i, null);
|
|
3525
|
+
else hasDeferred = true;
|
|
3526
|
+
}
|
|
3527
|
+
if (!hasAnySeed) return null;
|
|
3528
|
+
return {
|
|
3529
|
+
value: result,
|
|
3530
|
+
...deferredKeys.size > 0 || hasDeferred ? {
|
|
3531
|
+
deferred: true,
|
|
3532
|
+
...deferredKeys.size > 0 ? { deferredKeys } : {}
|
|
3533
|
+
} : {}
|
|
3534
|
+
};
|
|
3535
|
+
}, async () => {
|
|
3536
|
+
const stateArray = state.states;
|
|
3537
|
+
const runtime = exec?.dependencyRuntime ?? require_dependency_runtime.createDependencyRuntimeContext(exec?.dependencyRegistry);
|
|
3538
|
+
const childExec = withDependencyRuntimeExec(seqParser.usage, exec, runtime);
|
|
3539
|
+
const pairs = buildIndexedParserPairs(parsers);
|
|
3540
|
+
const stateRecord = createAnnotatedArrayStateRecord(stateArray);
|
|
3541
|
+
const preCompleted = await preCompleteAndRegisterDependenciesAsync(stateRecord, pairs, runtime.registry, childExec);
|
|
3542
|
+
await require_dependency_runtime.collectExplicitSourceValuesAsync(filterPreCompletedRuntimeNodes(require_dependency_runtime.buildRuntimeNodesFromArray(parsers, stateArray, exec?.path), new Set(preCompleted.keys())), runtime);
|
|
3543
|
+
const phase3Exec = {
|
|
3544
|
+
...childExec,
|
|
3545
|
+
preCompletedByParser: void 0
|
|
3546
|
+
};
|
|
3547
|
+
const resolvedArray = await require_dependency_runtime.resolveStateWithRuntimeAsync(stateArray, runtime);
|
|
3548
|
+
const result = [];
|
|
3549
|
+
const deferredKeys = /* @__PURE__ */ new Map();
|
|
3550
|
+
let hasDeferred = false;
|
|
3551
|
+
let hasAnySeed = false;
|
|
3552
|
+
for (let i = 0; i < parsers.length; i++) {
|
|
3553
|
+
const elementParser = parsers[i];
|
|
3554
|
+
const childExec$1 = require_execution_context.withChildExecPath(phase3Exec, i);
|
|
3555
|
+
const preCompletedResult = preCompleted.get(String(i));
|
|
3556
|
+
const seed = preCompletedResult !== void 0 ? await reusePreCompletedPhase2SeedAsync(elementParser, prepareStateForCompletion(resolvedArray[i], elementParser), preCompletedResult, childExec$1) : await require_phase2_seed.completeOrExtractPhase2Seed(elementParser, prepareStateForCompletion(resolvedArray[i], elementParser), childExec$1);
|
|
3557
|
+
if (seed == null) continue;
|
|
3558
|
+
hasAnySeed = true;
|
|
3559
|
+
result[i] = seed.value;
|
|
3560
|
+
if (seed.deferred) if (seed.deferredKeys) deferredKeys.set(i, seed.deferredKeys);
|
|
3561
|
+
else if (seed.value == null || typeof seed.value !== "object") deferredKeys.set(i, null);
|
|
3562
|
+
else hasDeferred = true;
|
|
3563
|
+
}
|
|
3564
|
+
if (!hasAnySeed) return null;
|
|
3565
|
+
return {
|
|
3566
|
+
value: result,
|
|
3567
|
+
...deferredKeys.size > 0 || hasDeferred ? {
|
|
3568
|
+
deferred: true,
|
|
3569
|
+
...deferredKeys.size > 0 ? { deferredKeys } : {}
|
|
3570
|
+
} : {}
|
|
3571
|
+
};
|
|
3572
|
+
});
|
|
3573
|
+
},
|
|
3574
|
+
suggest(context, prefix) {
|
|
3575
|
+
return require_mode_dispatch.dispatchIterableByMode(combinedMode, () => {
|
|
3576
|
+
const suggestions = [];
|
|
3577
|
+
const advancedContext = advanceSeqSuggestContextSync(context, syncParsers, initialState.states);
|
|
3578
|
+
const runtime = require_dependency_runtime.createDependencyRuntimeContext(advancedContext.dependencyRegistry?.clone());
|
|
3579
|
+
const state = advancedContext.state;
|
|
3580
|
+
const stateArray = state.states;
|
|
3581
|
+
const nodes = buildSuggestRuntimeNodesFromArray(syncParsers, stateArray, advancedContext.exec?.path);
|
|
3582
|
+
require_dependency_runtime.collectExplicitSourceValues(nodes, runtime);
|
|
3583
|
+
require_dependency_runtime.fillMissingSourceDefaults(nodes, runtime);
|
|
3584
|
+
require_dependency_runtime.collectSourcesFromState(stateArray, runtime);
|
|
3585
|
+
completeDependencySourceDefaults({
|
|
3586
|
+
...advancedContext,
|
|
3587
|
+
state: createAnnotatedArrayStateRecord(stateArray)
|
|
3588
|
+
}, buildIndexedParserPairs(syncParsers), runtime.registry, advancedContext.exec);
|
|
3589
|
+
const contextWithRegistry = {
|
|
3590
|
+
...advancedContext,
|
|
3591
|
+
dependencyRegistry: runtime.registry,
|
|
3592
|
+
...advancedContext.exec != null ? { exec: {
|
|
3593
|
+
...advancedContext.exec,
|
|
3594
|
+
dependencyRuntime: runtime,
|
|
3595
|
+
dependencyRegistry: runtime.registry
|
|
3596
|
+
} } : {}
|
|
3597
|
+
};
|
|
3598
|
+
for (let i = state.index; i < syncParsers.length; i++) {
|
|
3599
|
+
const parser = syncParsers[i];
|
|
3600
|
+
const parserState = getSeqChildState(state, i, parser);
|
|
3601
|
+
suggestions.push(...parser.suggest(withChildContext$1(contextWithRegistry, i, parserState, parser), prefix));
|
|
3602
|
+
if (parser.canSkip?.(parserState, require_execution_context.withChildExecPath(contextWithRegistry.exec, i)) !== true) break;
|
|
3603
|
+
}
|
|
3604
|
+
return require_suggestion.deduplicateSuggestions(suggestions);
|
|
3605
|
+
}, async function* () {
|
|
3606
|
+
const suggestions = [];
|
|
3607
|
+
const advancedContext = await advanceSeqSuggestContextAsync(context, parsers, initialState.states);
|
|
3608
|
+
const runtime = require_dependency_runtime.createDependencyRuntimeContext(advancedContext.dependencyRegistry?.clone());
|
|
3609
|
+
const state = advancedContext.state;
|
|
3610
|
+
const stateArray = state.states;
|
|
3611
|
+
const nodes = buildSuggestRuntimeNodesFromArray(parsers, stateArray, advancedContext.exec?.path);
|
|
3612
|
+
await require_dependency_runtime.collectExplicitSourceValuesAsync(nodes, runtime);
|
|
3613
|
+
await require_dependency_runtime.fillMissingSourceDefaultsAsync(nodes, runtime);
|
|
3614
|
+
require_dependency_runtime.collectSourcesFromState(stateArray, runtime);
|
|
3615
|
+
await completeDependencySourceDefaultsAsync({
|
|
3616
|
+
...advancedContext,
|
|
3617
|
+
state: createAnnotatedArrayStateRecord(stateArray)
|
|
3618
|
+
}, buildIndexedParserPairs(parsers), runtime.registry, advancedContext.exec);
|
|
3619
|
+
const contextWithRegistry = {
|
|
3620
|
+
...advancedContext,
|
|
3621
|
+
dependencyRegistry: runtime.registry,
|
|
3622
|
+
...advancedContext.exec != null ? { exec: {
|
|
3623
|
+
...advancedContext.exec,
|
|
3624
|
+
dependencyRuntime: runtime,
|
|
3625
|
+
dependencyRegistry: runtime.registry
|
|
3626
|
+
} } : {}
|
|
3627
|
+
};
|
|
3628
|
+
for (let i = state.index; i < parsers.length; i++) {
|
|
3629
|
+
const parser = parsers[i];
|
|
3630
|
+
const parserState = getSeqChildState(state, i, parser);
|
|
3631
|
+
const parserSuggestions = parser.suggest(withChildContext$1(contextWithRegistry, i, parserState, parser), prefix);
|
|
3632
|
+
if (parser.mode === "async") for await (const suggestion of parserSuggestions) suggestions.push(suggestion);
|
|
3633
|
+
else suggestions.push(...parserSuggestions);
|
|
3634
|
+
if (parser.canSkip?.(parserState, require_execution_context.withChildExecPath(contextWithRegistry.exec, i)) !== true) break;
|
|
3635
|
+
}
|
|
3636
|
+
yield* require_suggestion.deduplicateSuggestions(suggestions);
|
|
3637
|
+
});
|
|
3638
|
+
},
|
|
3639
|
+
getDocFragments(state, defaultValue) {
|
|
3640
|
+
const fragments = syncParsers.flatMap((parser, index) => {
|
|
3641
|
+
const indexState = state.kind === "unavailable" ? { kind: "unavailable" } : {
|
|
3642
|
+
kind: "available",
|
|
3643
|
+
state: state.state.states[index]
|
|
3644
|
+
};
|
|
3645
|
+
return parser.getDocFragments(indexState, defaultValue?.[index]).fragments;
|
|
3646
|
+
});
|
|
3647
|
+
const entries = fragments.filter((d) => d.type === "entry");
|
|
3648
|
+
const sections = [];
|
|
3649
|
+
for (const fragment of fragments) {
|
|
3650
|
+
if (fragment.type !== "section") continue;
|
|
3651
|
+
if (fragment.title == null) entries.push(...fragment.entries);
|
|
3652
|
+
else sections.push(fragment);
|
|
3653
|
+
}
|
|
3654
|
+
sections.push({
|
|
3655
|
+
title: label,
|
|
3656
|
+
entries
|
|
3657
|
+
});
|
|
3658
|
+
return { fragments: sections.map((s) => ({
|
|
3659
|
+
...s,
|
|
3660
|
+
type: "section"
|
|
3661
|
+
})) };
|
|
3662
|
+
},
|
|
3663
|
+
[Symbol.for("Deno.customInspect")]() {
|
|
3664
|
+
const parsersStr = parsers.length === 1 ? "1 parser" : `${parsers.length} parsers`;
|
|
3665
|
+
return label == null ? `seq(${parsersStr})` : `seq(${JSON.stringify(label)}, ${parsersStr})`;
|
|
3666
|
+
}
|
|
3667
|
+
};
|
|
3668
|
+
Object.defineProperty(seqParser, "complete", {
|
|
3669
|
+
value: createSeqComplete(parsers, combinedMode),
|
|
3670
|
+
configurable: true,
|
|
3671
|
+
enumerable: true
|
|
3672
|
+
});
|
|
3673
|
+
const normalizers = [];
|
|
3674
|
+
for (let i = 0; i < parsers.length; i++) {
|
|
3675
|
+
const parser = parsers[i];
|
|
3676
|
+
if (typeof parser.normalizeValue === "function") normalizers.push([i, parser.normalizeValue.bind(parser)]);
|
|
3677
|
+
}
|
|
3678
|
+
if (normalizers.length > 0) Object.defineProperty(seqParser, "normalizeValue", {
|
|
3679
|
+
value(arr) {
|
|
3680
|
+
if (!Array.isArray(arr)) return arr;
|
|
3681
|
+
let changed = false;
|
|
3682
|
+
let result;
|
|
3683
|
+
for (const [index, normalize] of normalizers) if (index < arr.length && Object.hasOwn(arr, index)) try {
|
|
3684
|
+
const original = arr[index];
|
|
3685
|
+
const normalized = normalize(original);
|
|
3686
|
+
if (normalized !== original) {
|
|
3687
|
+
result ??= [...arr];
|
|
3688
|
+
result[index] = normalized;
|
|
3689
|
+
changed = true;
|
|
3690
|
+
}
|
|
3691
|
+
} catch {}
|
|
3692
|
+
return changed ? result : arr;
|
|
3693
|
+
},
|
|
3694
|
+
configurable: true,
|
|
3695
|
+
enumerable: false
|
|
3696
|
+
});
|
|
3697
|
+
require_internal_parser.defineInheritedAnnotationParser(seqParser);
|
|
3698
|
+
return seqParser;
|
|
3699
|
+
}
|
|
2918
3700
|
function merge(...args) {
|
|
2919
3701
|
const label = typeof args[0] === "string" ? args[0] : void 0;
|
|
2920
3702
|
if (label != null) require_validate.validateLabel(label);
|
|
@@ -2936,6 +3718,7 @@ function merge(...args) {
|
|
|
2936
3718
|
const syncSorted = syncWithIndex.toSorted(([a], [b]) => b.priority - a.priority);
|
|
2937
3719
|
const syncParsers = syncSorted.map(([p]) => p);
|
|
2938
3720
|
if (!options.allowDuplicates) checkDuplicateOptionNames(sorted.map(([parser, originalIndex]) => [String(originalIndex), parser.usage]));
|
|
3721
|
+
checkDuplicateReachableLeadingCommandNames(sorted.map(([parser, originalIndex]) => [String(originalIndex), parser]));
|
|
2939
3722
|
const mergedFieldParsers = collectChildFieldParsers(parsers);
|
|
2940
3723
|
const duplicateOutputFieldNames = collectDuplicateFieldNames(mergedFieldParsers);
|
|
2941
3724
|
const parserStateKey = (index) => `__parser_${index}`;
|
|
@@ -2947,23 +3730,24 @@ function merge(...args) {
|
|
|
2947
3730
|
if (parser.initialState === void 0) initialState[parserStateKey(i)] = void 0;
|
|
2948
3731
|
else if (parser.initialState && typeof parser.initialState === "object") for (const field in parser.initialState) initialState[field] = parser.initialState[field];
|
|
2949
3732
|
}
|
|
2950
|
-
const
|
|
3733
|
+
const extractParserStateFromState = (parser, state, index) => {
|
|
2951
3734
|
if (parser.initialState === void 0) {
|
|
2952
3735
|
const key = parserStateKey(index);
|
|
2953
|
-
if (
|
|
3736
|
+
if (state && typeof state === "object" && key in state) return state[key];
|
|
2954
3737
|
return void 0;
|
|
2955
3738
|
} else if (parser.initialState && typeof parser.initialState === "object") {
|
|
2956
3739
|
const localStateKey = localObjectStateKey(index);
|
|
2957
|
-
if (shouldPreserveLocalChildState(parser) &&
|
|
2958
|
-
if (
|
|
3740
|
+
if (shouldPreserveLocalChildState(parser) && state && typeof state === "object" && localStateKey in state) return state[localStateKey];
|
|
3741
|
+
if (state && typeof state === "object") {
|
|
2959
3742
|
const extractedState = {};
|
|
2960
|
-
for (const field in parser.initialState) extractedState[field] = field in
|
|
3743
|
+
for (const field in parser.initialState) extractedState[field] = field in state ? state[field] : parser.initialState[field];
|
|
2961
3744
|
return extractedState;
|
|
2962
3745
|
}
|
|
2963
3746
|
return parser.initialState;
|
|
2964
3747
|
}
|
|
2965
3748
|
return parser.initialState;
|
|
2966
3749
|
};
|
|
3750
|
+
const extractParserState = (parser, context, index) => extractParserStateFromState(parser, context.state, index);
|
|
2967
3751
|
const mergeResultState = (parser, context, parserState, result, index) => {
|
|
2968
3752
|
if (parser.initialState === void 0) {
|
|
2969
3753
|
const key = parserStateKey(index);
|
|
@@ -3088,6 +3872,12 @@ function merge(...args) {
|
|
|
3088
3872
|
leadingNames: sharedBufferLeadingNames(parsers),
|
|
3089
3873
|
acceptingAnyToken: parsers.some((p) => p.acceptingAnyToken),
|
|
3090
3874
|
initialState,
|
|
3875
|
+
canSkip(state, exec) {
|
|
3876
|
+
return parsers.every((parser, index) => {
|
|
3877
|
+
const parserState = extractParserStateFromState(parser, state, index);
|
|
3878
|
+
return parser.canSkip?.(require_annotation_state.getWrappedChildState(state, parserState, parser), require_execution_context.withChildExecPath(exec, index)) === true;
|
|
3879
|
+
});
|
|
3880
|
+
},
|
|
3091
3881
|
parse(context) {
|
|
3092
3882
|
if (isAsync) return parseAsync(context);
|
|
3093
3883
|
return parseSync(context);
|
|
@@ -3104,8 +3894,8 @@ function merge(...args) {
|
|
|
3104
3894
|
if (resolvedState && typeof resolvedState === "object") {
|
|
3105
3895
|
const extractedState = {};
|
|
3106
3896
|
for (const field in parser.initialState) extractedState[field] = field in resolvedState ? resolvedState[field] : parser.initialState[field];
|
|
3107
|
-
const annotations =
|
|
3108
|
-
if (annotations !== void 0) return
|
|
3897
|
+
const annotations = require_internal_annotations.getAnnotations(resolvedState);
|
|
3898
|
+
if (annotations !== void 0) return require_internal_annotations.inheritAnnotations(resolvedState, extractedState);
|
|
3109
3899
|
return extractedState;
|
|
3110
3900
|
}
|
|
3111
3901
|
return parser.initialState;
|
|
@@ -3258,7 +4048,7 @@ function merge(...args) {
|
|
|
3258
4048
|
if (resolvedState && typeof resolvedState === "object") {
|
|
3259
4049
|
const extractedState = {};
|
|
3260
4050
|
for (const field in parser.initialState) extractedState[field] = field in resolvedState ? resolvedState[field] : parser.initialState[field];
|
|
3261
|
-
return
|
|
4051
|
+
return require_internal_annotations.inheritAnnotations(resolvedState, extractedState);
|
|
3262
4052
|
}
|
|
3263
4053
|
return parser.initialState;
|
|
3264
4054
|
}
|
|
@@ -3555,7 +4345,7 @@ function merge(...args) {
|
|
|
3555
4345
|
};
|
|
3556
4346
|
}
|
|
3557
4347
|
};
|
|
3558
|
-
|
|
4348
|
+
require_internal_parser.defineInheritedAnnotationParser(mergeParser);
|
|
3559
4349
|
return mergeParser;
|
|
3560
4350
|
}
|
|
3561
4351
|
/**
|
|
@@ -3691,7 +4481,7 @@ async function seedSuggestRuntimeFromFieldParsersAsync(parser, state, runtime, p
|
|
|
3691
4481
|
*/
|
|
3692
4482
|
function preParseSuggestContext(context, parsers) {
|
|
3693
4483
|
if (context.buffer.length < 1 || !Array.isArray(context.state)) return context;
|
|
3694
|
-
return preParseSuggestLoop(context,
|
|
4484
|
+
return preParseSuggestLoop(context, require_internal_annotations.annotateFreshArray(context.state, context.state.slice()), parsers);
|
|
3695
4485
|
}
|
|
3696
4486
|
/**
|
|
3697
4487
|
* Async variant of {@link preParseSuggestContext} that awaits async child
|
|
@@ -3700,7 +4490,7 @@ function preParseSuggestContext(context, parsers) {
|
|
|
3700
4490
|
*/
|
|
3701
4491
|
async function preParseSuggestContextAsync(context, parsers) {
|
|
3702
4492
|
if (context.buffer.length < 1 || !Array.isArray(context.state)) return context;
|
|
3703
|
-
return await preParseSuggestLoop(context,
|
|
4493
|
+
return await preParseSuggestLoop(context, require_internal_annotations.annotateFreshArray(context.state, context.state.slice()), parsers);
|
|
3704
4494
|
}
|
|
3705
4495
|
/**
|
|
3706
4496
|
* Shared loop for sync and async concat suggest pre-parse. When a child
|
|
@@ -3807,7 +4597,7 @@ function concat(...parsers) {
|
|
|
3807
4597
|
for (const [parser, index] of remainingParsers) {
|
|
3808
4598
|
const result = parser.parse(withChildContext$1(currentContext, index, stateArray[index], parser));
|
|
3809
4599
|
if (result.success && result.consumed.length > 0) {
|
|
3810
|
-
const newStateArray =
|
|
4600
|
+
const newStateArray = require_internal_annotations.annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? require_annotation_state.getWrappedChildState(currentContext.state, result.next.state, parser) : s));
|
|
3811
4601
|
const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
|
|
3812
4602
|
currentContext = {
|
|
3813
4603
|
...currentContext,
|
|
@@ -3828,7 +4618,7 @@ function concat(...parsers) {
|
|
|
3828
4618
|
if (!foundMatch) for (const [parser, index] of remainingParsers) {
|
|
3829
4619
|
const result = parser.parse(withChildContext$1(currentContext, index, stateArray[index], parser));
|
|
3830
4620
|
if (result.success && result.consumed.length < 1) {
|
|
3831
|
-
const newStateArray =
|
|
4621
|
+
const newStateArray = require_internal_annotations.annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? require_annotation_state.getWrappedChildState(currentContext.state, result.next.state, parser) : s));
|
|
3832
4622
|
const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
|
|
3833
4623
|
currentContext = {
|
|
3834
4624
|
...currentContext,
|
|
@@ -3873,7 +4663,7 @@ function concat(...parsers) {
|
|
|
3873
4663
|
for (const [parser, index] of remainingParsers) {
|
|
3874
4664
|
const result = await parser.parse(withChildContext$1(currentContext, index, stateArray[index], parser));
|
|
3875
4665
|
if (result.success && result.consumed.length > 0) {
|
|
3876
|
-
const newStateArray =
|
|
4666
|
+
const newStateArray = require_internal_annotations.annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? require_annotation_state.getWrappedChildState(currentContext.state, result.next.state, parser) : s));
|
|
3877
4667
|
const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
|
|
3878
4668
|
currentContext = {
|
|
3879
4669
|
...currentContext,
|
|
@@ -3894,7 +4684,7 @@ function concat(...parsers) {
|
|
|
3894
4684
|
if (!foundMatch) for (const [parser, index] of remainingParsers) {
|
|
3895
4685
|
const result = await parser.parse(withChildContext$1(currentContext, index, stateArray[index], parser));
|
|
3896
4686
|
if (result.success && result.consumed.length < 1) {
|
|
3897
|
-
const newStateArray =
|
|
4687
|
+
const newStateArray = require_internal_annotations.annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? require_annotation_state.getWrappedChildState(currentContext.state, result.next.state, parser) : s));
|
|
3898
4688
|
const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
|
|
3899
4689
|
currentContext = {
|
|
3900
4690
|
...currentContext,
|
|
@@ -4033,6 +4823,10 @@ function concat(...parsers) {
|
|
|
4033
4823
|
leadingNames: sharedBufferLeadingNames(parsers),
|
|
4034
4824
|
acceptingAnyToken: parsers.some((p) => p.acceptingAnyToken),
|
|
4035
4825
|
initialState,
|
|
4826
|
+
canSkip(state, exec) {
|
|
4827
|
+
const stateArray = state;
|
|
4828
|
+
return parsers.every((parser, index) => parser.canSkip?.(require_annotation_state.getWrappedChildState(stateArray, stateArray[index], parser), require_execution_context.withChildExecPath(exec, index)) === true);
|
|
4829
|
+
},
|
|
4036
4830
|
parse(context) {
|
|
4037
4831
|
if (isAsync) return parseAsync(context);
|
|
4038
4832
|
return parseSync(context);
|
|
@@ -4165,7 +4959,7 @@ function concat(...parsers) {
|
|
|
4165
4959
|
return { fragments: result };
|
|
4166
4960
|
}
|
|
4167
4961
|
};
|
|
4168
|
-
|
|
4962
|
+
require_internal_parser.defineInheritedAnnotationParser(concatParser);
|
|
4169
4963
|
return concatParser;
|
|
4170
4964
|
}
|
|
4171
4965
|
function group(label, parser, options = {}) {
|
|
@@ -4181,6 +4975,7 @@ function group(label, parser, options = {}) {
|
|
|
4181
4975
|
initialState: parser.initialState,
|
|
4182
4976
|
...fieldParsersKey in parser ? { [fieldParsersKey]: parser[fieldParsersKey] } : {},
|
|
4183
4977
|
...typeof parser.shouldDeferCompletion === "function" ? { shouldDeferCompletion: parser.shouldDeferCompletion.bind(parser) } : {},
|
|
4978
|
+
...typeof parser.canSkip === "function" ? { canSkip: parser.canSkip.bind(parser) } : {},
|
|
4184
4979
|
getSuggestRuntimeNodes(state, path) {
|
|
4185
4980
|
return parser.getSuggestRuntimeNodes?.(state, path) ?? (parser.dependencyMetadata?.source != null ? [{
|
|
4186
4981
|
path,
|
|
@@ -4338,6 +5133,10 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
4338
5133
|
...term,
|
|
4339
5134
|
terms: appendLiteralToUsage(term.terms, literalValue)
|
|
4340
5135
|
});
|
|
5136
|
+
else if (term.type === "sequence") result.push({
|
|
5137
|
+
...term,
|
|
5138
|
+
terms: appendLiteralToUsage(term.terms, literalValue)
|
|
5139
|
+
});
|
|
4341
5140
|
else if (term.type === "exclusive") result.push({
|
|
4342
5141
|
...term,
|
|
4343
5142
|
terms: term.terms.map((t) => appendLiteralToUsage(t, literalValue))
|
|
@@ -5220,7 +6019,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
5220
6019
|
return { fragments };
|
|
5221
6020
|
}
|
|
5222
6021
|
};
|
|
5223
|
-
|
|
6022
|
+
require_internal_parser.defineInheritedAnnotationParser(conditionalParser);
|
|
5224
6023
|
return conditionalParser;
|
|
5225
6024
|
}
|
|
5226
6025
|
|
|
@@ -5233,4 +6032,5 @@ exports.longestMatch = longestMatch;
|
|
|
5233
6032
|
exports.merge = merge;
|
|
5234
6033
|
exports.object = object;
|
|
5235
6034
|
exports.or = or;
|
|
6035
|
+
exports.seq = seq;
|
|
5236
6036
|
exports.tuple = tuple;
|