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