@optique/core 1.0.10 → 1.0.11-dev.2654

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.
@@ -1,5 +1,6 @@
1
1
  const require_annotations = require('./internal/annotations.cjs');
2
2
  const require_message = require('./message.cjs');
3
+ const require_passthrough = require('./internal/passthrough.cjs');
3
4
  const require_validate = require('./validate.cjs');
4
5
  const require_usage = require('./usage.cjs');
5
6
  const require_doc = require('./doc.cjs');
@@ -96,6 +97,63 @@ function sharedBufferLeadingNames(parsers) {
96
97
  return names.size === 0 ? EMPTY_LEADING_NAMES : names;
97
98
  }
98
99
  /**
100
+ * Defers capture until a known option at an equal or higher lane priority
101
+ * has been tried.
102
+ * Other siblings retain their relative order, and explicit priorities win.
103
+ */
104
+ function orderBeforePassThrough(pairs, context, getParser, getState, passThroughParsers) {
105
+ const token = context.buffer[0];
106
+ if (passThroughParsers.size === 0 || context.optionsTerminated || token == null || token === "--" || !/^[-/+]/.test(token)) return pairs;
107
+ const matches = new Map(pairs.map((pair) => [pair, require_passthrough.getOptionMatch(getParser(pair), getState(pair), token)]));
108
+ const normalizedOptions = /* @__PURE__ */ new Map();
109
+ const captures = new Map(pairs.flatMap((pair) => {
110
+ if (!passThroughParsers.has(getParser(pair))) return [];
111
+ const priority = require_passthrough.getPassThroughPriority(getParser(pair), getState(pair), token);
112
+ const match = matches.get(pair);
113
+ if (match != null && (priority == null || match.priority >= priority)) {
114
+ const unfiltered = require_passthrough.getPassThroughPriority(getParser(pair), getState(pair));
115
+ if (priority == null || unfiltered != null && unfiltered > match.priority) normalizedOptions.set(pair, match.priority);
116
+ return [];
117
+ }
118
+ return priority == null ? [] : [[pair, priority]];
119
+ }));
120
+ const matching = pairs.filter((pair) => !captures.has(pair)).flatMap((pair) => {
121
+ const match = matches.get(pair);
122
+ return match == null ? [] : [match];
123
+ });
124
+ const orderedCaptures = [...captures].sort((a, b) => b[1] - a[1]);
125
+ if (matching.length === 0) {
126
+ let captureIndex = 0;
127
+ return pairs.map((pair) => captures.has(pair) ? orderedCaptures[captureIndex++][0] : pair);
128
+ }
129
+ const matchingPriority = Math.max(...matching.map((match) => match.priority));
130
+ const ordinary = pairs.filter((pair) => !captures.has(pair) && !normalizedOptions.has(pair));
131
+ const positions = new Map(pairs.map((pair, index) => [pair, index]));
132
+ for (const [pair, priority] of [...normalizedOptions].sort((a, b) => b[1] - a[1])) {
133
+ let insertion = ordinary.findIndex((candidate) => {
134
+ const match = matches.get(candidate);
135
+ return match != null && (match.priority < priority || match.priority === priority && positions.get(pair) < positions.get(candidate));
136
+ });
137
+ if (insertion < 0) {
138
+ const lastMatch = ordinary.findLastIndex((candidate) => matches.get(candidate) != null);
139
+ insertion = lastMatch >= 0 ? lastMatch + 1 : ordinary.findIndex((candidate) => positions.get(candidate) > positions.get(pair));
140
+ if (insertion < 0) insertion = ordinary.length;
141
+ }
142
+ ordinary.splice(insertion, 0, pair);
143
+ }
144
+ const first = ordinary.findIndex((pair) => matches.get(pair) != null);
145
+ const last = ordinary.findLastIndex((pair) => matches.get(pair) != null);
146
+ const before = orderedCaptures.filter(([, priority]) => priority > matchingPriority).map(([pair]) => pair);
147
+ const after = orderedCaptures.filter(([, priority]) => priority <= matchingPriority).map(([pair]) => pair);
148
+ return [
149
+ ...ordinary.slice(0, first),
150
+ ...before,
151
+ ...ordinary.slice(first, last + 1),
152
+ ...after,
153
+ ...ordinary.slice(last + 1)
154
+ ];
155
+ }
156
+ /**
99
157
  * Internal symbol for exposing field-level parser pairs from `object()`
100
158
  * and `merge()` parsers. This allows `merge()` to pre-complete dependency
101
159
  * source fields from child parsers before resolving deferred states.
@@ -533,6 +591,7 @@ function preserveExclusiveStateAfterOptionsTerminator(context, result) {
533
591
  success: true,
534
592
  next: {
535
593
  ...context,
594
+ ...require_passthrough.getPassThroughFailureHint(result.next),
536
595
  buffer: result.next.buffer,
537
596
  optionsTerminated: true,
538
597
  state: context.state,
@@ -820,6 +879,7 @@ function or(...args) {
820
879
  success: true,
821
880
  next: {
822
881
  ...context,
882
+ ...require_passthrough.getPassThroughFailureHint(result.next),
823
883
  buffer: result.next.buffer,
824
884
  optionsTerminated: result.next.optionsTerminated,
825
885
  state: createExclusiveState(context.state, i, parser, result),
@@ -856,6 +916,7 @@ function or(...args) {
856
916
  success: true,
857
917
  next: {
858
918
  ...context,
919
+ ...require_passthrough.getPassThroughFailureHint(replayedResult.next),
859
920
  buffer: replayedResult.next.buffer,
860
921
  optionsTerminated: replayedResult.next.optionsTerminated,
861
922
  state: createExclusiveState(context.state, i, parser, {
@@ -875,6 +936,7 @@ function or(...args) {
875
936
  success: true,
876
937
  next: {
877
938
  ...context,
939
+ ...require_passthrough.getPassThroughFailureHint(result.next),
878
940
  buffer: result.next.buffer,
879
941
  optionsTerminated: result.next.optionsTerminated,
880
942
  state: createExclusiveState(context.state, i, parser, result),
@@ -919,6 +981,7 @@ function or(...args) {
919
981
  provisional: true,
920
982
  next: {
921
983
  ...context,
984
+ ...require_passthrough.getPassThroughFailureHint(provisionalConsuming.result.next),
922
985
  buffer: provisionalConsuming.result.next.buffer,
923
986
  optionsTerminated: provisionalConsuming.result.next.optionsTerminated,
924
987
  state: createExclusiveState(context.state, provisionalConsuming.index, provisionalConsuming.parser, provisionalConsuming.result),
@@ -953,6 +1016,7 @@ function or(...args) {
953
1016
  provisional: true,
954
1017
  next: {
955
1018
  ...context,
1019
+ ...require_passthrough.getPassThroughFailureHint(replayedResult.next),
956
1020
  buffer: replayedResult.next.buffer,
957
1021
  optionsTerminated: replayedResult.next.optionsTerminated,
958
1022
  state: createExclusiveState(context.state, provisionalConsuming.index, provisionalConsuming.parser, {
@@ -1024,6 +1088,7 @@ function or(...args) {
1024
1088
  success: true,
1025
1089
  next: {
1026
1090
  ...context,
1091
+ ...require_passthrough.getPassThroughFailureHint(result.next),
1027
1092
  buffer: result.next.buffer,
1028
1093
  optionsTerminated: result.next.optionsTerminated,
1029
1094
  state: createExclusiveState(context.state, i, parser, result),
@@ -1062,6 +1127,7 @@ function or(...args) {
1062
1127
  success: true,
1063
1128
  next: {
1064
1129
  ...context,
1130
+ ...require_passthrough.getPassThroughFailureHint(replayedResult.next),
1065
1131
  buffer: replayedResult.next.buffer,
1066
1132
  optionsTerminated: replayedResult.next.optionsTerminated,
1067
1133
  state: createExclusiveState(context.state, i, parser, {
@@ -1081,6 +1147,7 @@ function or(...args) {
1081
1147
  success: true,
1082
1148
  next: {
1083
1149
  ...context,
1150
+ ...require_passthrough.getPassThroughFailureHint(result.next),
1084
1151
  buffer: result.next.buffer,
1085
1152
  optionsTerminated: result.next.optionsTerminated,
1086
1153
  state: createExclusiveState(context.state, i, parser, result),
@@ -1125,6 +1192,7 @@ function or(...args) {
1125
1192
  provisional: true,
1126
1193
  next: {
1127
1194
  ...context,
1195
+ ...require_passthrough.getPassThroughFailureHint(provisionalConsuming.result.next),
1128
1196
  buffer: provisionalConsuming.result.next.buffer,
1129
1197
  optionsTerminated: provisionalConsuming.result.next.optionsTerminated,
1130
1198
  state: createExclusiveState(context.state, provisionalConsuming.index, provisionalConsuming.parser, provisionalConsuming.result),
@@ -1159,6 +1227,7 @@ function or(...args) {
1159
1227
  provisional: true,
1160
1228
  next: {
1161
1229
  ...context,
1230
+ ...require_passthrough.getPassThroughFailureHint(replayedResult.next),
1162
1231
  buffer: replayedResult.next.buffer,
1163
1232
  optionsTerminated: replayedResult.next.optionsTerminated,
1164
1233
  state: createExclusiveState(context.state, provisionalConsuming.index, provisionalConsuming.parser, {
@@ -1235,6 +1304,14 @@ function or(...args) {
1235
1304
  const singleDependencyMetadata = composeExclusiveDependencyMetadata(parsers);
1236
1305
  if (singleDependencyMetadata != null) singleResult.dependencyMetadata = singleDependencyMetadata;
1237
1306
  require_parser.defineInheritedAnnotationParser(singleResult);
1307
+ require_passthrough.defineOptionMatch(singleResult, (state, token) => require_passthrough.combineOptionMatches(parsers.map((parser, index) => {
1308
+ const active = normalizeExclusiveState(state);
1309
+ return require_passthrough.getOptionMatch(parser, active?.[0] === index && active[1].success ? active[1].next.state : parser.initialState, token);
1310
+ })));
1311
+ require_passthrough.definePassThroughPriority(singleResult, parsers, (state, token) => {
1312
+ const active = normalizeExclusiveState(state);
1313
+ return require_passthrough.combinePassThroughPriorities(parsers.map((parser, index) => require_passthrough.getPassThroughPriority(parser, active?.[0] === index && active[1].success ? active[1].next.state : parser.initialState, token)));
1314
+ });
1238
1315
  return singleResult;
1239
1316
  }
1240
1317
  /**
@@ -1264,24 +1341,27 @@ function longestMatch(...args) {
1264
1341
  return createUnexpectedInputErrorWithScopedSuggestions(defaultMsg, token, parsers, options?.errors?.suggestions);
1265
1342
  })()
1266
1343
  });
1267
- const commitLongestMatch = (context, match, optionsTerminatorResult) => {
1344
+ const commitLongestMatch = (context, match, optionsTerminatorResult, consumingFailure) => {
1268
1345
  const selectedResult = optionsTerminatorResult == null ? match.result : {
1269
1346
  ...match.result,
1270
1347
  next: {
1271
1348
  ...match.result.next,
1349
+ ...require_passthrough.getPassThroughFailureHint(optionsTerminatorResult.next),
1272
1350
  buffer: optionsTerminatorResult.next.buffer,
1273
1351
  optionsTerminated: true
1274
1352
  },
1275
1353
  consumed: [...optionsTerminatorResult.consumed, ...match.result.consumed]
1276
1354
  };
1355
+ const next = selectedResult.consumed.length === 0 ? require_passthrough.withPassThroughFailure(selectedResult.next, consumingFailure) : selectedResult.next;
1277
1356
  const parser = parsers[match.index];
1278
- const mergedExec = require_execution_context.mergeChildExec(context.exec, selectedResult.next.exec);
1357
+ const mergedExec = require_execution_context.mergeChildExec(context.exec, next.exec);
1279
1358
  return {
1280
1359
  success: true,
1281
1360
  next: {
1282
1361
  ...context,
1283
- buffer: selectedResult.next.buffer,
1284
- optionsTerminated: selectedResult.next.optionsTerminated,
1362
+ ...require_passthrough.getPassThroughFailureHint(next),
1363
+ buffer: next.buffer,
1364
+ optionsTerminated: next.optionsTerminated,
1285
1365
  state: createExclusiveState(context.state, match.index, parser, selectedResult),
1286
1366
  ...mergedExec != null ? {
1287
1367
  exec: mergedExec,
@@ -1316,6 +1396,7 @@ function longestMatch(...args) {
1316
1396
  let bestMatch = null;
1317
1397
  const optionsTerminatorMatches = [];
1318
1398
  let error = getInitialError(context);
1399
+ let consumingFailure;
1319
1400
  const activeState = normalizeExclusiveState(context.state);
1320
1401
  for (let i = 0; i < syncParsers.length; i++) {
1321
1402
  const parser = syncParsers[i];
@@ -1331,6 +1412,7 @@ function longestMatch(...args) {
1331
1412
  continue;
1332
1413
  }
1333
1414
  if (result.success) {
1415
+ consumingFailure = require_passthrough.retainConsumingFailureHint(consumingFailure, context, result.next);
1334
1416
  const consumed = context.buffer.length - result.next.buffer.length;
1335
1417
  const bestIsProvisional = bestMatch != null && bestMatch.result.success && !!bestMatch.result.provisional;
1336
1418
  if (bestMatch === null || consumed > bestMatch.consumed || consumed === bestMatch.consumed && bestIsProvisional && !result.provisional) bestMatch = {
@@ -1338,11 +1420,15 @@ function longestMatch(...args) {
1338
1420
  result,
1339
1421
  consumed
1340
1422
  };
1341
- } else if (error.consumed < result.consumed) error = result;
1423
+ } else {
1424
+ const match = require_passthrough.getOptionMatch(parser, childContext.state, context.buffer[0]);
1425
+ if (result.consumed > 0 && match != null) consumingFailure = require_passthrough.retainConsumingFailure(consumingFailure, result, match.priority);
1426
+ if (error.consumed < result.consumed) error = result;
1427
+ }
1342
1428
  }
1343
1429
  const optionsTerminatorResolution = resolveLongestMatchOptionsTerminator(context, bestMatch, optionsTerminatorMatches);
1344
1430
  if (optionsTerminatorResolution != null) return optionsTerminatorResolution;
1345
- if (bestMatch != null) return commitLongestMatch(context, bestMatch);
1431
+ if (bestMatch != null) return commitLongestMatch(context, bestMatch, void 0, consumingFailure);
1346
1432
  return {
1347
1433
  ...error,
1348
1434
  success: false
@@ -1352,6 +1438,7 @@ function longestMatch(...args) {
1352
1438
  let bestMatch = null;
1353
1439
  const optionsTerminatorMatches = [];
1354
1440
  let error = getInitialError(context);
1441
+ let consumingFailure;
1355
1442
  const activeState = normalizeExclusiveState(context.state);
1356
1443
  for (let i = 0; i < parsers.length; i++) {
1357
1444
  const parser = parsers[i];
@@ -1368,6 +1455,7 @@ function longestMatch(...args) {
1368
1455
  continue;
1369
1456
  }
1370
1457
  if (result.success) {
1458
+ consumingFailure = require_passthrough.retainConsumingFailureHint(consumingFailure, context, result.next);
1371
1459
  const consumed = context.buffer.length - result.next.buffer.length;
1372
1460
  const bestIsProvisional = bestMatch != null && bestMatch.result.success && !!bestMatch.result.provisional;
1373
1461
  if (bestMatch === null || consumed > bestMatch.consumed || consumed === bestMatch.consumed && bestIsProvisional && !result.provisional) bestMatch = {
@@ -1375,11 +1463,15 @@ function longestMatch(...args) {
1375
1463
  result,
1376
1464
  consumed
1377
1465
  };
1378
- } else if (error.consumed < result.consumed) error = result;
1466
+ } else {
1467
+ const match = require_passthrough.getOptionMatch(parser, childContext.state, context.buffer[0]);
1468
+ if (result.consumed > 0 && match != null) consumingFailure = require_passthrough.retainConsumingFailure(consumingFailure, result, match.priority);
1469
+ if (error.consumed < result.consumed) error = result;
1470
+ }
1379
1471
  }
1380
1472
  const optionsTerminatorResolution = resolveLongestMatchOptionsTerminator(context, bestMatch, optionsTerminatorMatches);
1381
1473
  if (optionsTerminatorResolution != null) return optionsTerminatorResolution;
1382
- if (bestMatch != null) return commitLongestMatch(context, bestMatch);
1474
+ if (bestMatch != null) return commitLongestMatch(context, bestMatch, void 0, consumingFailure);
1383
1475
  return {
1384
1476
  ...error,
1385
1477
  success: false
@@ -1445,6 +1537,14 @@ function longestMatch(...args) {
1445
1537
  const multiDependencyMetadata = composeExclusiveDependencyMetadata(parsers);
1446
1538
  if (multiDependencyMetadata != null) multiResult.dependencyMetadata = multiDependencyMetadata;
1447
1539
  require_parser.defineInheritedAnnotationParser(multiResult);
1540
+ require_passthrough.defineOptionMatch(multiResult, (state, token) => require_passthrough.combineOptionMatches(parsers.map((parser, index) => {
1541
+ const active = normalizeExclusiveState(state);
1542
+ return require_passthrough.getOptionMatch(parser, active?.[0] === index && active[1].success ? active[1].next.state : parser.initialState, token);
1543
+ })));
1544
+ require_passthrough.definePassThroughPriority(multiResult, parsers, (state, token) => {
1545
+ const active = normalizeExclusiveState(state);
1546
+ return require_passthrough.combinePassThroughPriorities(parsers.map((parser, index) => require_passthrough.getPassThroughPriority(parser, active?.[0] === index && active[1].success ? active[1].next.state : parser.initialState, token)));
1547
+ });
1448
1548
  return multiResult;
1449
1549
  }
1450
1550
  /**
@@ -1835,6 +1935,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
1835
1935
  const parserKeys = Reflect.ownKeys(parsers);
1836
1936
  const parserPairs = parserKeys.map((k) => [k, parsers[k]]);
1837
1937
  parserPairs.sort(([_, parserA], [__, parserB]) => parserB.priority - parserA.priority);
1938
+ const passThroughParsers = new Set(parserPairs.map(([, parser]) => parser).filter((parser) => require_passthrough.hasPassThroughUsage(parser.usage)));
1838
1939
  const createInitialState = () => {
1839
1940
  const state = {};
1840
1941
  for (const key of parserKeys) state[key] = parsers[key].initialState;
@@ -1883,6 +1984,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
1883
1984
  success: true,
1884
1985
  next: {
1885
1986
  ...context,
1987
+ ...require_passthrough.getPassThroughFailureHint(result.next),
1886
1988
  buffer: result.next.buffer,
1887
1989
  optionsTerminated: result.next.optionsTerminated,
1888
1990
  state: nextState,
@@ -1919,16 +2021,19 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
1919
2021
  let anySuccess = false;
1920
2022
  const allConsumed = [];
1921
2023
  const consumedFields = /* @__PURE__ */ new Set();
