@optique/core 1.2.8 → 1.2.9
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 +260 -40
- package/dist/constructs.js +260 -40
- package/dist/extension.cjs +17 -0
- package/dist/extension.d.cts +13 -1
- package/dist/extension.d.ts +13 -1
- package/dist/extension.js +17 -1
- package/dist/internal/passthrough.cjs +230 -0
- package/dist/internal/passthrough.js +213 -0
- package/dist/modifiers.cjs +22 -0
- package/dist/modifiers.js +22 -0
- package/dist/primitives.cjs +45 -9
- package/dist/primitives.js +45 -9
- package/dist/suggestion.cjs +3 -1
- package/dist/suggestion.js +3 -1
- package/package.json +2 -2
package/dist/constructs.js
CHANGED
|
@@ -8,6 +8,7 @@ import { createDependencySourceState, dependencyId, isDependencySourceState, isP
|
|
|
8
8
|
import { buildRuntimeNodesFromArray, buildRuntimeNodesFromPairs, collectExplicitSourceValues, collectExplicitSourceValuesAsync, collectSourcesFromState, createDependencyRuntimeContext, fillMissingSourceDefaults, fillMissingSourceDefaultsAsync, resolveStateWithRuntime, resolveStateWithRuntimeAsync } 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 { combineOptionMatches, combinePassThroughPriorities, defineOptionMatch, definePassThroughPriority, delegateKnownCompletion, getKnownCompletion, getOptionMatch, getPassThroughFailureHint, getPassThroughPriority, hasPassThroughUsage, matchesOptionToken, retainConsumingFailure, retainConsumingFailureHint, withPassThroughFailure } from "./internal/passthrough.js";
|
|
11
12
|
import { allowDuplicateLeadingCommandNamesKey } from "./internal/command-alias.js";
|
|
12
13
|
import { mergeChildExec, withChildContext, withChildExecPath } from "./execution-context.js";
|
|
13
14
|
import { completeOrExtractPhase2Seed, extractPhase2Seed, extractPhase2SeedKey, phase2SeedFromValueResult } from "./phase2-seed.js";
|
|
@@ -98,6 +99,63 @@ function sharedBufferLeadingNames(parsers) {
|
|
|
98
99
|
return names.size === 0 ? EMPTY_LEADING_NAMES : names;
|
|
99
100
|
}
|
|
100
101
|
/**
|
|
102
|
+
* Defers capture until a known option at an equal or higher lane priority
|
|
103
|
+
* has been tried.
|
|
104
|
+
* Other siblings retain their relative order, and explicit priorities win.
|
|
105
|
+
*/
|
|
106
|
+
function orderBeforePassThrough(pairs, context, getParser, getState, passThroughParsers) {
|
|
107
|
+
const token = context.buffer[0];
|
|
108
|
+
if (passThroughParsers.size === 0 || context.optionsTerminated || token == null || token === "--" || !/^[-/+]/.test(token)) return pairs;
|
|
109
|
+
const matches = new Map(pairs.map((pair) => [pair, getOptionMatch(getParser(pair), getState(pair), token)]));
|
|
110
|
+
const normalizedOptions = /* @__PURE__ */ new Map();
|
|
111
|
+
const captures = new Map(pairs.flatMap((pair) => {
|
|
112
|
+
if (!passThroughParsers.has(getParser(pair))) return [];
|
|
113
|
+
const priority = getPassThroughPriority(getParser(pair), getState(pair), token);
|
|
114
|
+
const match = matches.get(pair);
|
|
115
|
+
if (match != null && (priority == null || match.priority >= priority)) {
|
|
116
|
+
const unfiltered = getPassThroughPriority(getParser(pair), getState(pair));
|
|
117
|
+
if (priority == null || unfiltered != null && unfiltered > match.priority) normalizedOptions.set(pair, match.priority);
|
|
118
|
+
return [];
|
|
119
|
+
}
|
|
120
|
+
return priority == null ? [] : [[pair, priority]];
|
|
121
|
+
}));
|
|
122
|
+
const matching = pairs.filter((pair) => !captures.has(pair)).flatMap((pair) => {
|
|
123
|
+
const match = matches.get(pair);
|
|
124
|
+
return match == null ? [] : [match];
|
|
125
|
+
});
|
|
126
|
+
const orderedCaptures = [...captures].sort((a, b) => b[1] - a[1]);
|
|
127
|
+
if (matching.length === 0) {
|
|
128
|
+
let captureIndex = 0;
|
|
129
|
+
return pairs.map((pair) => captures.has(pair) ? orderedCaptures[captureIndex++][0] : pair);
|
|
130
|
+
}
|
|
131
|
+
const matchingPriority = Math.max(...matching.map((match) => match.priority));
|
|
132
|
+
const ordinary = pairs.filter((pair) => !captures.has(pair) && !normalizedOptions.has(pair));
|
|
133
|
+
const positions = new Map(pairs.map((pair, index) => [pair, index]));
|
|
134
|
+
for (const [pair, priority] of [...normalizedOptions].sort((a, b) => b[1] - a[1])) {
|
|
135
|
+
let insertion = ordinary.findIndex((candidate) => {
|
|
136
|
+
const match = matches.get(candidate);
|
|
137
|
+
return match != null && (match.priority < priority || match.priority === priority && positions.get(pair) < positions.get(candidate));
|
|
138
|
+
});
|
|
139
|
+
if (insertion < 0) {
|
|
140
|
+
const lastMatch = ordinary.findLastIndex((candidate) => matches.get(candidate) != null);
|
|
141
|
+
insertion = lastMatch >= 0 ? lastMatch + 1 : ordinary.findIndex((candidate) => positions.get(candidate) > positions.get(pair));
|
|
142
|
+
if (insertion < 0) insertion = ordinary.length;
|
|
143
|
+
}
|
|
144
|
+
ordinary.splice(insertion, 0, pair);
|
|
145
|
+
}
|
|
146
|
+
const first = ordinary.findIndex((pair) => matches.get(pair) != null);
|
|
147
|
+
const last = ordinary.findLastIndex((pair) => matches.get(pair) != null);
|
|
148
|
+
const before = orderedCaptures.filter(([, priority]) => priority > matchingPriority).map(([pair]) => pair);
|
|
149
|
+
const after = orderedCaptures.filter(([, priority]) => priority <= matchingPriority).map(([pair]) => pair);
|
|
150
|
+
return [
|
|
151
|
+
...ordinary.slice(0, first),
|
|
152
|
+
...before,
|
|
153
|
+
...ordinary.slice(first, last + 1),
|
|
154
|
+
...after,
|
|
155
|
+
...ordinary.slice(last + 1)
|
|
156
|
+
];
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
101
159
|
* Internal symbol for exposing field-level parser pairs from `object()`
|
|
102
160
|
* and `merge()` parsers. This allows `merge()` to pre-complete dependency
|
|
103
161
|
* source fields from child parsers before resolving deferred states.
|
|
@@ -599,6 +657,7 @@ function preserveExclusiveStateAfterOptionsTerminator(context, result) {
|
|
|
599
657
|
success: true,
|
|
600
658
|
next: {
|
|
601
659
|
...context,
|
|
660
|
+
...getPassThroughFailureHint(result.next),
|
|
602
661
|
buffer: result.next.buffer,
|
|
603
662
|
optionsTerminated: true,
|
|
604
663
|
state: context.state,
|
|
@@ -887,6 +946,7 @@ function or(...args) {
|
|
|
887
946
|
success: true,
|
|
888
947
|
next: {
|
|
889
948
|
...context,
|
|
949
|
+
...getPassThroughFailureHint(result.next),
|
|
890
950
|
buffer: result.next.buffer,
|
|
891
951
|
optionsTerminated: result.next.optionsTerminated,
|
|
892
952
|
state: createExclusiveState(context.state, i, parser, result),
|
|
@@ -923,6 +983,7 @@ function or(...args) {
|
|
|
923
983
|
success: true,
|
|
924
984
|
next: {
|
|
925
985
|
...context,
|
|
986
|
+
...getPassThroughFailureHint(replayedResult.next),
|
|
926
987
|
buffer: replayedResult.next.buffer,
|
|
927
988
|
optionsTerminated: replayedResult.next.optionsTerminated,
|
|
928
989
|
state: createExclusiveState(context.state, i, parser, {
|
|
@@ -942,6 +1003,7 @@ function or(...args) {
|
|
|
942
1003
|
success: true,
|
|
943
1004
|
next: {
|
|
944
1005
|
...context,
|
|
1006
|
+
...getPassThroughFailureHint(result.next),
|
|
945
1007
|
buffer: result.next.buffer,
|
|
946
1008
|
optionsTerminated: result.next.optionsTerminated,
|
|
947
1009
|
state: createExclusiveState(context.state, i, parser, result),
|
|
@@ -986,6 +1048,7 @@ function or(...args) {
|
|
|
986
1048
|
provisional: true,
|
|
987
1049
|
next: {
|
|
988
1050
|
...context,
|
|
1051
|
+
...getPassThroughFailureHint(provisionalConsuming.result.next),
|
|
989
1052
|
buffer: provisionalConsuming.result.next.buffer,
|
|
990
1053
|
optionsTerminated: provisionalConsuming.result.next.optionsTerminated,
|
|
991
1054
|
state: createExclusiveState(context.state, provisionalConsuming.index, provisionalConsuming.parser, provisionalConsuming.result),
|
|
@@ -1020,6 +1083,7 @@ function or(...args) {
|
|
|
1020
1083
|
provisional: true,
|
|
1021
1084
|
next: {
|
|
1022
1085
|
...context,
|
|
1086
|
+
...getPassThroughFailureHint(replayedResult.next),
|
|
1023
1087
|
buffer: replayedResult.next.buffer,
|
|
1024
1088
|
optionsTerminated: replayedResult.next.optionsTerminated,
|
|
1025
1089
|
state: createExclusiveState(context.state, provisionalConsuming.index, provisionalConsuming.parser, {
|
|
@@ -1091,6 +1155,7 @@ function or(...args) {
|
|
|
1091
1155
|
success: true,
|
|
1092
1156
|
next: {
|
|
1093
1157
|
...context,
|
|
1158
|
+
...getPassThroughFailureHint(result.next),
|
|
1094
1159
|
buffer: result.next.buffer,
|
|
1095
1160
|
optionsTerminated: result.next.optionsTerminated,
|
|
1096
1161
|
state: createExclusiveState(context.state, i, parser, result),
|
|
@@ -1129,6 +1194,7 @@ function or(...args) {
|
|
|
1129
1194
|
success: true,
|
|
1130
1195
|
next: {
|
|
1131
1196
|
...context,
|
|
1197
|
+
...getPassThroughFailureHint(replayedResult.next),
|
|
1132
1198
|
buffer: replayedResult.next.buffer,
|
|
1133
1199
|
optionsTerminated: replayedResult.next.optionsTerminated,
|
|
1134
1200
|
state: createExclusiveState(context.state, i, parser, {
|
|
@@ -1148,6 +1214,7 @@ function or(...args) {
|
|
|
1148
1214
|
success: true,
|
|
1149
1215
|
next: {
|
|
1150
1216
|
...context,
|
|
1217
|
+
...getPassThroughFailureHint(result.next),
|
|
1151
1218
|
buffer: result.next.buffer,
|
|
1152
1219
|
optionsTerminated: result.next.optionsTerminated,
|
|
1153
1220
|
state: createExclusiveState(context.state, i, parser, result),
|
|
@@ -1192,6 +1259,7 @@ function or(...args) {
|
|
|
1192
1259
|
provisional: true,
|
|
1193
1260
|
next: {
|
|
1194
1261
|
...context,
|
|
1262
|
+
...getPassThroughFailureHint(provisionalConsuming.result.next),
|
|
1195
1263
|
buffer: provisionalConsuming.result.next.buffer,
|
|
1196
1264
|
optionsTerminated: provisionalConsuming.result.next.optionsTerminated,
|
|
1197
1265
|
state: createExclusiveState(context.state, provisionalConsuming.index, provisionalConsuming.parser, provisionalConsuming.result),
|
|
@@ -1226,6 +1294,7 @@ function or(...args) {
|
|
|
1226
1294
|
provisional: true,
|
|
1227
1295
|
next: {
|
|
1228
1296
|
...context,
|
|
1297
|
+
...getPassThroughFailureHint(replayedResult.next),
|
|
1229
1298
|
buffer: replayedResult.next.buffer,
|
|
1230
1299
|
optionsTerminated: replayedResult.next.optionsTerminated,
|
|
1231
1300
|
state: createExclusiveState(context.state, provisionalConsuming.index, provisionalConsuming.parser, {
|
|
@@ -1311,6 +1380,14 @@ function or(...args) {
|
|
|
1311
1380
|
const singleDependencyMetadata = composeExclusiveDependencyMetadata(parsers);
|
|
1312
1381
|
if (singleDependencyMetadata != null) singleResult.dependencyMetadata = singleDependencyMetadata;
|
|
1313
1382
|
defineInheritedAnnotationParser(singleResult);
|
|
1383
|
+
defineOptionMatch(singleResult, (state, token) => combineOptionMatches(parsers.map((parser, index) => {
|
|
1384
|
+
const active = normalizeExclusiveState(state);
|
|
1385
|
+
return getOptionMatch(parser, active?.[0] === index && active[1].success ? active[1].next.state : parser.initialState, token);
|
|
1386
|
+
})));
|
|
1387
|
+
definePassThroughPriority(singleResult, parsers, (state, token) => {
|
|
1388
|
+
const active = normalizeExclusiveState(state);
|
|
1389
|
+
return combinePassThroughPriorities(parsers.map((parser, index) => getPassThroughPriority(parser, active?.[0] === index && active[1].success ? active[1].next.state : parser.initialState, token)));
|
|
1390
|
+
});
|
|
1314
1391
|
return fluent(singleResult);
|
|
1315
1392
|
}
|
|
1316
1393
|
/**
|
|
@@ -1345,24 +1422,27 @@ function createLongestMatch(...args) {
|
|
|
1345
1422
|
return createUnexpectedInputErrorWithScopedSuggestions(defaultMsg, token, parsers, options?.errors?.suggestions);
|
|
1346
1423
|
})()
|
|
1347
1424
|
});
|
|
1348
|
-
const commitLongestMatch = (context, match, optionsTerminatorResult) => {
|
|
1425
|
+
const commitLongestMatch = (context, match, optionsTerminatorResult, consumingFailure) => {
|
|
1349
1426
|
const selectedResult = optionsTerminatorResult == null ? match.result : {
|
|
1350
1427
|
...match.result,
|
|
1351
1428
|
next: {
|
|
1352
1429
|
...match.result.next,
|
|
1430
|
+
...getPassThroughFailureHint(optionsTerminatorResult.next),
|
|
1353
1431
|
buffer: optionsTerminatorResult.next.buffer,
|
|
1354
1432
|
optionsTerminated: true
|
|
1355
1433
|
},
|
|
1356
1434
|
consumed: [...optionsTerminatorResult.consumed, ...match.result.consumed]
|
|
1357
1435
|
};
|
|
1436
|
+
const next = selectedResult.consumed.length === 0 ? withPassThroughFailure(selectedResult.next, consumingFailure) : selectedResult.next;
|
|
1358
1437
|
const parser = parsers[match.index];
|
|
1359
|
-
const mergedExec = mergeChildExec(context.exec,
|
|
1438
|
+
const mergedExec = mergeChildExec(context.exec, next.exec);
|
|
1360
1439
|
return {
|
|
1361
1440
|
success: true,
|
|
1362
1441
|
next: {
|
|
1363
1442
|
...context,
|
|
1364
|
-
|
|
1365
|
-
|
|
1443
|
+
...getPassThroughFailureHint(next),
|
|
1444
|
+
buffer: next.buffer,
|
|
1445
|
+
optionsTerminated: next.optionsTerminated,
|
|
1366
1446
|
state: createExclusiveState(context.state, match.index, parser, selectedResult),
|
|
1367
1447
|
...mergedExec != null ? {
|
|
1368
1448
|
exec: mergedExec,
|
|
@@ -1397,6 +1477,7 @@ function createLongestMatch(...args) {
|
|
|
1397
1477
|
let bestMatch = null;
|
|
1398
1478
|
const optionsTerminatorMatches = [];
|
|
1399
1479
|
let error = getInitialError(context);
|
|
1480
|
+
let consumingFailure;
|
|
1400
1481
|
const activeState = normalizeExclusiveState(context.state);
|
|
1401
1482
|
for (let i = 0; i < syncParsers.length; i++) {
|
|
1402
1483
|
const parser = syncParsers[i];
|
|
@@ -1412,6 +1493,7 @@ function createLongestMatch(...args) {
|
|
|
1412
1493
|
continue;
|
|
1413
1494
|
}
|
|
1414
1495
|
if (result.success) {
|
|
1496
|
+
consumingFailure = retainConsumingFailureHint(consumingFailure, context, result.next);
|
|
1415
1497
|
const consumed = context.buffer.length - result.next.buffer.length;
|
|
1416
1498
|
const bestIsProvisional = bestMatch != null && bestMatch.result.success && !!bestMatch.result.provisional;
|
|
1417
1499
|
if (bestMatch === null || consumed > bestMatch.consumed || consumed === bestMatch.consumed && bestIsProvisional && !result.provisional) bestMatch = {
|
|
@@ -1419,11 +1501,15 @@ function createLongestMatch(...args) {
|
|
|
1419
1501
|
result,
|
|
1420
1502
|
consumed
|
|
1421
1503
|
};
|
|
1422
|
-
} else
|
|
1504
|
+
} else {
|
|
1505
|
+
const match = getOptionMatch(parser, childContext.state, context.buffer[0]);
|
|
1506
|
+
if (result.consumed > 0 && match != null) consumingFailure = retainConsumingFailure(consumingFailure, result, match.priority);
|
|
1507
|
+
if (error.consumed < result.consumed) error = result;
|
|
1508
|
+
}
|
|
1423
1509
|
}
|
|
1424
1510
|
const optionsTerminatorResolution = resolveLongestMatchOptionsTerminator(context, bestMatch, optionsTerminatorMatches);
|
|
1425
1511
|
if (optionsTerminatorResolution != null) return optionsTerminatorResolution;
|
|
1426
|
-
if (bestMatch != null) return commitLongestMatch(context, bestMatch);
|
|
1512
|
+
if (bestMatch != null) return commitLongestMatch(context, bestMatch, void 0, consumingFailure);
|
|
1427
1513
|
return {
|
|
1428
1514
|
...error,
|
|
1429
1515
|
success: false
|
|
@@ -1433,6 +1519,7 @@ function createLongestMatch(...args) {
|
|
|
1433
1519
|
let bestMatch = null;
|
|
1434
1520
|
const optionsTerminatorMatches = [];
|
|
1435
1521
|
let error = getInitialError(context);
|
|
1522
|
+
let consumingFailure;
|
|
1436
1523
|
const activeState = normalizeExclusiveState(context.state);
|
|
1437
1524
|
for (let i = 0; i < parsers.length; i++) {
|
|
1438
1525
|
const parser = parsers[i];
|
|
@@ -1449,6 +1536,7 @@ function createLongestMatch(...args) {
|
|
|
1449
1536
|
continue;
|
|
1450
1537
|
}
|
|
1451
1538
|
if (result.success) {
|
|
1539
|
+
consumingFailure = retainConsumingFailureHint(consumingFailure, context, result.next);
|
|
1452
1540
|
const consumed = context.buffer.length - result.next.buffer.length;
|
|
1453
1541
|
const bestIsProvisional = bestMatch != null && bestMatch.result.success && !!bestMatch.result.provisional;
|
|
1454
1542
|
if (bestMatch === null || consumed > bestMatch.consumed || consumed === bestMatch.consumed && bestIsProvisional && !result.provisional) bestMatch = {
|
|
@@ -1456,11 +1544,15 @@ function createLongestMatch(...args) {
|
|
|
1456
1544
|
result,
|
|
1457
1545
|
consumed
|
|
1458
1546
|
};
|
|
1459
|
-
} else
|
|
1547
|
+
} else {
|
|
1548
|
+
const match = getOptionMatch(parser, childContext.state, context.buffer[0]);
|
|
1549
|
+
if (result.consumed > 0 && match != null) consumingFailure = retainConsumingFailure(consumingFailure, result, match.priority);
|
|
1550
|
+
if (error.consumed < result.consumed) error = result;
|
|
1551
|
+
}
|
|
1460
1552
|
}
|
|
1461
1553
|
const optionsTerminatorResolution = resolveLongestMatchOptionsTerminator(context, bestMatch, optionsTerminatorMatches);
|
|
1462
1554
|
if (optionsTerminatorResolution != null) return optionsTerminatorResolution;
|
|
1463
|
-
if (bestMatch != null) return commitLongestMatch(context, bestMatch);
|
|
1555
|
+
if (bestMatch != null) return commitLongestMatch(context, bestMatch, void 0, consumingFailure);
|
|
1464
1556
|
return {
|
|
1465
1557
|
...error,
|
|
1466
1558
|
success: false
|
|
@@ -1526,6 +1618,14 @@ function createLongestMatch(...args) {
|
|
|
1526
1618
|
const multiDependencyMetadata = composeExclusiveDependencyMetadata(parsers);
|
|
1527
1619
|
if (multiDependencyMetadata != null) multiResult.dependencyMetadata = multiDependencyMetadata;
|
|
1528
1620
|
defineInheritedAnnotationParser(multiResult);
|
|
1621
|
+
defineOptionMatch(multiResult, (state, token) => combineOptionMatches(parsers.map((parser, index) => {
|
|
1622
|
+
const active = normalizeExclusiveState(state);
|
|
1623
|
+
return getOptionMatch(parser, active?.[0] === index && active[1].success ? active[1].next.state : parser.initialState, token);
|
|
1624
|
+
})));
|
|
1625
|
+
definePassThroughPriority(multiResult, parsers, (state, token) => {
|
|
1626
|
+
const active = normalizeExclusiveState(state);
|
|
1627
|
+
return combinePassThroughPriorities(parsers.map((parser, index) => getPassThroughPriority(parser, active?.[0] === index && active[1].success ? active[1].next.state : parser.initialState, token)));
|
|
1628
|
+
});
|
|
1529
1629
|
return fluent(multiResult);
|
|
1530
1630
|
}
|
|
1531
1631
|
/**
|
|
@@ -1916,6 +2016,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
1916
2016
|
const parserKeys = Reflect.ownKeys(parsers);
|
|
1917
2017
|
const parserPairs = parserKeys.map((k) => [k, parsers[k]]);
|
|
1918
2018
|
parserPairs.sort(([_, parserA], [__, parserB]) => parserB.priority - parserA.priority);
|
|
2019
|
+
const passThroughParsers = new Set(parserPairs.map(([, parser]) => parser).filter((parser) => hasPassThroughUsage(parser.usage)));
|
|
1919
2020
|
const createInitialState = () => {
|
|
1920
2021
|
const state = {};
|
|
1921
2022
|
for (const key of parserKeys) state[key] = parsers[key].initialState;
|
|
@@ -1965,6 +2066,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
1965
2066
|
success: true,
|
|
1966
2067
|
next: {
|
|
1967
2068
|
...context,
|
|
2069
|
+
...getPassThroughFailureHint(result.next),
|
|
1968
2070
|
buffer: result.next.buffer,
|
|
1969
2071
|
optionsTerminated: result.next.optionsTerminated,
|
|
1970
2072
|
state: nextState,
|
|
@@ -2001,16 +2103,19 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
2001
2103
|
let anySuccess = false;
|
|
2002
2104
|
const allConsumed = [];
|
|
2003
2105
|
const consumedFields = /* @__PURE__ */ new Set();
|
|
2106
|
+
let consumingFailure;
|
|
2004
2107
|
let madeProgress = true;
|
|
2005
2108
|
while (madeProgress && currentContext.buffer.length > 0) {
|
|
2006
2109
|
madeProgress = false;
|
|
2110
|
+
consumingFailure = void 0;
|
|
2007
2111
|
const getFieldState = createFieldStateGetter(currentContext.state, getObjectParseChildState);
|
|
2008
|
-
for (const [field, parser] of parserPairs) {
|
|
2009
|
-
const result = parser.parse(withChildContext$1(currentContext, field, getFieldState(field, parser), parser));
|
|
2112
|
+
for (const [field, parser] of orderBeforePassThrough(parserPairs, currentContext, ([, parser$1]) => parser$1, ([field$1, parser$1]) => getFieldState(field$1, parser$1), passThroughParsers)) {
|
|
2113
|
+
const result = parser.parse(withPassThroughFailure(withChildContext$1(currentContext, field, getFieldState(field, parser), parser), consumingFailure, getPassThroughPriority(parser, getFieldState(field, parser), currentContext.buffer[0])));
|
|
2010
2114
|
if (result.success && result.consumed.length > 0) {
|
|
2011
2115
|
const mergedExec = mergeChildExec(currentContext.exec, result.next.exec);
|
|
2012
2116
|
currentContext = {
|
|
2013
2117
|
...currentContext,
|
|
2118
|
+
...getPassThroughFailureHint(result.next),
|
|
2014
2119
|
buffer: result.next.buffer,
|
|
2015
2120
|
optionsTerminated: result.next.optionsTerminated,
|
|
2016
2121
|
state: {
|
|
@@ -2028,7 +2133,12 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
2028
2133
|
madeProgress = true;
|
|
2029
2134
|
consumedFields.add(field);
|
|
2030
2135
|
break;
|
|
2031
|
-
} else if (
|
|
2136
|
+
} else if (result.success) consumingFailure = retainConsumingFailureHint(consumingFailure, currentContext, result.next);
|
|
2137
|
+
else {
|
|
2138
|
+
const match = getOptionMatch(parser, getFieldState(field, parser), currentContext.buffer[0]);
|
|
2139
|
+
if (result.consumed > 0 && match != null) consumingFailure = retainConsumingFailure(consumingFailure, result, match.priority);
|
|
2140
|
+
if (error.consumed < result.consumed) error = result;
|
|
2141
|
+
}
|
|
2032
2142
|
}
|
|
2033
2143
|
}
|
|
2034
2144
|
{
|
|
@@ -2038,7 +2148,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
2038
2148
|
const typedParser = parser;
|
|
2039
2149
|
if (parser.leadingNames.size > 0 || typedParser.acceptingAnyToken) continue;
|
|
2040
2150
|
const fieldState = getFieldState(field, parser);
|
|
2041
|
-
const result = typedParser.parse(withChildContext$1(currentContext, field, fieldState, parser));
|
|
2151
|
+
const result = typedParser.parse(withPassThroughFailure(withChildContext$1(currentContext, field, fieldState, parser), consumingFailure, getPassThroughPriority(parser, getFieldState(field, parser), currentContext.buffer[0])));
|
|
2042
2152
|
if (result.success && result.consumed.length === 0 && result.next.state !== fieldState) {
|
|
2043
2153
|
const mergedExec = mergeChildExec(currentContext.exec, result.next.exec);
|
|
2044
2154
|
currentContext = {
|
|
@@ -2058,7 +2168,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
2058
2168
|
}
|
|
2059
2169
|
if (anySuccess) return {
|
|
2060
2170
|
success: true,
|
|
2061
|
-
next: currentContext,
|
|
2171
|
+
next: withPassThroughFailure(currentContext, consumingFailure),
|
|
2062
2172
|
consumed: allConsumed
|
|
2063
2173
|
};
|
|
2064
2174
|
if (currentContext.buffer.length === 0) {
|
|
@@ -2107,17 +2217,20 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
2107
2217
|
let anySuccess = false;
|
|
2108
2218
|
const allConsumed = [];
|
|
2109
2219
|
const consumedFields = /* @__PURE__ */ new Set();
|
|
2220
|
+
let consumingFailure;
|
|
2110
2221
|
let madeProgress = true;
|
|
2111
2222
|
while (madeProgress && currentContext.buffer.length > 0) {
|
|
2112
2223
|
madeProgress = false;
|
|
2224
|
+
consumingFailure = void 0;
|
|
2113
2225
|
const getFieldState = createFieldStateGetter(currentContext.state, getObjectParseChildState);
|
|
2114
|
-
for (const [field, parser] of parserPairs) {
|
|
2115
|
-
const resultOrPromise = parser.parse(withChildContext$1(currentContext, field, getFieldState(field, parser), parser));
|
|
2226
|
+
for (const [field, parser] of orderBeforePassThrough(parserPairs, currentContext, ([, parser$1]) => parser$1, ([field$1, parser$1]) => getFieldState(field$1, parser$1), passThroughParsers)) {
|
|
2227
|
+
const resultOrPromise = parser.parse(withPassThroughFailure(withChildContext$1(currentContext, field, getFieldState(field, parser), parser), consumingFailure, getPassThroughPriority(parser, getFieldState(field, parser), currentContext.buffer[0])));
|
|
2116
2228
|
const result = await resultOrPromise;
|
|
2117
2229
|
if (result.success && result.consumed.length > 0) {
|
|
2118
2230
|
const mergedExec = mergeChildExec(currentContext.exec, result.next.exec);
|
|
2119
2231
|
currentContext = {
|
|
2120
2232
|
...currentContext,
|
|
2233
|
+
...getPassThroughFailureHint(result.next),
|
|
2121
2234
|
buffer: result.next.buffer,
|
|
2122
2235
|
optionsTerminated: result.next.optionsTerminated,
|
|
2123
2236
|
state: {
|
|
@@ -2135,7 +2248,12 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
2135
2248
|
madeProgress = true;
|
|
2136
2249
|
consumedFields.add(field);
|
|
2137
2250
|
break;
|
|
2138
|
-
} else if (
|
|
2251
|
+
} else if (result.success) consumingFailure = retainConsumingFailureHint(consumingFailure, currentContext, result.next);
|
|
2252
|
+
else {
|
|
2253
|
+
const match = getOptionMatch(parser, getFieldState(field, parser), currentContext.buffer[0]);
|
|
2254
|
+
if (result.consumed > 0 && match != null) consumingFailure = retainConsumingFailure(consumingFailure, result, match.priority);
|
|
2255
|
+
if (error.consumed < result.consumed) error = result;
|
|
2256
|
+
}
|
|
2139
2257
|
}
|
|
2140
2258
|
}
|
|
2141
2259
|
{
|
|
@@ -2144,7 +2262,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
2144
2262
|
if (consumedFields.has(field)) continue;
|
|
2145
2263
|
if (parser.leadingNames.size > 0 || parser.acceptingAnyToken) continue;
|
|
2146
2264
|
const fieldState = getFieldState(field, parser);
|
|
2147
|
-
const resultOrPromise = parser.parse(withChildContext$1(currentContext, field, fieldState, parser));
|
|
2265
|
+
const resultOrPromise = parser.parse(withPassThroughFailure(withChildContext$1(currentContext, field, fieldState, parser), consumingFailure, getPassThroughPriority(parser, getFieldState(field, parser), currentContext.buffer[0])));
|
|
2148
2266
|
const result = await resultOrPromise;
|
|
2149
2267
|
if (result.success && result.consumed.length === 0 && result.next.state !== fieldState) {
|
|
2150
2268
|
const mergedExec = mergeChildExec(currentContext.exec, result.next.exec);
|
|
@@ -2165,7 +2283,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
2165
2283
|
}
|
|
2166
2284
|
if (anySuccess) return {
|
|
2167
2285
|
success: true,
|
|
2168
|
-
next: currentContext,
|
|
2286
|
+
next: withPassThroughFailure(currentContext, consumingFailure),
|
|
2169
2287
|
consumed: allConsumed
|
|
2170
2288
|
};
|
|
2171
2289
|
if (currentContext.buffer.length === 0) {
|
|
@@ -2515,6 +2633,8 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
2515
2633
|
});
|
|
2516
2634
|
defineParseLanes(objectParser, objectParseLanes);
|
|
2517
2635
|
defineInheritedAnnotationParser(objectParser);
|
|
2636
|
+
defineOptionMatch(objectParser, (state, token) => combineOptionMatches(parserPairs.map(([field, parser]) => getOptionMatch(parser, getAnnotatedFieldState(state, typeof field === "number" ? String(field) : field, parser), token))));
|
|
2637
|
+
definePassThroughPriority(objectParser, parserPairs.map(([, parser]) => parser), (state, token) => combinePassThroughPriorities(parserPairs.map(([field, parser]) => getPassThroughPriority(parser, getAnnotatedFieldState(state, typeof field === "number" ? String(field) : field, parser), token))));
|
|
2518
2638
|
return fluent(objectParser);
|
|
2519
2639
|
}
|
|
2520
2640
|
function isParserLike(value) {
|
|
@@ -2965,6 +3085,7 @@ function advanceTupleSuggestContextSync(context, parsers) {
|
|
|
2965
3085
|
const mergedExec = mergeChildExec(currentContext.exec, result.next.exec);
|
|
2966
3086
|
currentContext = {
|
|
2967
3087
|
...currentContext,
|
|
3088
|
+
...getPassThroughFailureHint(result.next),
|
|
2968
3089
|
buffer: result.next.buffer,
|
|
2969
3090
|
optionsTerminated: result.next.optionsTerminated,
|
|
2970
3091
|
state: newStateArray,
|
|
@@ -3031,6 +3152,7 @@ async function advanceTupleSuggestContextAsync(context, parsers) {
|
|
|
3031
3152
|
const mergedExec = mergeChildExec(currentContext.exec, result.next.exec);
|
|
3032
3153
|
currentContext = {
|
|
3033
3154
|
...currentContext,
|
|
3155
|
+
...getPassThroughFailureHint(result.next),
|
|
3034
3156
|
buffer: result.next.buffer,
|
|
3035
3157
|
optionsTerminated: result.next.optionsTerminated,
|
|
3036
3158
|
state: newStateArray,
|
|
@@ -3130,10 +3252,12 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
3130
3252
|
const combinedMode = parsers.some((p) => p.mode === "async") ? "async" : "sync";
|
|
3131
3253
|
const syncParsers = parsers;
|
|
3132
3254
|
if (!options.allowDuplicates) checkDuplicateOptionNames(parsers.map((parser, index) => [String(index), parser.usage]));
|
|
3255
|
+
const passThroughParsers = new Set(parsers.filter((parser) => hasPassThroughUsage(parser.usage)));
|
|
3133
3256
|
const parseSync = (context) => {
|
|
3134
3257
|
let currentContext = context;
|
|
3135
3258
|
const allConsumed = [];
|
|
3136
3259
|
const matchedParsers = /* @__PURE__ */ new Set();
|
|
3260
|
+
let consumingFailure;
|
|
3137
3261
|
while (matchedParsers.size < syncParsers.length) {
|
|
3138
3262
|
let foundMatch = false;
|
|
3139
3263
|
let error = {
|
|
@@ -3141,14 +3265,15 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
3141
3265
|
error: message`No remaining parsers could match the input.`
|
|
3142
3266
|
};
|
|
3143
3267
|
const stateArray = currentContext.state;
|
|
3144
|
-
const remainingParsers = syncParsers.map((parser, index) => [parser, index]).filter(([
|
|
3268
|
+
const remainingParsers = orderBeforePassThrough(syncParsers.map((parser, index) => [parser, index]).filter(([parser, index]) => !matchedParsers.has(index) || getOptionMatch(parser, stateArray[index], currentContext.buffer[0])?.continuesCommand === true || passThroughParsers.size > 0 && !currentContext.optionsTerminated && getOptionMatch(parser, stateArray[index], currentContext.buffer[0]) != null).sort(([parserA], [parserB]) => parserB.priority - parserA.priority), currentContext, ([parser]) => parser, ([, index]) => stateArray[index], passThroughParsers);
|
|
3145
3269
|
for (const [parser, index] of remainingParsers) {
|
|
3146
|
-
const result = parser.parse(withChildContext$1(currentContext, index, stateArray[index], parser));
|
|
3270
|
+
const result = parser.parse(withPassThroughFailure(withChildContext$1(currentContext, index, stateArray[index], parser), consumingFailure, getPassThroughPriority(parser, stateArray[index], currentContext.buffer[0])));
|
|
3147
3271
|
if (result.success && result.consumed.length > 0) {
|
|
3148
3272
|
const newStateArray = annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? getWrappedChildState(currentContext.state, result.next.state, parser) : s));
|
|
3149
3273
|
const mergedExec = mergeChildExec(currentContext.exec, result.next.exec);
|
|
3150
3274
|
currentContext = {
|
|
3151
3275
|
...currentContext,
|
|
3276
|
+
...getPassThroughFailureHint(result.next),
|
|
3152
3277
|
buffer: result.next.buffer,
|
|
3153
3278
|
optionsTerminated: result.next.optionsTerminated,
|
|
3154
3279
|
state: newStateArray,
|
|
@@ -3157,14 +3282,21 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
3157
3282
|
dependencyRegistry: mergedExec.dependencyRegistry
|
|
3158
3283
|
} : {}
|
|
3159
3284
|
};
|
|
3285
|
+
consumingFailure = void 0;
|
|
3160
3286
|
allConsumed.push(...result.consumed);
|
|
3161
3287
|
matchedParsers.add(index);
|
|
3162
3288
|
foundMatch = true;
|
|
3163
3289
|
break;
|
|
3164
|
-
} else if (
|
|
3290
|
+
} else if (result.success) consumingFailure = retainConsumingFailureHint(consumingFailure, currentContext, result.next);
|
|
3291
|
+
else {
|
|
3292
|
+
const match = getOptionMatch(parser, stateArray[index], currentContext.buffer[0]);
|
|
3293
|
+
if (result.consumed > 0 && match != null) consumingFailure = retainConsumingFailure(consumingFailure, result, match.priority);
|
|
3294
|
+
if (error.consumed < result.consumed) error = result;
|
|
3295
|
+
}
|
|
3165
3296
|
}
|
|
3166
3297
|
if (!foundMatch) for (const [parser, index] of remainingParsers) {
|
|
3167
|
-
|
|
3298
|
+
if (matchedParsers.has(index)) continue;
|
|
3299
|
+
const result = parser.parse(withPassThroughFailure(withChildContext$1(currentContext, index, stateArray[index], parser), consumingFailure, getPassThroughPriority(parser, stateArray[index], currentContext.buffer[0])));
|
|
3168
3300
|
if (result.success && result.consumed.length < 1) {
|
|
3169
3301
|
const newStateArray = annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? getWrappedChildState(currentContext.state, result.next.state, parser) : s));
|
|
3170
3302
|
const mergedExec = mergeChildExec(currentContext.exec, result.next.exec);
|
|
@@ -3192,7 +3324,7 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
3192
3324
|
}
|
|
3193
3325
|
return {
|
|
3194
3326
|
success: true,
|
|
3195
|
-
next: currentContext,
|
|
3327
|
+
next: withPassThroughFailure(currentContext, consumingFailure),
|
|
3196
3328
|
consumed: allConsumed
|
|
3197
3329
|
};
|
|
3198
3330
|
};
|
|
@@ -3200,6 +3332,7 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
3200
3332
|
let currentContext = context;
|
|
3201
3333
|
const allConsumed = [];
|
|
3202
3334
|
const matchedParsers = /* @__PURE__ */ new Set();
|
|
3335
|
+
let consumingFailure;
|
|
3203
3336
|
while (matchedParsers.size < parsers.length) {
|
|
3204
3337
|
let foundMatch = false;
|
|
3205
3338
|
let error = {
|
|
@@ -3207,15 +3340,16 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
3207
3340
|
error: message`No remaining parsers could match the input.`
|
|
3208
3341
|
};
|
|
3209
3342
|
const stateArray = currentContext.state;
|
|
3210
|
-
const remainingParsers = parsers.map((parser, index) => [parser, index]).filter(([
|
|
3343
|
+
const remainingParsers = orderBeforePassThrough(parsers.map((parser, index) => [parser, index]).filter(([parser, index]) => !matchedParsers.has(index) || getOptionMatch(parser, stateArray[index], currentContext.buffer[0])?.continuesCommand === true || passThroughParsers.size > 0 && !currentContext.optionsTerminated && getOptionMatch(parser, stateArray[index], currentContext.buffer[0]) != null).sort(([parserA], [parserB]) => parserB.priority - parserA.priority), currentContext, ([parser]) => parser, ([, index]) => stateArray[index], passThroughParsers);
|
|
3211
3344
|
for (const [parser, index] of remainingParsers) {
|
|
3212
|
-
const resultOrPromise = parser.parse(withChildContext$1(currentContext, index, stateArray[index], parser));
|
|
3345
|
+
const resultOrPromise = parser.parse(withPassThroughFailure(withChildContext$1(currentContext, index, stateArray[index], parser), consumingFailure, getPassThroughPriority(parser, stateArray[index], currentContext.buffer[0])));
|
|
3213
3346
|
const result = await resultOrPromise;
|
|
3214
3347
|
if (result.success && result.consumed.length > 0) {
|
|
3215
3348
|
const newStateArray = annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? getWrappedChildState(currentContext.state, result.next.state, parser) : s));
|
|
3216
3349
|
const mergedExec = mergeChildExec(currentContext.exec, result.next.exec);
|
|
3217
3350
|
currentContext = {
|
|
3218
3351
|
...currentContext,
|
|
3352
|
+
...getPassThroughFailureHint(result.next),
|
|
3219
3353
|
buffer: result.next.buffer,
|
|
3220
3354
|
optionsTerminated: result.next.optionsTerminated,
|
|
3221
3355
|
state: newStateArray,
|
|
@@ -3224,14 +3358,21 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
3224
3358
|
dependencyRegistry: mergedExec.dependencyRegistry
|
|
3225
3359
|
} : {}
|
|
3226
3360
|
};
|
|
3361
|
+
consumingFailure = void 0;
|
|
3227
3362
|
allConsumed.push(...result.consumed);
|
|
3228
3363
|
matchedParsers.add(index);
|
|
3229
3364
|
foundMatch = true;
|
|
3230
3365
|
break;
|
|
3231
|
-
} else if (
|
|
3366
|
+
} else if (result.success) consumingFailure = retainConsumingFailureHint(consumingFailure, currentContext, result.next);
|
|
3367
|
+
else {
|
|
3368
|
+
const match = getOptionMatch(parser, stateArray[index], currentContext.buffer[0]);
|
|
3369
|
+
if (result.consumed > 0 && match != null) consumingFailure = retainConsumingFailure(consumingFailure, result, match.priority);
|
|
3370
|
+
if (error.consumed < result.consumed) error = result;
|
|
3371
|
+
}
|
|
3232
3372
|
}
|
|
3233
3373
|
if (!foundMatch) for (const [parser, index] of remainingParsers) {
|
|
3234
|
-
|
|
3374
|
+
if (matchedParsers.has(index)) continue;
|
|
3375
|
+
const resultOrPromise = parser.parse(withPassThroughFailure(withChildContext$1(currentContext, index, stateArray[index], parser), consumingFailure, getPassThroughPriority(parser, stateArray[index], currentContext.buffer[0])));
|
|
3235
3376
|
const result = await resultOrPromise;
|
|
3236
3377
|
if (result.success && result.consumed.length < 1) {
|
|
3237
3378
|
const newStateArray = annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? getWrappedChildState(currentContext.state, result.next.state, parser) : s));
|
|
@@ -3260,7 +3401,7 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
3260
3401
|
}
|
|
3261
3402
|
return {
|
|
3262
3403
|
success: true,
|
|
3263
|
-
next: currentContext,
|
|
3404
|
+
next: withPassThroughFailure(currentContext, consumingFailure),
|
|
3264
3405
|
consumed: allConsumed
|
|
3265
3406
|
};
|
|
3266
3407
|
};
|
|
@@ -3513,6 +3654,8 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
3513
3654
|
enumerable: false
|
|
3514
3655
|
});
|
|
3515
3656
|
defineInheritedAnnotationParser(tupleParser);
|
|
3657
|
+
defineOptionMatch(tupleParser, (state, token) => combineOptionMatches(parsers.map((parser, index) => getOptionMatch(parser, getWrappedChildState(state, state[index], parser), token))));
|
|
3658
|
+
definePassThroughPriority(tupleParser, parsers, (state, token) => combinePassThroughPriorities(parsers.map((parser, index) => getPassThroughPriority(parser, getWrappedChildState(state, state[index], parser), token))));
|
|
3516
3659
|
return fluent(tupleParser);
|
|
3517
3660
|
}
|
|
3518
3661
|
function seq(...rawArgs) {
|
|
@@ -3926,6 +4069,7 @@ function merge(...args) {
|
|
|
3926
4069
|
success: true,
|
|
3927
4070
|
next: {
|
|
3928
4071
|
...context,
|
|
4072
|
+
...getPassThroughFailureHint(result.next),
|
|
3929
4073
|
buffer: result.next.buffer,
|
|
3930
4074
|
optionsTerminated: result.next.optionsTerminated,
|
|
3931
4075
|
state: newState,
|
|
@@ -4031,6 +4175,7 @@ function merge(...args) {
|
|
|
4031
4175
|
const mergedExec = mergeChildExec(settledContext.exec, result.next.exec);
|
|
4032
4176
|
settledContext = {
|
|
4033
4177
|
...settledContext,
|
|
4178
|
+
...getPassThroughFailureHint(result.next),
|
|
4034
4179
|
buffer: result.next.buffer,
|
|
4035
4180
|
optionsTerminated: result.next.optionsTerminated,
|
|
4036
4181
|
state: nextState,
|
|
@@ -4063,6 +4208,7 @@ function merge(...args) {
|
|
|
4063
4208
|
const newState = mergeResultState(parser, currentContext, parserState, result, i);
|
|
4064
4209
|
const newContext = {
|
|
4065
4210
|
...currentContext,
|
|
4211
|
+
...getPassThroughFailureHint(result.next),
|
|
4066
4212
|
buffer: result.next.buffer,
|
|
4067
4213
|
optionsTerminated: result.next.optionsTerminated,
|
|
4068
4214
|
state: newState,
|
|
@@ -4108,6 +4254,7 @@ function merge(...args) {
|
|
|
4108
4254
|
const newState = mergeResultState(parser, currentContext, parserState, result, i);
|
|
4109
4255
|
const newContext = {
|
|
4110
4256
|
...currentContext,
|
|
4257
|
+
...getPassThroughFailureHint(result.next),
|
|
4111
4258
|
buffer: result.next.buffer,
|
|
4112
4259
|
optionsTerminated: result.next.optionsTerminated,
|
|
4113
4260
|
state: newState,
|
|
@@ -4147,10 +4294,12 @@ function merge(...args) {
|
|
|
4147
4294
|
const consumedLanes = /* @__PURE__ */ new Set();
|
|
4148
4295
|
const consumedGroups = /* @__PURE__ */ new Set();
|
|
4149
4296
|
const laneResults = /* @__PURE__ */ new Map();
|
|
4297
|
+
let consumingFailure;
|
|
4150
4298
|
let attemptedLane = false;
|
|
4151
4299
|
let madeProgress = true;
|
|
4152
4300
|
while (madeProgress && currentContext.buffer.length > 0) {
|
|
4153
4301
|
madeProgress = false;
|
|
4302
|
+
consumingFailure = void 0;
|
|
4154
4303
|
let consumingError = null;
|
|
4155
4304
|
for (const lane of mergeParseLanes) {
|
|
4156
4305
|
if (consumingError != null && lane.priority < consumingError.priority) {
|
|
@@ -4168,6 +4317,10 @@ function merge(...args) {
|
|
|
4168
4317
|
break;
|
|
4169
4318
|
}
|
|
4170
4319
|
if (!result.success) {
|
|
4320
|
+
if (result.consumed > 0 && matchesOptionToken({
|
|
4321
|
+
leadingNames: lane.leadingNames,
|
|
4322
|
+
usage: parsers.flatMap((parser) => parser.usage)
|
|
4323
|
+
}, currentContext.buffer[0])) consumingFailure = retainConsumingFailure(consumingFailure, result, lane.priority);
|
|
4171
4324
|
if (result.consumed > 0 && consumingError == null) consumingError = {
|
|
4172
4325
|
priority: lane.priority,
|
|
4173
4326
|
result
|
|
@@ -4199,7 +4352,7 @@ function merge(...args) {
|
|
|
4199
4352
|
}
|
|
4200
4353
|
return {
|
|
4201
4354
|
success: true,
|
|
4202
|
-
next: currentContext,
|
|
4355
|
+
next: withPassThroughFailure(currentContext, consumingFailure),
|
|
4203
4356
|
consumed: allConsumed
|
|
4204
4357
|
};
|
|
4205
4358
|
};
|
|
@@ -4210,10 +4363,12 @@ function merge(...args) {
|
|
|
4210
4363
|
const consumedLanes = /* @__PURE__ */ new Set();
|
|
4211
4364
|
const consumedGroups = /* @__PURE__ */ new Set();
|
|
4212
4365
|
const laneResults = /* @__PURE__ */ new Map();
|
|
4366
|
+
let consumingFailure;
|
|
4213
4367
|
let attemptedLane = false;
|
|
4214
4368
|
let madeProgress = true;
|
|
4215
4369
|
while (madeProgress && currentContext.buffer.length > 0) {
|
|
4216
4370
|
madeProgress = false;
|
|
4371
|
+
consumingFailure = void 0;
|
|
4217
4372
|
let consumingError = null;
|
|
4218
4373
|
for (const lane of mergeParseLanes) {
|
|
4219
4374
|
if (consumingError != null && lane.priority < consumingError.priority) {
|
|
@@ -4231,6 +4386,10 @@ function merge(...args) {
|
|
|
4231
4386
|
break;
|
|
4232
4387
|
}
|
|
4233
4388
|
if (!result.success) {
|
|
4389
|
+
if (result.consumed > 0 && matchesOptionToken({
|
|
4390
|
+
leadingNames: lane.leadingNames,
|
|
4391
|
+
usage: parsers.flatMap((parser) => parser.usage)
|
|
4392
|
+
}, currentContext.buffer[0])) consumingFailure = retainConsumingFailure(consumingFailure, result, lane.priority);
|
|
4234
4393
|
if (result.consumed > 0 && consumingError == null) consumingError = {
|
|
4235
4394
|
priority: lane.priority,
|
|
4236
4395
|
result
|
|
@@ -4262,7 +4421,7 @@ function merge(...args) {
|
|
|
4262
4421
|
}
|
|
4263
4422
|
return {
|
|
4264
4423
|
success: true,
|
|
4265
|
-
next: currentContext,
|
|
4424
|
+
next: withPassThroughFailure(currentContext, consumingFailure),
|
|
4266
4425
|
consumed: allConsumed
|
|
4267
4426
|
};
|
|
4268
4427
|
};
|
|
@@ -4751,6 +4910,8 @@ function merge(...args) {
|
|
|
4751
4910
|
};
|
|
4752
4911
|
defineParseLanes(mergeParser, mergeParseLanes);
|
|
4753
4912
|
defineInheritedAnnotationParser(mergeParser);
|
|
4913
|
+
defineOptionMatch(mergeParser, (state, token) => combineOptionMatches(sorted.map(([parser], index) => getOptionMatch(parser, extractParserStateFromState(parser, state, index), token))));
|
|
4914
|
+
definePassThroughPriority(mergeParser, parsers, (state, token) => combinePassThroughPriorities(sorted.map(([parser], index) => getPassThroughPriority(parser, extractParserStateFromState(parser, state, index), token))));
|
|
4754
4915
|
return fluent(mergeParser);
|
|
4755
4916
|
}
|
|
4756
4917
|
/**
|
|
@@ -4941,6 +5102,7 @@ function tryParseSuggestList(context, stateArray, parsers, matchedParsers, remai
|
|
|
4941
5102
|
const mergedExec = mergeChildExec(context.exec, result$1.next.exec);
|
|
4942
5103
|
return preParseSuggestLoop({
|
|
4943
5104
|
...context,
|
|
5105
|
+
...getPassThroughFailureHint(result$1.next),
|
|
4944
5106
|
buffer: result$1.next.buffer,
|
|
4945
5107
|
optionsTerminated: result$1.next.optionsTerminated,
|
|
4946
5108
|
state: stateArray,
|
|
@@ -4968,6 +5130,7 @@ function tryParseSuggestList(context, stateArray, parsers, matchedParsers, remai
|
|
|
4968
5130
|
const mergedExec = mergeChildExec(context.exec, result.next.exec);
|
|
4969
5131
|
return {
|
|
4970
5132
|
...context,
|
|
5133
|
+
...getPassThroughFailureHint(result.next),
|
|
4971
5134
|
buffer: result.next.buffer,
|
|
4972
5135
|
optionsTerminated: result.next.optionsTerminated,
|
|
4973
5136
|
state: stateArray,
|
|
@@ -4987,10 +5150,12 @@ function concat(...parsers) {
|
|
|
4987
5150
|
const isAsync = combinedMode === "async";
|
|
4988
5151
|
const syncParsers = parsers;
|
|
4989
5152
|
const initialState = parsers.map((parser) => parser.initialState);
|
|
5153
|
+
const passThroughParsers = new Set(parsers.filter((parser) => hasPassThroughUsage(parser.usage)));
|
|
4990
5154
|
const parseSync = (context) => {
|
|
4991
5155
|
let currentContext = context;
|
|
4992
5156
|
const allConsumed = [];
|
|
4993
5157
|
const matchedParsers = /* @__PURE__ */ new Set();
|
|
5158
|
+
let consumingFailure;
|
|
4994
5159
|
while (matchedParsers.size < syncParsers.length) {
|
|
4995
5160
|
let foundMatch = false;
|
|
4996
5161
|
let error = {
|
|
@@ -4998,14 +5163,15 @@ function concat(...parsers) {
|
|
|
4998
5163
|
error: message`No remaining parsers could match the input.`
|
|
4999
5164
|
};
|
|
5000
5165
|
const stateArray = currentContext.state;
|
|
5001
|
-
const remainingParsers = syncParsers.map((parser, index) => [parser, index]).filter(([
|
|
5166
|
+
const remainingParsers = orderBeforePassThrough(syncParsers.map((parser, index) => [parser, index]).filter(([parser, index]) => !matchedParsers.has(index) || getOptionMatch(parser, stateArray[index], currentContext.buffer[0])?.continuesCommand === true || passThroughParsers.size > 0 && !currentContext.optionsTerminated && getOptionMatch(parser, stateArray[index], currentContext.buffer[0]) != null).sort(([parserA], [parserB]) => parserB.priority - parserA.priority), currentContext, ([parser]) => parser, ([, index]) => stateArray[index], passThroughParsers);
|
|
5002
5167
|
for (const [parser, index] of remainingParsers) {
|
|
5003
|
-
const result = parser.parse(withChildContext$1(currentContext, index, stateArray[index], parser));
|
|
5168
|
+
const result = parser.parse(withPassThroughFailure(withChildContext$1(currentContext, index, stateArray[index], parser), consumingFailure, getPassThroughPriority(parser, stateArray[index], currentContext.buffer[0])));
|
|
5004
5169
|
if (result.success && result.consumed.length > 0) {
|
|
5005
5170
|
const newStateArray = annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? getWrappedChildState(currentContext.state, result.next.state, parser) : s));
|
|
5006
5171
|
const mergedExec = mergeChildExec(currentContext.exec, result.next.exec);
|
|
5007
5172
|
currentContext = {
|
|
5008
5173
|
...currentContext,
|
|
5174
|
+
...getPassThroughFailureHint(result.next),
|
|
5009
5175
|
buffer: result.next.buffer,
|
|
5010
5176
|
optionsTerminated: result.next.optionsTerminated,
|
|
5011
5177
|
state: newStateArray,
|
|
@@ -5014,14 +5180,21 @@ function concat(...parsers) {
|
|
|
5014
5180
|
dependencyRegistry: mergedExec.dependencyRegistry
|
|
5015
5181
|
} : {}
|
|
5016
5182
|
};
|
|
5183
|
+
consumingFailure = void 0;
|
|
5017
5184
|
allConsumed.push(...result.consumed);
|
|
5018
5185
|
matchedParsers.add(index);
|
|
5019
5186
|
foundMatch = true;
|
|
5020
5187
|
break;
|
|
5021
|
-
} else if (
|
|
5188
|
+
} else if (result.success) consumingFailure = retainConsumingFailureHint(consumingFailure, currentContext, result.next);
|
|
5189
|
+
else {
|
|
5190
|
+
const match = getOptionMatch(parser, stateArray[index], currentContext.buffer[0]);
|
|
5191
|
+
if (result.consumed > 0 && match != null) consumingFailure = retainConsumingFailure(consumingFailure, result, match.priority);
|
|
5192
|
+
if (error.consumed < result.consumed) error = result;
|
|
5193
|
+
}
|
|
5022
5194
|
}
|
|
5023
5195
|
if (!foundMatch) for (const [parser, index] of remainingParsers) {
|
|
5024
|
-
|
|
5196
|
+
if (matchedParsers.has(index)) continue;
|
|
5197
|
+
const result = parser.parse(withPassThroughFailure(withChildContext$1(currentContext, index, stateArray[index], parser), consumingFailure, getPassThroughPriority(parser, stateArray[index], currentContext.buffer[0])));
|
|
5025
5198
|
if (result.success && result.consumed.length < 1) {
|
|
5026
5199
|
const newStateArray = annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? getWrappedChildState(currentContext.state, result.next.state, parser) : s));
|
|
5027
5200
|
const mergedExec = mergeChildExec(currentContext.exec, result.next.exec);
|
|
@@ -5049,7 +5222,7 @@ function concat(...parsers) {
|
|
|
5049
5222
|
}
|
|
5050
5223
|
return {
|
|
5051
5224
|
success: true,
|
|
5052
|
-
next: currentContext,
|
|
5225
|
+
next: withPassThroughFailure(currentContext, consumingFailure),
|
|
5053
5226
|
consumed: allConsumed
|
|
5054
5227
|
};
|
|
5055
5228
|
};
|
|
@@ -5057,6 +5230,7 @@ function concat(...parsers) {
|
|
|
5057
5230
|
let currentContext = context;
|
|
5058
5231
|
const allConsumed = [];
|
|
5059
5232
|
const matchedParsers = /* @__PURE__ */ new Set();
|
|
5233
|
+
let consumingFailure;
|
|
5060
5234
|
while (matchedParsers.size < parsers.length) {
|
|
5061
5235
|
let foundMatch = false;
|
|
5062
5236
|
let error = {
|
|
@@ -5064,14 +5238,15 @@ function concat(...parsers) {
|
|
|
5064
5238
|
error: message`No remaining parsers could match the input.`
|
|
5065
5239
|
};
|
|
5066
5240
|
const stateArray = currentContext.state;
|
|
5067
|
-
const remainingParsers = parsers.map((parser, index) => [parser, index]).filter(([
|
|
5241
|
+
const remainingParsers = orderBeforePassThrough(parsers.map((parser, index) => [parser, index]).filter(([parser, index]) => !matchedParsers.has(index) || getOptionMatch(parser, stateArray[index], currentContext.buffer[0])?.continuesCommand === true || passThroughParsers.size > 0 && !currentContext.optionsTerminated && getOptionMatch(parser, stateArray[index], currentContext.buffer[0]) != null).sort(([parserA], [parserB]) => parserB.priority - parserA.priority), currentContext, ([parser]) => parser, ([, index]) => stateArray[index], passThroughParsers);
|
|
5068
5242
|
for (const [parser, index] of remainingParsers) {
|
|
5069
|
-
const result = await parser.parse(withChildContext$1(currentContext, index, stateArray[index], parser));
|
|
5243
|
+
const result = await parser.parse(withPassThroughFailure(withChildContext$1(currentContext, index, stateArray[index], parser), consumingFailure, getPassThroughPriority(parser, stateArray[index], currentContext.buffer[0])));
|
|
5070
5244
|
if (result.success && result.consumed.length > 0) {
|
|
5071
5245
|
const newStateArray = annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? getWrappedChildState(currentContext.state, result.next.state, parser) : s));
|
|
5072
5246
|
const mergedExec = mergeChildExec(currentContext.exec, result.next.exec);
|
|
5073
5247
|
currentContext = {
|
|
5074
5248
|
...currentContext,
|
|
5249
|
+
...getPassThroughFailureHint(result.next),
|
|
5075
5250
|
buffer: result.next.buffer,
|
|
5076
5251
|
optionsTerminated: result.next.optionsTerminated,
|
|
5077
5252
|
state: newStateArray,
|
|
@@ -5080,14 +5255,21 @@ function concat(...parsers) {
|
|
|
5080
5255
|
dependencyRegistry: mergedExec.dependencyRegistry
|
|
5081
5256
|
} : {}
|
|
5082
5257
|
};
|
|
5258
|
+
consumingFailure = void 0;
|
|
5083
5259
|
allConsumed.push(...result.consumed);
|
|
5084
5260
|
matchedParsers.add(index);
|
|
5085
5261
|
foundMatch = true;
|
|
5086
5262
|
break;
|
|
5087
|
-
} else if (
|
|
5263
|
+
} else if (result.success) consumingFailure = retainConsumingFailureHint(consumingFailure, currentContext, result.next);
|
|
5264
|
+
else {
|
|
5265
|
+
const match = getOptionMatch(parser, stateArray[index], currentContext.buffer[0]);
|
|
5266
|
+
if (result.consumed > 0 && match != null) consumingFailure = retainConsumingFailure(consumingFailure, result, match.priority);
|
|
5267
|
+
if (error.consumed < result.consumed) error = result;
|
|
5268
|
+
}
|
|
5088
5269
|
}
|
|
5089
5270
|
if (!foundMatch) for (const [parser, index] of remainingParsers) {
|
|
5090
|
-
|
|
5271
|
+
if (matchedParsers.has(index)) continue;
|
|
5272
|
+
const result = await parser.parse(withPassThroughFailure(withChildContext$1(currentContext, index, stateArray[index], parser), consumingFailure, getPassThroughPriority(parser, stateArray[index], currentContext.buffer[0])));
|
|
5091
5273
|
if (result.success && result.consumed.length < 1) {
|
|
5092
5274
|
const newStateArray = annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? getWrappedChildState(currentContext.state, result.next.state, parser) : s));
|
|
5093
5275
|
const mergedExec = mergeChildExec(currentContext.exec, result.next.exec);
|
|
@@ -5115,7 +5297,7 @@ function concat(...parsers) {
|
|
|
5115
5297
|
}
|
|
5116
5298
|
return {
|
|
5117
5299
|
success: true,
|
|
5118
|
-
next: currentContext,
|
|
5300
|
+
next: withPassThroughFailure(currentContext, consumingFailure),
|
|
5119
5301
|
consumed: allConsumed
|
|
5120
5302
|
};
|
|
5121
5303
|
};
|
|
@@ -5365,6 +5547,8 @@ function concat(...parsers) {
|
|
|
5365
5547
|
}
|
|
5366
5548
|
};
|
|
5367
5549
|
defineInheritedAnnotationParser(concatParser);
|
|
5550
|
+
defineOptionMatch(concatParser, (state, token) => combineOptionMatches(parsers.map((parser, index) => getOptionMatch(parser, getWrappedChildState(state, state[index], parser), token))));
|
|
5551
|
+
definePassThroughPriority(concatParser, parsers, (state, token) => combinePassThroughPriorities(parsers.map((parser, index) => getPassThroughPriority(parser, getWrappedChildState(state, state[index], parser), token))));
|
|
5368
5552
|
return fluent(concatParser);
|
|
5369
5553
|
}
|
|
5370
5554
|
function group(label, parser, options = {}) {
|
|
@@ -5457,6 +5641,9 @@ function group(label, parser, options = {}) {
|
|
|
5457
5641
|
configurable: true,
|
|
5458
5642
|
enumerable: false
|
|
5459
5643
|
});
|
|
5644
|
+
delegateKnownCompletion(groupParser, parser);
|
|
5645
|
+
defineOptionMatch(groupParser, (state, token) => getOptionMatch(parser, state, token));
|
|
5646
|
+
definePassThroughPriority(groupParser, [parser], (state, token) => getPassThroughPriority(parser, state, token));
|
|
5460
5647
|
return fluent(groupParser);
|
|
5461
5648
|
}
|
|
5462
5649
|
/**
|
|
@@ -5611,6 +5798,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
5611
5798
|
dependencyRegistry: discriminatorExec.dependencyRegistry
|
|
5612
5799
|
} : {}
|
|
5613
5800
|
}, "_branch", branchParser.initialState, branchParser, branchParser.usage),
|
|
5801
|
+
...getPassThroughFailureHint(discriminatorResult.next),
|
|
5614
5802
|
buffer: discriminatorResult.next.buffer,
|
|
5615
5803
|
optionsTerminated: discriminatorResult.next.optionsTerminated
|
|
5616
5804
|
});
|
|
@@ -5732,6 +5920,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
5732
5920
|
const discriminatorExec = mergeChildExec(context.exec, discriminatorResult.next.exec);
|
|
5733
5921
|
const speculationContext = {
|
|
5734
5922
|
...context,
|
|
5923
|
+
...getPassThroughFailureHint(discriminatorResult.next),
|
|
5735
5924
|
buffer: discriminatorResult.next.buffer,
|
|
5736
5925
|
optionsTerminated: discriminatorResult.next.optionsTerminated,
|
|
5737
5926
|
...discriminatorExec != null ? {
|
|
@@ -5859,6 +6048,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
5859
6048
|
dependencyRegistry: discriminatorExec.dependencyRegistry
|
|
5860
6049
|
} : {}
|
|
5861
6050
|
}, "_branch", branchParser.initialState, branchParser, branchParser.usage),
|
|
6051
|
+
...getPassThroughFailureHint(discriminatorResult.next),
|
|
5862
6052
|
buffer: discriminatorResult.next.buffer,
|
|
5863
6053
|
optionsTerminated: discriminatorResult.next.optionsTerminated
|
|
5864
6054
|
});
|
|
@@ -6426,6 +6616,36 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
6426
6616
|
}
|
|
6427
6617
|
};
|
|
6428
6618
|
defineInheritedAnnotationParser(conditionalParser);
|
|
6619
|
+
const reachableBranches = (state) => {
|
|
6620
|
+
if (state.selectedBranch != null) {
|
|
6621
|
+
const branch = state.selectedBranch.kind === "default" ? defaultBranch : branches[state.selectedBranch.key];
|
|
6622
|
+
return branch == null ? [] : [{
|
|
6623
|
+
branch,
|
|
6624
|
+
state: state.branchState
|
|
6625
|
+
}];
|
|
6626
|
+
}
|
|
6627
|
+
const known = getKnownCompletion(discriminator, state.discriminatorState);
|
|
6628
|
+
if (known != null) {
|
|
6629
|
+
const branch = typeof known.value === "string" ? branches[known.value] : void 0;
|
|
6630
|
+
const reachable = branch ?? defaultBranch;
|
|
6631
|
+
return reachable == null ? [] : [{
|
|
6632
|
+
branch: reachable,
|
|
6633
|
+
state: reachable.initialState
|
|
6634
|
+
}];
|
|
6635
|
+
}
|
|
6636
|
+
return allBranchParsers.map((branch) => ({
|
|
6637
|
+
branch,
|
|
6638
|
+
state: branch.initialState
|
|
6639
|
+
}));
|
|
6640
|
+
};
|
|
6641
|
+
definePassThroughPriority(conditionalParser, [discriminator, ...allBranchParsers], (state, token) => combinePassThroughPriorities([...state.selectedBranch == null ? [getPassThroughPriority(discriminator, state.discriminatorState, token)] : [], ...reachableBranches(state).map(({ branch, state: state$1 }) => getPassThroughPriority(branch, state$1, token))]));
|
|
6642
|
+
defineOptionMatch(conditionalParser, (state, token) => {
|
|
6643
|
+
if (state.selectedBranch != null) {
|
|
6644
|
+
const branch = state.selectedBranch.kind === "default" ? defaultBranch : branches[state.selectedBranch.key];
|
|
6645
|
+
return branch == null ? void 0 : getOptionMatch(branch, state.branchState, token);
|
|
6646
|
+
}
|
|
6647
|
+
return combineOptionMatches([getOptionMatch(discriminator, state.discriminatorState, token), ...reachableBranches(state).map(({ branch, state: state$1 }) => getOptionMatch(branch, state$1, token))]);
|
|
6648
|
+
});
|
|
6429
6649
|
return fluent(conditionalParser);
|
|
6430
6650
|
}
|
|
6431
6651
|
|