@optique/core 1.4.0-dev.2607 → 1.4.0-dev.2608
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constructs.cjs +78 -129
- package/dist/constructs.js +78 -129
- package/dist/facade.cjs +74 -7
- package/dist/facade.d.cts +19 -0
- package/dist/facade.d.ts +19 -0
- package/dist/facade.js +72 -5
- package/dist/modifiers.cjs +5 -6
- package/dist/modifiers.js +5 -6
- package/dist/primitives.cjs +13 -57
- package/dist/primitives.d.cts +3 -3
- package/dist/primitives.d.ts +3 -3
- package/dist/primitives.js +13 -57
- package/dist/usage-internals.cjs +0 -73
- package/dist/usage-internals.js +1 -71
- package/package.json +2 -2
- package/skills/optique/SKILL.md +9 -9
- package/dist/short-option.cjs +0 -197
- package/dist/short-option.js +0 -186
package/dist/constructs.js
CHANGED
|
@@ -8,13 +8,12 @@ import { createDependencySourceState, dependencyId, isDependencySourceState, isP
|
|
|
8
8
|
import { buildRuntimeNodesFromArray, buildRuntimeNodesFromPairs, collectExplicitSourceValues, collectExplicitSourceValuesAsync, collectSourcesFromState, completeEffectfulSourcesAsync, createDependencyRuntimeContext, effectfulSchedulingNodesKey, exclusiveSourceScopeKey, extractRawInputFromState, fillMissingSourceDefaults, fillMissingSourceDefaultsAsync, forkRuntimeForCommittedSubtree, getDefaultDependencySnapshot, guaranteedStaticSourceIdsKey, hasInactiveCompletion, isMatchedState, recordSourceScope, releaseUncollectedSourceValues, replaceCachedBarrierFailure, resolveDerivedSourceValues, resolveDerivedSourceValuesAsync, resolveStateWithRuntime, resolveStateWithRuntimeAsync, serializeSchedulingPath, sourceCollectionExpansionKey, staticSourceScopeKey } from "./dependency-runtime.js";
|
|
9
9
|
import { defineInheritedAnnotationParser, defineParseLanes, getOwnParseLanes, getParserSuggestRuntimeNodes, unmatchedNonCliDependencySourceStateMarker } from "./internal/parser.js";
|
|
10
10
|
import { annotationViewTargets, getWrappedChildParseState, getWrappedChildState, reconcileObjectChildState, unwrapAnnotationView } from "./annotation-state.js";
|
|
11
|
-
import { collectLeadingCandidates } from "./usage-internals.js";
|
|
12
|
-
import { adoptOptionScope, combinedOptionScope, conditionalOptionScope, forkOptionScope, restoreOptionScope, scopeParser, selectableOptionScope, withOptionScope, withParserOptionScope } from "./short-option.js";
|
|
13
11
|
import { allowDuplicateLeadingCommandNamesKey } from "./internal/command-alias.js";
|
|
14
12
|
import { mergeChildExec, withChildContext, withChildExecPath } from "./execution-context.js";
|
|
15
13
|
import { completeOrExtractPhase2Seed, extractPhase2Seed, extractPhase2SeedKey, phase2SeedFromValueResult } from "./phase2-seed.js";
|
|
16
14
|
import { fluent } from "./modifiers.js";
|
|
17
15
|
import { DEFAULT_FIND_SIMILAR_OPTIONS, createErrorWithSuggestions, createSuggestionMessage, deduplicateSuggestions, expandCommandAliasSuggestions, findSimilar } from "./suggestion.js";
|
|
16
|
+
import { collectLeadingCandidates } from "./usage-internals.js";
|
|
18
17
|
|
|
19
18
|
//#region src/constructs.ts
|
|
20
19
|
/**
|
|
@@ -49,7 +48,7 @@ function withoutRepublishInstruction(exec) {
|
|
|
49
48
|
}
|
|
50
49
|
function withChildContext$1(context, segment, state, parser, usage) {
|
|
51
50
|
const childState = parser == null ? state : getWrappedChildParseState(context.state, state, parser);
|
|
52
|
-
return withChildContext(
|
|
51
|
+
return withChildContext(context, segment, childState, usage);
|
|
53
52
|
}
|
|
54
53
|
function isUnmatchedDependencyState(state, parser) {
|
|
55
54
|
if (state === void 0) return true;
|
|
@@ -1403,7 +1402,7 @@ function or(...args) {
|
|
|
1403
1402
|
let optionsTerminatorResult = null;
|
|
1404
1403
|
let provisionalAmbiguous = false;
|
|
1405
1404
|
for (const [parser, i] of orderedParsers) {
|
|
1406
|
-
const result = parser.parse(withChildContext$1(
|
|
1405
|
+
const result = parser.parse(withChildContext$1(context, i, activeState == null || activeState[0] !== i || !activeState[1].success ? parser.initialState : activeState[1].next.state, parser));
|
|
1407
1406
|
if (isOptionsTerminatorOnlyResult(context, result)) {
|
|
1408
1407
|
if (activeState?.[0] === i && activeState[1].success && activeState[1].consumed.length > 0 && result.next.buffer.length < 1) return preserveExclusiveStateAfterOptionsTerminator(context, result);
|
|
1409
1408
|
optionsTerminatorResult ??= result;
|
|
@@ -1438,7 +1437,7 @@ function or(...args) {
|
|
|
1438
1437
|
return {
|
|
1439
1438
|
success: true,
|
|
1440
1439
|
next: {
|
|
1441
|
-
...
|
|
1440
|
+
...context,
|
|
1442
1441
|
buffer: result.next.buffer,
|
|
1443
1442
|
optionsTerminated: result.next.optionsTerminated,
|
|
1444
1443
|
state: createExclusiveState(context.state, i, parser, result),
|
|
@@ -1474,7 +1473,7 @@ function or(...args) {
|
|
|
1474
1473
|
return {
|
|
1475
1474
|
success: true,
|
|
1476
1475
|
next: {
|
|
1477
|
-
...
|
|
1476
|
+
...context,
|
|
1478
1477
|
buffer: replayedResult.next.buffer,
|
|
1479
1478
|
optionsTerminated: replayedResult.next.optionsTerminated,
|
|
1480
1479
|
state: createExclusiveState(context.state, i, parser, {
|
|
@@ -1493,7 +1492,7 @@ function or(...args) {
|
|
|
1493
1492
|
return {
|
|
1494
1493
|
success: true,
|
|
1495
1494
|
next: {
|
|
1496
|
-
...
|
|
1495
|
+
...context,
|
|
1497
1496
|
buffer: result.next.buffer,
|
|
1498
1497
|
optionsTerminated: result.next.optionsTerminated,
|
|
1499
1498
|
state: createExclusiveState(context.state, i, parser, result),
|
|
@@ -1519,7 +1518,7 @@ function or(...args) {
|
|
|
1519
1518
|
success: true,
|
|
1520
1519
|
...zeroConsumedBranch.result.provisional ? { provisional: true } : {},
|
|
1521
1520
|
next: {
|
|
1522
|
-
...
|
|
1521
|
+
...context,
|
|
1523
1522
|
state: createExclusiveState(context.state, zeroConsumedBranch.index, zeroConsumedBranch.parser, zeroConsumedBranch.result),
|
|
1524
1523
|
...mergedExec != null ? {
|
|
1525
1524
|
exec: mergedExec,
|
|
@@ -1537,7 +1536,7 @@ function or(...args) {
|
|
|
1537
1536
|
success: true,
|
|
1538
1537
|
provisional: true,
|
|
1539
1538
|
next: {
|
|
1540
|
-
...
|
|
1539
|
+
...context,
|
|
1541
1540
|
buffer: provisionalConsuming.result.next.buffer,
|
|
1542
1541
|
optionsTerminated: provisionalConsuming.result.next.optionsTerminated,
|
|
1543
1542
|
state: createExclusiveState(context.state, provisionalConsuming.index, provisionalConsuming.parser, provisionalConsuming.result),
|
|
@@ -1552,7 +1551,7 @@ function or(...args) {
|
|
|
1552
1551
|
if (activeState != null && activeState[1].success) {
|
|
1553
1552
|
const previouslyConsumed = activeState[1].consumed;
|
|
1554
1553
|
const checkResult = provisionalConsuming.parser.parse({
|
|
1555
|
-
...withChildContext$1(
|
|
1554
|
+
...withChildContext$1(context, provisionalConsuming.index, provisionalConsuming.parser.initialState, provisionalConsuming.parser),
|
|
1556
1555
|
buffer: previouslyConsumed
|
|
1557
1556
|
});
|
|
1558
1557
|
const canConsumeShared = checkResult.success && checkResult.consumed.length === previouslyConsumed.length && checkResult.consumed.every((c, idx) => c === previouslyConsumed[idx]);
|
|
@@ -1571,7 +1570,7 @@ function or(...args) {
|
|
|
1571
1570
|
success: true,
|
|
1572
1571
|
provisional: true,
|
|
1573
1572
|
next: {
|
|
1574
|
-
...
|
|
1573
|
+
...context,
|
|
1575
1574
|
buffer: replayedResult.next.buffer,
|
|
1576
1575
|
optionsTerminated: replayedResult.next.optionsTerminated,
|
|
1577
1576
|
state: createExclusiveState(context.state, provisionalConsuming.index, provisionalConsuming.parser, {
|
|
@@ -1606,7 +1605,7 @@ function or(...args) {
|
|
|
1606
1605
|
let optionsTerminatorResult = null;
|
|
1607
1606
|
let provisionalAmbiguous = false;
|
|
1608
1607
|
for (const [parser, i] of orderedParsers) {
|
|
1609
|
-
const resultOrPromise = parser.parse(withChildContext$1(
|
|
1608
|
+
const resultOrPromise = parser.parse(withChildContext$1(context, i, activeState == null || activeState[0] !== i || !activeState[1].success ? parser.initialState : activeState[1].next.state, parser));
|
|
1610
1609
|
const result = await resultOrPromise;
|
|
1611
1610
|
if (isOptionsTerminatorOnlyResult(context, result)) {
|
|
1612
1611
|
if (activeState?.[0] === i && activeState[1].success && activeState[1].consumed.length > 0 && result.next.buffer.length < 1) return preserveExclusiveStateAfterOptionsTerminator(context, result);
|
|
@@ -1642,7 +1641,7 @@ function or(...args) {
|
|
|
1642
1641
|
return {
|
|
1643
1642
|
success: true,
|
|
1644
1643
|
next: {
|
|
1645
|
-
...
|
|
1644
|
+
...context,
|
|
1646
1645
|
buffer: result.next.buffer,
|
|
1647
1646
|
optionsTerminated: result.next.optionsTerminated,
|
|
1648
1647
|
state: createExclusiveState(context.state, i, parser, result),
|
|
@@ -1680,7 +1679,7 @@ function or(...args) {
|
|
|
1680
1679
|
return {
|
|
1681
1680
|
success: true,
|
|
1682
1681
|
next: {
|
|
1683
|
-
...
|
|
1682
|
+
...context,
|
|
1684
1683
|
buffer: replayedResult.next.buffer,
|
|
1685
1684
|
optionsTerminated: replayedResult.next.optionsTerminated,
|
|
1686
1685
|
state: createExclusiveState(context.state, i, parser, {
|
|
@@ -1699,7 +1698,7 @@ function or(...args) {
|
|
|
1699
1698
|
return {
|
|
1700
1699
|
success: true,
|
|
1701
1700
|
next: {
|
|
1702
|
-
...
|
|
1701
|
+
...context,
|
|
1703
1702
|
buffer: result.next.buffer,
|
|
1704
1703
|
optionsTerminated: result.next.optionsTerminated,
|
|
1705
1704
|
state: createExclusiveState(context.state, i, parser, result),
|
|
@@ -1725,7 +1724,7 @@ function or(...args) {
|
|
|
1725
1724
|
success: true,
|
|
1726
1725
|
...zeroConsumedBranch.result.provisional ? { provisional: true } : {},
|
|
1727
1726
|
next: {
|
|
1728
|
-
...
|
|
1727
|
+
...context,
|
|
1729
1728
|
state: createExclusiveState(context.state, zeroConsumedBranch.index, zeroConsumedBranch.parser, zeroConsumedBranch.result),
|
|
1730
1729
|
...mergedExec != null ? {
|
|
1731
1730
|
exec: mergedExec,
|
|
@@ -1743,7 +1742,7 @@ function or(...args) {
|
|
|
1743
1742
|
success: true,
|
|
1744
1743
|
provisional: true,
|
|
1745
1744
|
next: {
|
|
1746
|
-
...
|
|
1745
|
+
...context,
|
|
1747
1746
|
buffer: provisionalConsuming.result.next.buffer,
|
|
1748
1747
|
optionsTerminated: provisionalConsuming.result.next.optionsTerminated,
|
|
1749
1748
|
state: createExclusiveState(context.state, provisionalConsuming.index, provisionalConsuming.parser, provisionalConsuming.result),
|
|
@@ -1758,7 +1757,7 @@ function or(...args) {
|
|
|
1758
1757
|
if (activeState != null && activeState[1].success) {
|
|
1759
1758
|
const previouslyConsumed = activeState[1].consumed;
|
|
1760
1759
|
const checkResult = await provisionalConsuming.parser.parse({
|
|
1761
|
-
...withChildContext$1(
|
|
1760
|
+
...withChildContext$1(context, provisionalConsuming.index, provisionalConsuming.parser.initialState, provisionalConsuming.parser),
|
|
1762
1761
|
buffer: previouslyConsumed
|
|
1763
1762
|
});
|
|
1764
1763
|
const canConsumeShared = checkResult.success && checkResult.consumed.length === previouslyConsumed.length && checkResult.consumed.every((c, idx) => c === previouslyConsumed[idx]);
|
|
@@ -1777,7 +1776,7 @@ function or(...args) {
|
|
|
1777
1776
|
success: true,
|
|
1778
1777
|
provisional: true,
|
|
1779
1778
|
next: {
|
|
1780
|
-
...
|
|
1779
|
+
...context,
|
|
1781
1780
|
buffer: replayedResult.next.buffer,
|
|
1782
1781
|
optionsTerminated: replayedResult.next.optionsTerminated,
|
|
1783
1782
|
state: createExclusiveState(context.state, provisionalConsuming.index, provisionalConsuming.parser, {
|
|
@@ -1864,7 +1863,7 @@ function or(...args) {
|
|
|
1864
1863
|
if (singleDependencyMetadata != null) singleResult.dependencyMetadata = singleDependencyMetadata;
|
|
1865
1864
|
defineExclusiveSchedulingNodes(singleResult, parsers);
|
|
1866
1865
|
defineInheritedAnnotationParser(singleResult);
|
|
1867
|
-
return fluent(
|
|
1866
|
+
return fluent(singleResult);
|
|
1868
1867
|
}
|
|
1869
1868
|
/**
|
|
1870
1869
|
* @since 0.5.0
|
|
@@ -1913,7 +1912,7 @@ function createLongestMatch(...args) {
|
|
|
1913
1912
|
return {
|
|
1914
1913
|
success: true,
|
|
1915
1914
|
next: {
|
|
1916
|
-
...
|
|
1915
|
+
...context,
|
|
1917
1916
|
buffer: selectedResult.next.buffer,
|
|
1918
1917
|
optionsTerminated: selectedResult.next.optionsTerminated,
|
|
1919
1918
|
state: createExclusiveState(context.state, match.index, parser, selectedResult),
|
|
@@ -1953,7 +1952,7 @@ function createLongestMatch(...args) {
|
|
|
1953
1952
|
const activeState = normalizeExclusiveState(context.state);
|
|
1954
1953
|
for (let i = 0; i < syncParsers.length; i++) {
|
|
1955
1954
|
const parser = syncParsers[i];
|
|
1956
|
-
const childContext = withChildContext$1(
|
|
1955
|
+
const childContext = withChildContext$1(context, i, activeState == null || activeState[0] !== i || !activeState[1].success ? parser.initialState : activeState[1].next.state, parser);
|
|
1957
1956
|
const result = parser.parse(childContext);
|
|
1958
1957
|
if (isOptionsTerminatorOnlyResult(context, result)) {
|
|
1959
1958
|
optionsTerminatorMatches.push({
|
|
@@ -1989,7 +1988,7 @@ function createLongestMatch(...args) {
|
|
|
1989
1988
|
const activeState = normalizeExclusiveState(context.state);
|
|
1990
1989
|
for (let i = 0; i < parsers.length; i++) {
|
|
1991
1990
|
const parser = parsers[i];
|
|
1992
|
-
const childContext = withChildContext$1(
|
|
1991
|
+
const childContext = withChildContext$1(context, i, activeState == null || activeState[0] !== i || !activeState[1].success ? parser.initialState : activeState[1].next.state, parser);
|
|
1993
1992
|
const resultOrPromise = parser.parse(childContext);
|
|
1994
1993
|
const result = await resultOrPromise;
|
|
1995
1994
|
if (isOptionsTerminatorOnlyResult(context, result)) {
|
|
@@ -2080,7 +2079,7 @@ function createLongestMatch(...args) {
|
|
|
2080
2079
|
if (multiDependencyMetadata != null) multiResult.dependencyMetadata = multiDependencyMetadata;
|
|
2081
2080
|
defineExclusiveSchedulingNodes(multiResult, parsers);
|
|
2082
2081
|
defineInheritedAnnotationParser(multiResult);
|
|
2083
|
-
return fluent(
|
|
2082
|
+
return fluent(multiResult);
|
|
2084
2083
|
}
|
|
2085
2084
|
/**
|
|
2086
2085
|
* Creates the initial parse error shared by object-like combinators.
|
|
@@ -3094,15 +3093,15 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
3094
3093
|
});
|
|
3095
3094
|
defineParseLanes(objectParser, objectParseLanes);
|
|
3096
3095
|
defineInheritedAnnotationParser(objectParser);
|
|
3097
|
-
return fluent(
|
|
3096
|
+
return fluent(objectParser);
|
|
3098
3097
|
}
|
|
3099
3098
|
function isParserLike(value) {
|
|
3100
3099
|
return value != null && (typeof value === "object" || typeof value === "function") && "parse" in value && "$valueType" in value && "$stateType" in value;
|
|
3101
3100
|
}
|
|
3102
3101
|
function tokenMatchesLeadingName(token, candidates) {
|
|
3103
3102
|
if (token == null) return false;
|
|
3104
|
-
for (const name of candidates.optionNames) if (token === name
|
|
3105
|
-
for (const name of candidates.joinedOptionNames) if (
|
|
3103
|
+
for (const name of candidates.optionNames) if (token === name) return true;
|
|
3104
|
+
for (const name of candidates.joinedOptionNames) if (name.startsWith("/") && token.startsWith(`${name}:`) || (name.startsWith("--") || name.startsWith("-") && name.length > 2) && token.startsWith(`${name}=`)) return true;
|
|
3106
3105
|
for (const name of candidates.commandNames) if (token === name) return true;
|
|
3107
3106
|
return false;
|
|
3108
3107
|
}
|
|
@@ -3328,7 +3327,6 @@ function advanceSeqSuggestContextSync(context, parsers, initialStates) {
|
|
|
3328
3327
|
while (currentContext.state.index < parsers.length) {
|
|
3329
3328
|
const index = currentContext.state.index;
|
|
3330
3329
|
const parser = parsers[index];
|
|
3331
|
-
currentContext = withParserOptionScope(currentContext, parser);
|
|
3332
3330
|
const parserState = getSeqChildState(currentContext.state, index, parser);
|
|
3333
3331
|
if (currentContext.buffer.length < 1) break;
|
|
3334
3332
|
if (shouldAdvanceSeqBeforeParse(parser, parserState, initialStates[index], currentContext, index, parsers)) {
|
|
@@ -3355,7 +3353,6 @@ async function advanceSeqSuggestContextAsync(context, parsers, initialStates) {
|
|
|
3355
3353
|
while (currentContext.state.index < parsers.length) {
|
|
3356
3354
|
const index = currentContext.state.index;
|
|
3357
3355
|
const parser = parsers[index];
|
|
3358
|
-
currentContext = withParserOptionScope(currentContext, parser);
|
|
3359
3356
|
const parserState = getSeqChildState(currentContext.state, index, parser);
|
|
3360
3357
|
if (currentContext.buffer.length < 1) break;
|
|
3361
3358
|
if (shouldAdvanceSeqBeforeParse(parser, parserState, initialStates[index], currentContext, index, parsers)) {
|
|
@@ -4112,7 +4109,7 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
4112
4109
|
enumerable: false
|
|
4113
4110
|
});
|
|
4114
4111
|
defineInheritedAnnotationParser(tupleParser);
|
|
4115
|
-
return fluent(
|
|
4112
|
+
return fluent(tupleParser);
|
|
4116
4113
|
}
|
|
4117
4114
|
function seq(...rawArgs) {
|
|
4118
4115
|
const label = typeof rawArgs[0] === "string" ? rawArgs[0] : void 0;
|
|
@@ -4130,31 +4127,12 @@ function seq(...rawArgs) {
|
|
|
4130
4127
|
...result,
|
|
4131
4128
|
consumed: consumed.length + result.consumed
|
|
4132
4129
|
});
|
|
4133
|
-
const reachableSeqScope = (context) => {
|
|
4134
|
-
let end = Math.min(context.state.index + 1, parsers.length);
|
|
4135
|
-
while (end < parsers.length) {
|
|
4136
|
-
const index = end - 1;
|
|
4137
|
-
const child = parsers[index];
|
|
4138
|
-
if (context.buffer.length > 0 && !tokenMatchesLeadingName(context.buffer[0], leadingCandidatesAfter(parsers, end))) break;
|
|
4139
|
-
if (!parserCanSkipAt(child, getSeqChildState(context.state, index, child), context.exec, index)) break;
|
|
4140
|
-
end++;
|
|
4141
|
-
}
|
|
4142
|
-
return combinedOptionScope(parsers.slice(0, end));
|
|
4143
|
-
};
|
|
4144
|
-
const seqScope = selectableOptionScope(reachableSeqScope({
|
|
4145
|
-
state: initialState,
|
|
4146
|
-
buffer: [],
|
|
4147
|
-
usage: [],
|
|
4148
|
-
optionsTerminated: false
|
|
4149
|
-
}));
|
|
4150
4130
|
const parseSync = (context) => {
|
|
4151
4131
|
let currentContext = context;
|
|
4152
4132
|
const allConsumed = [];
|
|
4153
4133
|
while (currentContext.state.index < syncParsers.length) {
|
|
4154
4134
|
const index = currentContext.state.index;
|
|
4155
4135
|
const parser = syncParsers[index];
|
|
4156
|
-
seqScope.select(currentContext, reachableSeqScope(currentContext));
|
|
4157
|
-
currentContext = withParserOptionScope(currentContext, parser);
|
|
4158
4136
|
const parserState = getSeqChildState(currentContext.state, index, parser);
|
|
4159
4137
|
if (currentContext.buffer.length < 1) break;
|
|
4160
4138
|
if (shouldAdvanceSeqBeforeParse(parser, parserState, initialState.states[index], currentContext, index, syncParsers)) {
|
|
@@ -4197,8 +4175,6 @@ function seq(...rawArgs) {
|
|
|
4197
4175
|
while (currentContext.state.index < parsers.length) {
|
|
4198
4176
|
const index = currentContext.state.index;
|
|
4199
4177
|
const parser = parsers[index];
|
|
4200
|
-
seqScope.select(currentContext, reachableSeqScope(currentContext));
|
|
4201
|
-
currentContext = withParserOptionScope(currentContext, parser);
|
|
4202
4178
|
const parserState = getSeqChildState(currentContext.state, index, parser);
|
|
4203
4179
|
if (currentContext.buffer.length < 1) break;
|
|
4204
4180
|
if (shouldAdvanceSeqBeforeParse(parser, parserState, initialState.states[index], currentContext, index, parsers)) {
|
|
@@ -4467,9 +4443,7 @@ function seq(...rawArgs) {
|
|
|
4467
4443
|
enumerable: false
|
|
4468
4444
|
});
|
|
4469
4445
|
defineInheritedAnnotationParser(seqParser);
|
|
4470
|
-
return fluent(
|
|
4471
|
-
seqScope.select(context, reachableSeqScope(context));
|
|
4472
|
-
}));
|
|
4446
|
+
return fluent(seqParser);
|
|
4473
4447
|
}
|
|
4474
4448
|
function merge(...args) {
|
|
4475
4449
|
const label = typeof args[0] === "string" ? args[0] : void 0;
|
|
@@ -5463,7 +5437,7 @@ function merge(...args) {
|
|
|
5463
5437
|
};
|
|
5464
5438
|
defineParseLanes(mergeParser, mergeParseLanes);
|
|
5465
5439
|
defineInheritedAnnotationParser(mergeParser);
|
|
5466
|
-
return fluent(
|
|
5440
|
+
return fluent(mergeParser);
|
|
5467
5441
|
}
|
|
5468
5442
|
/**
|
|
5469
5443
|
* Builds a dependency registry from the pre-parsed context state and returns
|
|
@@ -6090,7 +6064,7 @@ function concat(...parsers) {
|
|
|
6090
6064
|
}
|
|
6091
6065
|
};
|
|
6092
6066
|
defineInheritedAnnotationParser(concatParser);
|
|
6093
|
-
return fluent(
|
|
6067
|
+
return fluent(concatParser);
|
|
6094
6068
|
}
|
|
6095
6069
|
function group(label, parser, options = {}) {
|
|
6096
6070
|
validateLabel(label);
|
|
@@ -6200,7 +6174,7 @@ function group(label, parser, options = {}) {
|
|
|
6200
6174
|
configurable: true,
|
|
6201
6175
|
enumerable: false
|
|
6202
6176
|
});
|
|
6203
|
-
return fluent(
|
|
6177
|
+
return fluent(groupParser);
|
|
6204
6178
|
}
|
|
6205
6179
|
/**
|
|
6206
6180
|
* Creates a conditional parser that selects different branch parsers based on
|
|
@@ -6309,7 +6283,6 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
6309
6283
|
const noMatchContext = analyzeNoMatchContext([discriminator, ...allBranchParsers]);
|
|
6310
6284
|
return options?.errors?.noMatch ? typeof options.errors.noMatch === "function" ? options.errors.noMatch(noMatchContext) : options.errors.noMatch : generateNoMatchError(noMatchContext);
|
|
6311
6285
|
};
|
|
6312
|
-
const optionScope = conditionalOptionScope(discriminator, defaultBranch, branchParsers.map(([, p]) => p));
|
|
6313
6286
|
const parseSync = (context) => {
|
|
6314
6287
|
const state = context.state ?? initialState;
|
|
6315
6288
|
const syncDiscriminator = discriminator;
|
|
@@ -6346,12 +6319,10 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
6346
6319
|
const value = completionResult.value;
|
|
6347
6320
|
const branchParser = syncBranches[value];
|
|
6348
6321
|
if (branchParser) {
|
|
6349
|
-
const branchContext = forkOptionScope(context);
|
|
6350
|
-
optionScope.select(branchContext, branchParser);
|
|
6351
6322
|
const discriminatorExec = mergeChildExec(context.exec, discriminatorResult.next.exec);
|
|
6352
6323
|
const branchParseResult = branchParser.parse({
|
|
6353
6324
|
...withChildContext$1({
|
|
6354
|
-
...
|
|
6325
|
+
...context,
|
|
6355
6326
|
...discriminatorExec != null ? {
|
|
6356
6327
|
exec: discriminatorExec,
|
|
6357
6328
|
dependencyRegistry: discriminatorExec.dependencyRegistry
|
|
@@ -6361,7 +6332,6 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
6361
6332
|
optionsTerminated: discriminatorResult.next.optionsTerminated
|
|
6362
6333
|
});
|
|
6363
6334
|
if (branchParseResult.success) {
|
|
6364
|
-
if (discriminatorResult.consumed.length > 0 || branchParseResult.consumed.length > 0) adoptOptionScope(context, branchParseResult.next);
|
|
6365
6335
|
const mergedExec = mergeChildExec(discriminatorExec, branchParseResult.next.exec);
|
|
6366
6336
|
const isProvisional = branchParseResult.provisional || discriminatorResult.consumed.length === 0 && branchParseResult.consumed.length === 0 && (branchParser.leadingNames.size > 0 || branchParser.acceptingAnyToken);
|
|
6367
6337
|
return {
|
|
@@ -6386,29 +6356,26 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
6386
6356
|
consumed: [...discriminatorResult.consumed, ...branchParseResult.consumed]
|
|
6387
6357
|
};
|
|
6388
6358
|
}
|
|
6389
|
-
if (discriminatorResult.consumed.length > 0) {
|
|
6390
|
-
|
|
6391
|
-
|
|
6392
|
-
|
|
6393
|
-
|
|
6394
|
-
|
|
6395
|
-
|
|
6396
|
-
|
|
6397
|
-
|
|
6398
|
-
|
|
6399
|
-
kind: "branch",
|
|
6400
|
-
key: value
|
|
6401
|
-
},
|
|
6402
|
-
branchState: getWrappedChildState(state, branchParser.initialState, branchParser)
|
|
6359
|
+
if (discriminatorResult.consumed.length > 0) return {
|
|
6360
|
+
success: true,
|
|
6361
|
+
next: {
|
|
6362
|
+
...discriminatorResult.next,
|
|
6363
|
+
state: {
|
|
6364
|
+
discriminatorState: annotatedDiscriminatorState,
|
|
6365
|
+
discriminatorValue: value,
|
|
6366
|
+
selectedBranch: {
|
|
6367
|
+
kind: "branch",
|
|
6368
|
+
key: value
|
|
6403
6369
|
},
|
|
6404
|
-
|
|
6405
|
-
exec: discriminatorExec,
|
|
6406
|
-
dependencyRegistry: discriminatorExec.dependencyRegistry
|
|
6407
|
-
} : {}
|
|
6370
|
+
branchState: getWrappedChildState(state, branchParser.initialState, branchParser)
|
|
6408
6371
|
},
|
|
6409
|
-
|
|
6410
|
-
|
|
6411
|
-
|
|
6372
|
+
...discriminatorExec != null ? {
|
|
6373
|
+
exec: discriminatorExec,
|
|
6374
|
+
dependencyRegistry: discriminatorExec.dependencyRegistry
|
|
6375
|
+
} : {}
|
|
6376
|
+
},
|
|
6377
|
+
consumed: discriminatorResult.consumed
|
|
6378
|
+
};
|
|
6412
6379
|
return branchParseResult;
|
|
6413
6380
|
}
|
|
6414
6381
|
}
|
|
@@ -6481,7 +6448,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
6481
6448
|
if (discriminatorResult.consumed.length === 0 && discriminator.mode === "async") {
|
|
6482
6449
|
const discriminatorExec = mergeChildExec(context.exec, discriminatorResult.next.exec);
|
|
6483
6450
|
const speculationContext = {
|
|
6484
|
-
...
|
|
6451
|
+
...context,
|
|
6485
6452
|
buffer: discriminatorResult.next.buffer,
|
|
6486
6453
|
optionsTerminated: discriminatorResult.next.optionsTerminated,
|
|
6487
6454
|
...discriminatorExec != null ? {
|
|
@@ -6495,7 +6462,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
6495
6462
|
let speculativeError;
|
|
6496
6463
|
let ambiguous = false;
|
|
6497
6464
|
for (const [key, bp] of branchParsers) {
|
|
6498
|
-
const branchResult = await bp.parse(withChildContext$1(
|
|
6465
|
+
const branchResult = await bp.parse(withChildContext$1(speculationContext, "_branch", bp.initialState, bp, bp.usage));
|
|
6499
6466
|
if (branchResult.success && branchResult.consumed.length > 0) {
|
|
6500
6467
|
if (branchResult.provisional) {
|
|
6501
6468
|
if (provisionalHit == null && !provisionalAmbiguous) provisionalHit = {
|
|
@@ -6528,12 +6495,11 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
6528
6495
|
if (branchResult.success) {
|
|
6529
6496
|
const annotatedDiscriminatorState$2 = getWrappedChildState(state, discriminatorResult.next.state, discriminator);
|
|
6530
6497
|
const mergedExec = mergeChildExec(discriminatorExec, branchResult.next.exec);
|
|
6531
|
-
optionScope.select(context, bp);
|
|
6532
6498
|
return {
|
|
6533
6499
|
success: true,
|
|
6534
6500
|
provisional: true,
|
|
6535
6501
|
next: {
|
|
6536
|
-
...
|
|
6502
|
+
...branchResult.next,
|
|
6537
6503
|
state: {
|
|
6538
6504
|
...state,
|
|
6539
6505
|
discriminatorState: annotatedDiscriminatorState$2,
|
|
@@ -6555,15 +6521,14 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
6555
6521
|
}
|
|
6556
6522
|
let deferredBranchState = state.branchState;
|
|
6557
6523
|
if (defaultBranch !== void 0 && !ambiguous && !provisionalAmbiguous) {
|
|
6558
|
-
const defaultResult = await defaultBranch.parse(withChildContext$1(
|
|
6524
|
+
const defaultResult = await defaultBranch.parse(withChildContext$1(speculationContext, "_branch", state.branchState ?? defaultBranch.initialState, defaultBranch, defaultBranch.usage));
|
|
6559
6525
|
if (defaultResult.success && defaultResult.consumed.length > 0) {
|
|
6560
6526
|
const defaultExec = mergeChildExec(discriminatorExec ?? context.exec, defaultResult.next.exec);
|
|
6561
|
-
optionScope.select(context, defaultBranch);
|
|
6562
6527
|
return {
|
|
6563
6528
|
success: true,
|
|
6564
6529
|
...defaultResult.provisional ? { provisional: true } : {},
|
|
6565
6530
|
next: {
|
|
6566
|
-
...
|
|
6531
|
+
...defaultResult.next,
|
|
6567
6532
|
state: {
|
|
6568
6533
|
...state,
|
|
6569
6534
|
selectedBranch: { kind: "default" },
|
|
@@ -6586,7 +6551,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
6586
6551
|
success: true,
|
|
6587
6552
|
provisional: true,
|
|
6588
6553
|
next: {
|
|
6589
|
-
...
|
|
6554
|
+
...speculationContext,
|
|
6590
6555
|
state: {
|
|
6591
6556
|
...state,
|
|
6592
6557
|
discriminatorState: annotatedDiscriminatorState$1,
|
|
@@ -6602,12 +6567,10 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
6602
6567
|
const value = completionResult.value;
|
|
6603
6568
|
const branchParser = branches[value];
|
|
6604
6569
|
if (branchParser) {
|
|
6605
|
-
const branchContext = forkOptionScope(context);
|
|
6606
|
-
optionScope.select(branchContext, branchParser);
|
|
6607
6570
|
const discriminatorExec = mergeChildExec(context.exec, discriminatorResult.next.exec);
|
|
6608
6571
|
const branchParseResult = await branchParser.parse({
|
|
6609
6572
|
...withChildContext$1({
|
|
6610
|
-
...
|
|
6573
|
+
...context,
|
|
6611
6574
|
...discriminatorExec != null ? {
|
|
6612
6575
|
exec: discriminatorExec,
|
|
6613
6576
|
dependencyRegistry: discriminatorExec.dependencyRegistry
|
|
@@ -6617,7 +6580,6 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
6617
6580
|
optionsTerminated: discriminatorResult.next.optionsTerminated
|
|
6618
6581
|
});
|
|
6619
6582
|
if (branchParseResult.success) {
|
|
6620
|
-
if (discriminatorResult.consumed.length > 0 || branchParseResult.consumed.length > 0) adoptOptionScope(context, branchParseResult.next);
|
|
6621
6583
|
const mergedExec = mergeChildExec(discriminatorExec, branchParseResult.next.exec);
|
|
6622
6584
|
return {
|
|
6623
6585
|
success: true,
|
|
@@ -6641,29 +6603,26 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
6641
6603
|
consumed: [...discriminatorResult.consumed, ...branchParseResult.consumed]
|
|
6642
6604
|
};
|
|
6643
6605
|
}
|
|
6644
|
-
if (discriminatorResult.consumed.length > 0) {
|
|
6645
|
-
|
|
6646
|
-
|
|
6647
|
-
|
|
6648
|
-
|
|
6649
|
-
|
|
6650
|
-
|
|
6651
|
-
|
|
6652
|
-
|
|
6653
|
-
|
|
6654
|
-
kind: "branch",
|
|
6655
|
-
key: value
|
|
6656
|
-
},
|
|
6657
|
-
branchState: getWrappedChildState(state, branchParser.initialState, branchParser)
|
|
6606
|
+
if (discriminatorResult.consumed.length > 0) return {
|
|
6607
|
+
success: true,
|
|
6608
|
+
next: {
|
|
6609
|
+
...discriminatorResult.next,
|
|
6610
|
+
state: {
|
|
6611
|
+
discriminatorState: annotatedDiscriminatorState,
|
|
6612
|
+
discriminatorValue: value,
|
|
6613
|
+
selectedBranch: {
|
|
6614
|
+
kind: "branch",
|
|
6615
|
+
key: value
|
|
6658
6616
|
},
|
|
6659
|
-
|
|
6660
|
-
exec: discriminatorExec,
|
|
6661
|
-
dependencyRegistry: discriminatorExec.dependencyRegistry
|
|
6662
|
-
} : {}
|
|
6617
|
+
branchState: getWrappedChildState(state, branchParser.initialState, branchParser)
|
|
6663
6618
|
},
|
|
6664
|
-
|
|
6665
|
-
|
|
6666
|
-
|
|
6619
|
+
...discriminatorExec != null ? {
|
|
6620
|
+
exec: discriminatorExec,
|
|
6621
|
+
dependencyRegistry: discriminatorExec.dependencyRegistry
|
|
6622
|
+
} : {}
|
|
6623
|
+
},
|
|
6624
|
+
consumed: discriminatorResult.consumed
|
|
6625
|
+
};
|
|
6667
6626
|
return branchParseResult;
|
|
6668
6627
|
}
|
|
6669
6628
|
}
|
|
@@ -7337,9 +7296,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
7337
7296
|
} : void 0, "_discriminator"));
|
|
7338
7297
|
if (discComplete.success && syncBranches[discComplete.value] !== void 0) {
|
|
7339
7298
|
const resolvedBranch = syncBranches[discComplete.value];
|
|
7340
|
-
|
|
7341
|
-
optionScope.select(branchContext, resolvedBranch);
|
|
7342
|
-
yield* resolvedBranch.suggest(withChildContext$1(branchContext, "_branch", state.branchState ?? resolvedBranch.initialState, resolvedBranch), prefix);
|
|
7299
|
+
yield* resolvedBranch.suggest(withChildContext$1(suggestContext, "_branch", state.branchState ?? resolvedBranch.initialState, resolvedBranch), prefix);
|
|
7343
7300
|
} else if (syncDefaultBranch !== void 0) yield* syncDefaultBranch.suggest(withChildContext$1(suggestContext, "_branch", state.branchState ?? syncDefaultBranch.initialState, syncDefaultBranch), prefix);
|
|
7344
7301
|
} else {
|
|
7345
7302
|
const branchParser = state.selectedBranch.kind === "default" ? syncDefaultBranch : syncBranches[state.selectedBranch.key];
|
|
@@ -7393,9 +7350,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
7393
7350
|
} : void 0, "_discriminator"));
|
|
7394
7351
|
if (discComplete.success && branches[discComplete.value] !== void 0) {
|
|
7395
7352
|
const resolvedBranch = branches[discComplete.value];
|
|
7396
|
-
|
|
7397
|
-
optionScope.select(branchContext, resolvedBranch);
|
|
7398
|
-
yield* resolvedBranch.suggest(withChildContext$1(branchContext, "_branch", state.branchState ?? resolvedBranch.initialState, resolvedBranch), prefix);
|
|
7353
|
+
yield* resolvedBranch.suggest(withChildContext$1(suggestContext, "_branch", state.branchState ?? resolvedBranch.initialState, resolvedBranch), prefix);
|
|
7399
7354
|
discResolved = true;
|
|
7400
7355
|
}
|
|
7401
7356
|
}
|
|
@@ -7546,13 +7501,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
7546
7501
|
configurable: true,
|
|
7547
7502
|
enumerable: false
|
|
7548
7503
|
});
|
|
7549
|
-
return fluent(
|
|
7550
|
-
const selected = context.state?.selectedBranch;
|
|
7551
|
-
if (selected != null) {
|
|
7552
|
-
const branch = selected.kind === "default" ? defaultBranch : branches[selected.key];
|
|
7553
|
-
if (branch != null) optionScope.select(context, branch);
|
|
7554
|
-
}
|
|
7555
|
-
}));
|
|
7504
|
+
return fluent(conditionalParser);
|
|
7556
7505
|
}
|
|
7557
7506
|
|
|
7558
7507
|
//#endregion
|