2024
+ let consumingFailure;
1922
2025
  let madeProgress = true;
1923
2026
  while (madeProgress && currentContext.buffer.length > 0) {
1924
2027
  madeProgress = false;
2028
+ consumingFailure = void 0;
1925
2029
  const getFieldState = createFieldStateGetter(currentContext.state, getObjectParseChildState);
1926
- for (const [field, parser] of parserPairs) {
1927
- const result = parser.parse(withChildContext$1(currentContext, field, getFieldState(field, parser), parser));
2030
+ for (const [field, parser] of orderBeforePassThrough(parserPairs, currentContext, ([, parser$1]) => parser$1, ([field$1, parser$1]) => getFieldState(field$1, parser$1), passThroughParsers)) {
2031
+ const result = parser.parse(require_passthrough.withPassThroughFailure(withChildContext$1(currentContext, field, getFieldState(field, parser), parser), consumingFailure, require_passthrough.getPassThroughPriority(parser, getFieldState(field, parser), currentContext.buffer[0])));
1928
2032
  if (result.success && result.consumed.length > 0) {
1929
2033
  const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
1930
2034
  currentContext = {
1931
2035
  ...currentContext,
2036
+ ...require_passthrough.getPassThroughFailureHint(result.next),
1932
2037
  buffer: result.next.buffer,
1933
2038
  optionsTerminated: result.next.optionsTerminated,
1934
2039
  state: {
@@ -1946,7 +2051,12 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
1946
2051
  madeProgress = true;
1947
2052
  consumedFields.add(field);
1948
2053
  break;
1949
- } else if (!result.success && error.consumed < result.consumed) error = result;
2054
+ } else if (result.success) consumingFailure = require_passthrough.retainConsumingFailureHint(consumingFailure, currentContext, result.next);
2055
+ else {
2056
+ const match = require_passthrough.getOptionMatch(parser, getFieldState(field, parser), currentContext.buffer[0]);
2057
+ if (result.consumed > 0 && match != null) consumingFailure = require_passthrough.retainConsumingFailure(consumingFailure, result, match.priority);
2058
+ if (error.consumed < result.consumed) error = result;
2059
+ }
1950
2060
  }
1951
2061
  }
1952
2062
  {
@@ -1956,7 +2066,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
1956
2066
  const typedParser = parser;
1957
2067
  if (parser.leadingNames.size > 0 || typedParser.acceptingAnyToken) continue;
1958
2068
  const fieldState = getFieldState(field, parser);
1959
- const result = typedParser.parse(withChildContext$1(currentContext, field, fieldState, parser));
2069
+ const result = typedParser.parse(require_passthrough.withPassThroughFailure(withChildContext$1(currentContext, field, fieldState, parser), consumingFailure, require_passthrough.getPassThroughPriority(parser, getFieldState(field, parser), currentContext.buffer[0])));
1960
2070
  if (result.success && result.consumed.length === 0 && result.next.state !== fieldState) {
1961
2071
  const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
1962
2072
  currentContext = {
@@ -1976,7 +2086,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
1976
2086
  }
1977
2087
  if (anySuccess) return {
1978
2088
  success: true,
1979
- next: currentContext,
2089
+ next: require_passthrough.withPassThroughFailure(currentContext, consumingFailure),
1980
2090
  consumed: allConsumed
1981
2091
  };
1982
2092
  if (currentContext.buffer.length === 0) {
@@ -2016,17 +2126,20 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2016
2126
  let anySuccess = false;
2017
2127
  const allConsumed = [];
2018
2128
  const consumedFields = /* @__PURE__ */ new Set();
2129
+ let consumingFailure;
2019
2130
  let madeProgress = true;
2020
2131
  while (madeProgress && currentContext.buffer.length > 0) {
2021
2132
  madeProgress = false;
2133
+ consumingFailure = void 0;
2022
2134
  const getFieldState = createFieldStateGetter(currentContext.state, getObjectParseChildState);
2023
- for (const [field, parser] of parserPairs) {
2024
- const resultOrPromise = parser.parse(withChildContext$1(currentContext, field, getFieldState(field, parser), parser));
2135
+ for (const [field, parser] of orderBeforePassThrough(parserPairs, currentContext, ([, parser$1]) => parser$1, ([field$1, parser$1]) => getFieldState(field$1, parser$1), passThroughParsers)) {
2136
+ const resultOrPromise = parser.parse(require_passthrough.withPassThroughFailure(withChildContext$1(currentContext, field, getFieldState(field, parser), parser), consumingFailure, require_passthrough.getPassThroughPriority(parser, getFieldState(field, parser), currentContext.buffer[0])));
2025
2137
  const result = await resultOrPromise;
2026
2138
  if (result.success && result.consumed.length > 0) {
2027
2139
  const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
2028
2140
  currentContext = {
2029
2141
  ...currentContext,
2142
+ ...require_passthrough.getPassThroughFailureHint(result.next),
2030
2143
  buffer: result.next.buffer,
2031
2144
  optionsTerminated: result.next.optionsTerminated,
2032
2145
  state: {
@@ -2044,7 +2157,12 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2044
2157
  madeProgress = true;
2045
2158
  consumedFields.add(field);
2046
2159
  break;
2047
- } else if (!result.success && error.consumed < result.consumed) error = result;
2160
+ } else if (result.success) consumingFailure = require_passthrough.retainConsumingFailureHint(consumingFailure, currentContext, result.next);
2161
+ else {
2162
+ const match = require_passthrough.getOptionMatch(parser, getFieldState(field, parser), currentContext.buffer[0]);
2163
+ if (result.consumed > 0 && match != null) consumingFailure = require_passthrough.retainConsumingFailure(consumingFailure, result, match.priority);
2164
+ if (error.consumed < result.consumed) error = result;
2165
+ }
2048
2166
  }
2049
2167
  }
2050
2168
  {
@@ -2053,7 +2171,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2053
2171
  if (consumedFields.has(field)) continue;
2054
2172
  if (parser.leadingNames.size > 0 || parser.acceptingAnyToken) continue;
2055
2173
  const fieldState = getFieldState(field, parser);
2056
- const resultOrPromise = parser.parse(withChildContext$1(currentContext, field, fieldState, parser));
2174
+ const resultOrPromise = parser.parse(require_passthrough.withPassThroughFailure(withChildContext$1(currentContext, field, fieldState, parser), consumingFailure, require_passthrough.getPassThroughPriority(parser, getFieldState(field, parser), currentContext.buffer[0])));
2057
2175
  const result = await resultOrPromise;
2058
2176
  if (result.success && result.consumed.length === 0 && result.next.state !== fieldState) {
2059
2177
  const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
@@ -2074,7 +2192,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2074
2192
  }
2075
2193
  if (anySuccess) return {
2076
2194
  success: true,
2077
- next: currentContext,
2195
+ next: require_passthrough.withPassThroughFailure(currentContext, consumingFailure),
2078
2196
  consumed: allConsumed
2079
2197
  };
2080
2198
  if (currentContext.buffer.length === 0) {
@@ -2408,6 +2526,8 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2408
2526
  });
2409
2527
  require_parser.defineParseLanes(objectParser, objectParseLanes);
2410
2528
  require_parser.defineInheritedAnnotationParser(objectParser);
2529
+ require_passthrough.defineOptionMatch(objectParser, (state, token) => require_passthrough.combineOptionMatches(parserPairs.map(([field, parser]) => require_passthrough.getOptionMatch(parser, getAnnotatedFieldState(state, typeof field === "number" ? String(field) : field, parser), token))));
2530
+ require_passthrough.definePassThroughPriority(objectParser, parserPairs.map(([, parser]) => parser), (state, token) => require_passthrough.combinePassThroughPriorities(parserPairs.map(([field, parser]) => require_passthrough.getPassThroughPriority(parser, getAnnotatedFieldState(state, typeof field === "number" ? String(field) : field, parser), token))));
2411
2531
  return objectParser;
2412
2532
  }
2413
2533
  function suggestTupleSync(context, prefix, parsers) {
@@ -2495,6 +2615,7 @@ function advanceTupleSuggestContextSync(context, parsers) {
2495
2615
  const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
2496
2616
  currentContext = {
2497
2617
  ...currentContext,
2618
+ ...require_passthrough.getPassThroughFailureHint(result.next),
2498
2619
  buffer: result.next.buffer,
2499
2620
  optionsTerminated: result.next.optionsTerminated,
2500
2621
  state: newStateArray,
@@ -2561,6 +2682,7 @@ async function advanceTupleSuggestContextAsync(context, parsers) {
2561
2682
  const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
2562
2683
  currentContext = {
2563
2684
  ...currentContext,
2685
+ ...require_passthrough.getPassThroughFailureHint(result.next),
2564
2686
  buffer: result.next.buffer,
2565
2687
  optionsTerminated: result.next.optionsTerminated,
2566
2688
  state: newStateArray,
@@ -2660,10 +2782,12 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2660
2782
  const combinedMode = parsers.some((p) => p.mode === "async") ? "async" : "sync";
2661
2783
  const syncParsers = parsers;
2662
2784
  if (!options.allowDuplicates) checkDuplicateOptionNames(parsers.map((parser, index) => [String(index), parser.usage]));
2785
+ const passThroughParsers = new Set(parsers.filter((parser) => require_passthrough.hasPassThroughUsage(parser.usage)));
2663
2786
  const parseSync = (context) => {
2664
2787
  let currentContext = context;
2665
2788
  const allConsumed = [];
2666
2789
  const matchedParsers = /* @__PURE__ */ new Set();
2790
+ let consumingFailure;
2667
2791
  while (matchedParsers.size < syncParsers.length) {
2668
2792
  let foundMatch = false;
2669
2793
  let error = {
@@ -2671,14 +2795,15 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2671
2795
  error: require_message.message`No remaining parsers could match the input.`
2672
2796
  };
2673
2797
  const stateArray = currentContext.state;
2674
- const remainingParsers = syncParsers.map((parser, index) => [parser, index]).filter(([_, index]) => !matchedParsers.has(index)).sort(([parserA], [parserB]) => parserB.priority - parserA.priority);
2798
+ const remainingParsers = orderBeforePassThrough(syncParsers.map((parser, index) => [parser, index]).filter(([parser, index]) => !matchedParsers.has(index) || require_passthrough.getOptionMatch(parser, stateArray[index], currentContext.buffer[0])?.continuesCommand === true || passThroughParsers.size > 0 && !currentContext.optionsTerminated && require_passthrough.getOptionMatch(parser, stateArray[index], currentContext.buffer[0]) != null).sort(([parserA], [parserB]) => parserB.priority - parserA.priority), currentContext, ([parser]) => parser, ([, index]) => stateArray[index], passThroughParsers);
2675
2799
  for (const [parser, index] of remainingParsers) {
2676
- const result = parser.parse(withChildContext$1(currentContext, index, stateArray[index], parser));
2800
+ const result = parser.parse(require_passthrough.withPassThroughFailure(withChildContext$1(currentContext, index, stateArray[index], parser), consumingFailure, require_passthrough.getPassThroughPriority(parser, stateArray[index], currentContext.buffer[0])));
2677
2801
  if (result.success && result.consumed.length > 0) {
2678
2802
  const newStateArray = require_annotations.annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? require_annotation_state.getWrappedChildState(currentContext.state, result.next.state, parser) : s));
2679
2803
  const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
2680
2804
  currentContext = {
2681
2805
  ...currentContext,
2806
+ ...require_passthrough.getPassThroughFailureHint(result.next),
2682
2807
  buffer: result.next.buffer,
2683
2808
  optionsTerminated: result.next.optionsTerminated,
2684
2809
  state: newStateArray,
@@ -2687,14 +2812,21 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2687
2812
  dependencyRegistry: mergedExec.dependencyRegistry
2688
2813
  } : {}
2689
2814
  };
2815
+ consumingFailure = void 0;
2690
2816
  allConsumed.push(...result.consumed);
2691
2817
  matchedParsers.add(index);
2692
2818
  foundMatch = true;
2693
2819
  break;
2694
- } else if (!result.success && error.consumed < result.consumed) error = result;
2820
+ } else if (result.success) consumingFailure = require_passthrough.retainConsumingFailureHint(consumingFailure, currentContext, result.next);
2821
+ else {
2822
+ const match = require_passthrough.getOptionMatch(parser, stateArray[index], currentContext.buffer[0]);
2823
+ if (result.consumed > 0 && match != null) consumingFailure = require_passthrough.retainConsumingFailure(consumingFailure, result, match.priority);
2824
+ if (error.consumed < result.consumed) error = result;
2825
+ }
2695
2826
  }
2696
2827
  if (!foundMatch) for (const [parser, index] of remainingParsers) {
2697
- const result = parser.parse(withChildContext$1(currentContext, index, stateArray[index], parser));
2828
+ if (matchedParsers.has(index)) continue;
2829
+ const result = parser.parse(require_passthrough.withPassThroughFailure(withChildContext$1(currentContext, index, stateArray[index], parser), consumingFailure, require_passthrough.getPassThroughPriority(parser, stateArray[index], currentContext.buffer[0])));
2698
2830
  if (result.success && result.consumed.length < 1) {
2699
2831
  const newStateArray = require_annotations.annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? require_annotation_state.getWrappedChildState(currentContext.state, result.next.state, parser) : s));
2700
2832
  const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
@@ -2722,7 +2854,7 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2722
2854
  }
2723
2855
  return {
2724
2856
  success: true,
2725
- next: currentContext,
2857
+ next: require_passthrough.withPassThroughFailure(currentContext, consumingFailure),
2726
2858
  consumed: allConsumed
2727
2859
  };
2728
2860
  };
@@ -2730,6 +2862,7 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2730
2862
  let currentContext = context;
2731
2863
  const allConsumed = [];
2732
2864
  const matchedParsers = /* @__PURE__ */ new Set();
2865
+ let consumingFailure;
2733
2866
  while (matchedParsers.size < parsers.length) {
2734
2867
  let foundMatch = false;
2735
2868
  let error = {
@@ -2737,15 +2870,16 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2737
2870
  error: require_message.message`No remaining parsers could match the input.`
2738
2871
  };
2739
2872
  const stateArray = currentContext.state;
2740
- const remainingParsers = parsers.map((parser, index) => [parser, index]).filter(([_, index]) => !matchedParsers.has(index)).sort(([parserA], [parserB]) => parserB.priority - parserA.priority);
2873
+ const remainingParsers = orderBeforePassThrough(parsers.map((parser, index) => [parser, index]).filter(([parser, index]) => !matchedParsers.has(index) || require_passthrough.getOptionMatch(parser, stateArray[index], currentContext.buffer[0])?.continuesCommand === true || passThroughParsers.size > 0 && !currentContext.optionsTerminated && require_passthrough.getOptionMatch(parser, stateArray[index], currentContext.buffer[0]) != null).sort(([parserA], [parserB]) => parserB.priority - parserA.priority), currentContext, ([parser]) => parser, ([, index]) => stateArray[index], passThroughParsers);
2741
2874
  for (const [parser, index] of remainingParsers) {
2742
- const resultOrPromise = parser.parse(withChildContext$1(currentContext, index, stateArray[index], parser));
2875
+ const resultOrPromise = parser.parse(require_passthrough.withPassThroughFailure(withChildContext$1(currentContext, index, stateArray[index], parser), consumingFailure, require_passthrough.getPassThroughPriority(parser, stateArray[index], currentContext.buffer[0])));
2743
2876
  const result = await resultOrPromise;
2744
2877
  if (result.success && result.consumed.length > 0) {
2745
2878
  const newStateArray = require_annotations.annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? require_annotation_state.getWrappedChildState(currentContext.state, result.next.state, parser) : s));
2746
2879
  const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
2747
2880
  currentContext = {
2748
2881
  ...currentContext,
2882
+ ...require_passthrough.getPassThroughFailureHint(result.next),
2749
2883
  buffer: result.next.buffer,
2750
2884
  optionsTerminated: result.next.optionsTerminated,
2751
2885
  state: newStateArray,
@@ -2754,14 +2888,21 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2754
2888
  dependencyRegistry: mergedExec.dependencyRegistry
2755
2889
  } : {}
2756
2890
  };
2891
+ consumingFailure = void 0;
2757
2892
  allConsumed.push(...result.consumed);
2758
2893
  matchedParsers.add(index);
2759
2894
  foundMatch = true;
2760
2895
  break;
2761
- } else if (!result.success && error.consumed < result.consumed) error = result;
2896
+ } else if (result.success) consumingFailure = require_passthrough.retainConsumingFailureHint(consumingFailure, currentContext, result.next);
2897
+ else {
2898
+ const match = require_passthrough.getOptionMatch(parser, stateArray[index], currentContext.buffer[0]);
2899
+ if (result.consumed > 0 && match != null) consumingFailure = require_passthrough.retainConsumingFailure(consumingFailure, result, match.priority);
2900
+ if (error.consumed < result.consumed) error = result;
2901
+ }
2762
2902
  }
2763
2903
  if (!foundMatch) for (const [parser, index] of remainingParsers) {
2764
- const resultOrPromise = parser.parse(withChildContext$1(currentContext, index, stateArray[index], parser));
2904
+ if (matchedParsers.has(index)) continue;
2905
+ const resultOrPromise = parser.parse(require_passthrough.withPassThroughFailure(withChildContext$1(currentContext, index, stateArray[index], parser), consumingFailure, require_passthrough.getPassThroughPriority(parser, stateArray[index], currentContext.buffer[0])));
2765
2906
  const result = await resultOrPromise;
2766
2907
  if (result.success && result.consumed.length < 1) {
2767
2908
  const newStateArray = require_annotations.annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? require_annotation_state.getWrappedChildState(currentContext.state, result.next.state, parser) : s));
@@ -2790,7 +2931,7 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2790
2931
  }
2791
2932
  return {
2792
2933
  success: true,
2793
- next: currentContext,
2934
+ next: require_passthrough.withPassThroughFailure(currentContext, consumingFailure),
2794
2935
  consumed: allConsumed
2795
2936
  };
2796
2937
  };
@@ -3039,6 +3180,8 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3039
3180
  enumerable: false
3040
3181
  });
3041
3182
  require_parser.defineInheritedAnnotationParser(tupleParser);
3183
+ require_passthrough.defineOptionMatch(tupleParser, (state, token) => require_passthrough.combineOptionMatches(parsers.map((parser, index) => require_passthrough.getOptionMatch(parser, require_annotation_state.getWrappedChildState(state, state[index], parser), token))));
3184
+ require_passthrough.definePassThroughPriority(tupleParser, parsers, (state, token) => require_passthrough.combinePassThroughPriorities(parsers.map((parser, index) => require_passthrough.getPassThroughPriority(parser, require_annotation_state.getWrappedChildState(state, state[index], parser), token))));
3042
3185
  return tupleParser;
3043
3186
  }
3044
3187
  function merge(...args) {
@@ -3122,6 +3265,7 @@ function merge(...args) {
3122
3265
  success: true,
3123
3266
  next: {
3124
3267
  ...context,
3268
+ ...require_passthrough.getPassThroughFailureHint(result.next),
3125
3269
  buffer: result.next.buffer,
3126
3270
  optionsTerminated: result.next.optionsTerminated,
3127
3271
  state: newState,
@@ -3227,6 +3371,7 @@ function merge(...args) {
3227
3371
  const mergedExec = require_execution_context.mergeChildExec(settledContext.exec, result.next.exec);
3228
3372
  settledContext = {
3229
3373
  ...settledContext,
3374
+ ...require_passthrough.getPassThroughFailureHint(result.next),
3230
3375
  buffer: result.next.buffer,
3231
3376
  optionsTerminated: result.next.optionsTerminated,
3232
3377
  state: nextState,
@@ -3259,6 +3404,7 @@ function merge(...args) {
3259
3404
  const newState = mergeResultState(parser, currentContext, parserState, result, i);
3260
3405
  const newContext = {
3261
3406
  ...currentContext,
3407
+ ...require_passthrough.getPassThroughFailureHint(result.next),
3262
3408
  buffer: result.next.buffer,
3263
3409
  optionsTerminated: result.next.optionsTerminated,
3264
3410
  state: newState,
@@ -3304,6 +3450,7 @@ function merge(...args) {
3304
3450
  const newState = mergeResultState(parser, currentContext, parserState, result, i);
3305
3451
  const newContext = {
3306
3452
  ...currentContext,
3453
+ ...require_passthrough.getPassThroughFailureHint(result.next),
3307
3454
  buffer: result.next.buffer,
3308
3455
  optionsTerminated: result.next.optionsTerminated,
3309
3456
  state: newState,
@@ -3343,10 +3490,12 @@ function merge(...args) {
3343
3490
  const consumedLanes = /* @__PURE__ */ new Set();
3344
3491
  const consumedGroups = /* @__PURE__ */ new Set();
3345
3492
  const laneResults = /* @__PURE__ */ new Map();
3493
+ let consumingFailure;
3346
3494
  let attemptedLane = false;
3347
3495
  let madeProgress = true;
3348
3496
  while (madeProgress && currentContext.buffer.length > 0) {
3349
3497
  madeProgress = false;
3498
+ consumingFailure = void 0;
3350
3499
  let consumingError = null;
3351
3500
  for (const lane of mergeParseLanes) {
3352
3501
  if (consumingError != null && lane.priority < consumingError.priority) {
@@ -3364,6 +3513,10 @@ function merge(...args) {
3364
3513
  break;
3365
3514
  }
3366
3515
  if (!result.success) {
3516
+ if (result.consumed > 0 && require_passthrough.matchesOptionToken({
3517
+ leadingNames: lane.leadingNames,
3518
+ usage: parsers.flatMap((parser) => parser.usage)
3519
+ }, currentContext.buffer[0])) consumingFailure = require_passthrough.retainConsumingFailure(consumingFailure, result, lane.priority);
3367
3520
  if (result.consumed > 0 && consumingError == null) consumingError = {
3368
3521
  priority: lane.priority,
3369
3522
  result
@@ -3395,7 +3548,7 @@ function merge(...args) {
3395
3548
  }
3396
3549
  return {
3397
3550
  success: true,
3398
- next: currentContext,
3551
+ next: require_passthrough.withPassThroughFailure(currentContext, consumingFailure),
3399
3552
  consumed: allConsumed
3400
3553
  };
3401
3554
  };
@@ -3406,10 +3559,12 @@ function merge(...args) {
3406
3559
  const consumedLanes = /* @__PURE__ */ new Set();
3407
3560
  const consumedGroups = /* @__PURE__ */ new Set();
3408
3561
  const laneResults = /* @__PURE__ */ new Map();
3562
+ let consumingFailure;
3409
3563
  let attemptedLane = false;
3410
3564
  let madeProgress = true;
3411
3565
  while (madeProgress && currentContext.buffer.length > 0) {
3412
3566
  madeProgress = false;
3567
+ consumingFailure = void 0;
3413
3568
  let consumingError = null;
3414
3569
  for (const lane of mergeParseLanes) {
3415
3570
  if (consumingError != null && lane.priority < consumingError.priority) {
@@ -3427,6 +3582,10 @@ function merge(...args) {
3427
3582
  break;
3428
3583
  }
3429
3584
  if (!result.success) {
3585
+ if (result.consumed > 0 && require_passthrough.matchesOptionToken({
3586
+ leadingNames: lane.leadingNames,
3587
+ usage: parsers.flatMap((parser) => parser.usage)
3588
+ }, currentContext.buffer[0])) consumingFailure = require_passthrough.retainConsumingFailure(consumingFailure, result, lane.priority);
3430
3589
  if (result.consumed > 0 && consumingError == null) consumingError = {
3431
3590
  priority: lane.priority,
3432
3591
  result
@@ -3458,7 +3617,7 @@ function merge(...args) {
3458
3617
  }
3459
3618
  return {
3460
3619
  success: true,
3461
- next: currentContext,
3620
+ next: require_passthrough.withPassThroughFailure(currentContext, consumingFailure),
3462
3621
  consumed: allConsumed
3463
3622
  };
3464
3623
  };
@@ -3941,6 +4100,8 @@ function merge(...args) {
3941
4100
  };
3942
4101
  require_parser.defineParseLanes(mergeParser, mergeParseLanes);
3943
4102
  require_parser.defineInheritedAnnotationParser(mergeParser);
4103
+ require_passthrough.defineOptionMatch(mergeParser, (state, token) => require_passthrough.combineOptionMatches(sorted.map(([parser], index) => require_passthrough.getOptionMatch(parser, extractParserState(parser, state, index), token))));
4104
+ require_passthrough.definePassThroughPriority(mergeParser, parsers, (state, token) => require_passthrough.combinePassThroughPriorities(sorted.map(([parser], index) => require_passthrough.getPassThroughPriority(parser, extractParserState(parser, state, index), token))));
3944
4105
  return mergeParser;
3945
4106
  }
3946
4107
  /**
@@ -4131,6 +4292,7 @@ function tryParseSuggestList(context, stateArray, parsers, matchedParsers, remai
4131
4292
  const mergedExec = require_execution_context.mergeChildExec(context.exec, result$1.next.exec);
4132
4293
  return preParseSuggestLoop({
4133
4294
  ...context,
4295
+ ...require_passthrough.getPassThroughFailureHint(result$1.next),
4134
4296
  buffer: result$1.next.buffer,
4135
4297
  optionsTerminated: result$1.next.optionsTerminated,
4136
4298
  state: stateArray,
@@ -4158,6 +4320,7 @@ function tryParseSuggestList(context, stateArray, parsers, matchedParsers, remai
4158
4320
  const mergedExec = require_execution_context.mergeChildExec(context.exec, result.next.exec);
4159
4321
  return {
4160
4322
  ...context,
4323
+ ...require_passthrough.getPassThroughFailureHint(result.next),
4161
4324
  buffer: result.next.buffer,
4162
4325
  optionsTerminated: result.next.optionsTerminated,
4163
4326
  state: stateArray,
@@ -4177,10 +4340,12 @@ function concat(...parsers) {
4177
4340
  const isAsync = combinedMode === "async";
4178
4341
  const syncParsers = parsers;
4179
4342
  const initialState = parsers.map((parser) => parser.initialState);
4343
+ const passThroughParsers = new Set(parsers.filter((parser) => require_passthrough.hasPassThroughUsage(parser.usage)));
4180
4344
  const parseSync = (context) => {
4181
4345
  let currentContext = context;
4182
4346
  const allConsumed = [];
4183
4347
  const matchedParsers = /* @__PURE__ */ new Set();
4348
+ let consumingFailure;
4184
4349
  while (matchedParsers.size < syncParsers.length) {
4185
4350
  let foundMatch = false;
4186
4351
  let error = {
@@ -4188,14 +4353,15 @@ function concat(...parsers) {
4188
4353
  error: require_message.message`No remaining parsers could match the input.`
4189
4354
  };
4190
4355
  const stateArray = currentContext.state;
4191
- const remainingParsers = syncParsers.map((parser, index) => [parser, index]).filter(([_, index]) => !matchedParsers.has(index)).sort(([parserA], [parserB]) => parserB.priority - parserA.priority);
4356
+ const remainingParsers = orderBeforePassThrough(syncParsers.map((parser, index) => [parser, index]).filter(([parser, index]) => !matchedParsers.has(index) || require_passthrough.getOptionMatch(parser, stateArray[index], currentContext.buffer[0])?.continuesCommand === true || passThroughParsers.size > 0 && !currentContext.optionsTerminated && require_passthrough.getOptionMatch(parser, stateArray[index], currentContext.buffer[0]) != null).sort(([parserA], [parserB]) => parserB.priority - parserA.priority), currentContext, ([parser]) => parser, ([, index]) => stateArray[index], passThroughParsers);
4192
4357
  for (const [parser, index] of remainingParsers) {
4193
- const result = parser.parse(withChildContext$1(currentContext, index, stateArray[index], parser));
4358
+ const result = parser.parse(require_passthrough.withPassThroughFailure(withChildContext$1(currentContext, index, stateArray[index], parser), consumingFailure, require_passthrough.getPassThroughPriority(parser, stateArray[index], currentContext.buffer[0])));
4194
4359
  if (result.success && result.consumed.length > 0) {
4195
4360
  const newStateArray = require_annotations.annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? require_annotation_state.getWrappedChildState(currentContext.state, result.next.state, parser) : s));
4196
4361
  const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
4197
4362
  currentContext = {
4198
4363
  ...currentContext,
4364
+ ...require_passthrough.getPassThroughFailureHint(result.next),
4199
4365
  buffer: result.next.buffer,
4200
4366
  optionsTerminated: result.next.optionsTerminated,
4201
4367
  state: newStateArray,
@@ -4204,14 +4370,21 @@ function concat(...parsers) {
4204
4370
  dependencyRegistry: mergedExec.dependencyRegistry
4205
4371
  } : {}
4206
4372
  };
4373
+ consumingFailure = void 0;
4207
4374
  allConsumed.push(...result.consumed);
4208
4375
  matchedParsers.add(index);
4209
4376
  foundMatch = true;
4210
4377
  break;
4211
- } else if (!result.success && error.consumed < result.consumed) error = result;
4378
+ } else if (result.success) consumingFailure = require_passthrough.retainConsumingFailureHint(consumingFailure, currentContext, result.next);
4379
+ else {
4380
+ const match = require_passthrough.getOptionMatch(parser, stateArray[index], currentContext.buffer[0]);
4381
+ if (result.consumed > 0 && match != null) consumingFailure = require_passthrough.retainConsumingFailure(consumingFailure, result, match.priority);
4382
+ if (error.consumed < result.consumed) error = result;
4383
+ }
4212
4384
  }
4213
4385
  if (!foundMatch) for (const [parser, index] of remainingParsers) {
4214
- const result = parser.parse(withChildContext$1(currentContext, index, stateArray[index], parser));
4386
+ if (matchedParsers.has(index)) continue;
4387
+ const result = parser.parse(require_passthrough.withPassThroughFailure(withChildContext$1(currentContext, index, stateArray[index], parser), consumingFailure, require_passthrough.getPassThroughPriority(parser, stateArray[index], currentContext.buffer[0])));
4215
4388
  if (result.success && result.consumed.length < 1) {
4216
4389
  const newStateArray = require_annotations.annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? require_annotation_state.getWrappedChildState(currentContext.state, result.next.state, parser) : s));
4217
4390
  const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
@@ -4239,7 +4412,7 @@ function concat(...parsers) {
4239
4412
  }
4240
4413
  return {
4241
4414
  success: true,
4242
- next: currentContext,
4415
+ next: require_passthrough.withPassThroughFailure(currentContext, consumingFailure),
4243
4416
  consumed: allConsumed
4244
4417
  };
4245
4418
  };
@@ -4247,6 +4420,7 @@ function concat(...parsers) {
4247
4420
  let currentContext = context;
4248
4421
  const allConsumed = [];
4249
4422
  const matchedParsers = /* @__PURE__ */ new Set();
4423
+ let consumingFailure;
4250
4424
  while (matchedParsers.size < parsers.length) {
4251
4425
  let foundMatch = false;
4252
4426
  let error = {
@@ -4254,14 +4428,15 @@ function concat(...parsers) {
4254
4428
  error: require_message.message`No remaining parsers could match the input.`
4255
4429
  };
4256
4430
  const stateArray = currentContext.state;
4257
- const remainingParsers = parsers.map((parser, index) => [parser, index]).filter(([_, index]) => !matchedParsers.has(index)).sort(([parserA], [parserB]) => parserB.priority - parserA.priority);
4431
+ const remainingParsers = orderBeforePassThrough(parsers.map((parser, index) => [parser, index]).filter(([parser, index]) => !matchedParsers.has(index) || require_passthrough.getOptionMatch(parser, stateArray[index], currentContext.buffer[0])?.continuesCommand === true || passThroughParsers.size > 0 && !currentContext.optionsTerminated && require_passthrough.getOptionMatch(parser, stateArray[index], currentContext.buffer[0]) != null).sort(([parserA], [parserB]) => parserB.priority - parserA.priority), currentContext, ([parser]) => parser, ([, index]) => stateArray[index], passThroughParsers);
4258
4432
  for (const [parser, index] of remainingParsers) {
4259
- const result = await parser.parse(withChildContext$1(currentContext, index, stateArray[index], parser));
4433
+ const result = await parser.parse(require_passthrough.withPassThroughFailure(withChildContext$1(currentContext, index, stateArray[index], parser), consumingFailure, require_passthrough.getPassThroughPriority(parser, stateArray[index], currentContext.buffer[0])));
4260
4434
  if (result.success && result.consumed.length > 0) {
4261
4435
  const newStateArray = require_annotations.annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? require_annotation_state.getWrappedChildState(currentContext.state, result.next.state, parser) : s));
4262
4436
  const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
4263
4437
  currentContext = {
4264
4438
  ...currentContext,
4439
+ ...require_passthrough.getPassThroughFailureHint(result.next),
4265
4440
  buffer: result.next.buffer,
4266
4441
  optionsTerminated: result.next.optionsTerminated,
4267
4442
  state: newStateArray,
@@ -4270,14 +4445,21 @@ function concat(...parsers) {
4270
4445
  dependencyRegistry: mergedExec.dependencyRegistry
4271
4446
  } : {}
4272
4447
  };
4448
+ consumingFailure = void 0;
4273
4449
  allConsumed.push(...result.consumed);
4274
4450
  matchedParsers.add(index);
4275
4451
  foundMatch = true;
4276
4452
  break;
4277
- } else if (!result.success && error.consumed < result.consumed) error = result;
4453
+ } else if (result.success) consumingFailure = require_passthrough.retainConsumingFailureHint(consumingFailure, currentContext, result.next);
4454
+ else {
4455
+ const match = require_passthrough.getOptionMatch(parser, stateArray[index], currentContext.buffer[0]);
4456
+ if (result.consumed > 0 && match != null) consumingFailure = require_passthrough.retainConsumingFailure(consumingFailure, result, match.priority);
4457
+ if (error.consumed < result.consumed) error = result;
4458
+ }
4278
4459
  }
4279
4460
  if (!foundMatch) for (const [parser, index] of remainingParsers) {
4280
- const result = await parser.parse(withChildContext$1(currentContext, index, stateArray[index], parser));
4461
+ if (matchedParsers.has(index)) continue;
4462
+ const result = await parser.parse(require_passthrough.withPassThroughFailure(withChildContext$1(currentContext, index, stateArray[index], parser), consumingFailure, require_passthrough.getPassThroughPriority(parser, stateArray[index], currentContext.buffer[0])));
4281
4463
  if (result.success && result.consumed.length < 1) {
4282
4464
  const newStateArray = require_annotations.annotateFreshArray(currentContext.state, stateArray.map((s, idx) => idx === index ? require_annotation_state.getWrappedChildState(currentContext.state, result.next.state, parser) : s));
4283
4465
  const mergedExec = require_execution_context.mergeChildExec(currentContext.exec, result.next.exec);
@@ -4305,7 +4487,7 @@ function concat(...parsers) {
4305
4487
  }
4306
4488
  return {
4307
4489
  success: true,
4308
- next: currentContext,
4490
+ next: require_passthrough.withPassThroughFailure(currentContext, consumingFailure),
4309
4491
  consumed: allConsumed
4310
4492
  };
4311
4493
  };
@@ -4551,6 +4733,8 @@ function concat(...parsers) {
4551
4733
  }
4552
4734
  };
4553
4735
  require_parser.defineInheritedAnnotationParser(concatParser);
4736
+ require_passthrough.defineOptionMatch(concatParser, (state, token) => require_passthrough.combineOptionMatches(parsers.map((parser, index) => require_passthrough.getOptionMatch(parser, require_annotation_state.getWrappedChildState(state, state[index], parser), token))));
4737
+ require_passthrough.definePassThroughPriority(concatParser, parsers, (state, token) => require_passthrough.combinePassThroughPriorities(parsers.map((parser, index) => require_passthrough.getPassThroughPriority(parser, require_annotation_state.getWrappedChildState(state, state[index], parser), token))));
4554
4738
  return concatParser;
4555
4739
  }
4556
4740
  function group(label, parser, options = {}) {
@@ -4642,6 +4826,9 @@ function group(label, parser, options = {}) {
4642
4826
  configurable: true,
4643
4827
  enumerable: false
4644
4828
  });
4829
+ require_passthrough.delegateKnownCompletion(groupParser, parser);
4830
+ require_passthrough.defineOptionMatch(groupParser, (state, token) => require_passthrough.getOptionMatch(parser, state, token));
4831
+ require_passthrough.definePassThroughPriority(groupParser, [parser], (state, token) => require_passthrough.getPassThroughPriority(parser, state, token));
4645
4832
  return groupParser;
4646
4833
  }
4647
4834
  /**
@@ -4792,6 +4979,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
4792
4979
  dependencyRegistry: discriminatorExec.dependencyRegistry
4793
4980
  } : {}
4794
4981
  }, "_branch", branchParser.initialState, branchParser, branchParser.usage),
4982
+ ...require_passthrough.getPassThroughFailureHint(discriminatorResult.next),
4795
4983
  buffer: discriminatorResult.next.buffer,
4796
4984
  optionsTerminated: discriminatorResult.next.optionsTerminated
4797
4985
  });
@@ -4913,6 +5101,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
4913
5101
  const discriminatorExec = require_execution_context.mergeChildExec(context.exec, discriminatorResult.next.exec);
4914
5102
  const speculationContext = {
4915
5103
  ...context,
5104
+ ...require_passthrough.getPassThroughFailureHint(discriminatorResult.next),
4916
5105
  buffer: discriminatorResult.next.buffer,
4917
5106
  optionsTerminated: discriminatorResult.next.optionsTerminated,
4918
5107
  ...discriminatorExec != null ? {
@@ -5040,6 +5229,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
5040
5229
  dependencyRegistry: discriminatorExec.dependencyRegistry
5041
5230
  } : {}
5042
5231
  }, "_branch", branchParser.initialState, branchParser, branchParser.usage),
5232
+ ...require_passthrough.getPassThroughFailureHint(discriminatorResult.next),
5043
5233
  buffer: discriminatorResult.next.buffer,
5044
5234
  optionsTerminated: discriminatorResult.next.optionsTerminated
5045
5235
  });
@@ -5607,6 +5797,36 @@ function conditional(discriminator, branches, defaultBranch, options) {
5607
5797
  }
5608
5798
  };
5609
5799
  require_parser.defineInheritedAnnotationParser(conditionalParser);
5800
+ const reachableBranches = (state) => {
5801
+ if (state.selectedBranch != null) {
5802
+ const branch = state.selectedBranch.kind === "default" ? defaultBranch : branches[state.selectedBranch.key];
5803
+ return branch == null ? [] : [{
5804
+ branch,
5805
+ state: state.branchState
5806
+ }];
5807
+ }
5808
+ const known = require_passthrough.getKnownCompletion(discriminator, state.discriminatorState);
5809
+ if (known != null) {
5810
+ const branch = typeof known.value === "string" ? branches[known.value] : void 0;
5811
+ const reachable = branch ?? defaultBranch;
5812
+ return reachable == null ? [] : [{
5813
+ branch: reachable,
5814
+ state: reachable.initialState
5815
+ }];
5816
+ }
5817
+ return allBranchParsers.map((branch) => ({
5818
+ branch,
5819
+ state: branch.initialState
5820
+ }));
5821
+ };
5822
+ require_passthrough.definePassThroughPriority(conditionalParser, [discriminator, ...allBranchParsers], (state, token) => require_passthrough.combinePassThroughPriorities([...state.selectedBranch == null ? [require_passthrough.getPassThroughPriority(discriminator, state.discriminatorState, token)] : [], ...reachableBranches(state).map(({ branch, state: state$1 }) => require_passthrough.getPassThroughPriority(branch, state$1, token))]));
5823
+ require_passthrough.defineOptionMatch(conditionalParser, (state, token) => {
5824
+ if (state.selectedBranch != null) {
5825
+ const branch = state.selectedBranch.kind === "default" ? defaultBranch : branches[state.selectedBranch.key];
5826
+ return branch == null ? void 0 : require_passthrough.getOptionMatch(branch, state.branchState, token);
5827
+ }
5828
+ return require_passthrough.combineOptionMatches([require_passthrough.getOptionMatch(discriminator, state.discriminatorState, token), ...reachableBranches(state).map(({ branch, state: state$1 }) => require_passthrough.getOptionMatch(branch, state$1, token))]);
5829
+ });
5610
5830
  return conditionalParser;
5611
5831
  }
5612
5832