@optique/core 1.0.0-dev.1699 → 1.0.0-dev.1703

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.
@@ -513,81 +513,77 @@ function createExclusiveComplete(parsers, options, noMatchContext, mode) {
513
513
  const syncParsers = parsers;
514
514
  return (state, exec) => {
515
515
  const activeState = normalizeExclusiveState(state);
516
- if (activeState == null) {
517
- const annotations = require_annotations.getAnnotations(state);
518
- const annotateInitial = (initial) => annotations != null && initial != null && typeof initial === "object" ? require_annotations.injectAnnotations(initial, annotations) : initial;
519
- return require_mode_dispatch.dispatchByMode(mode, () => {
520
- const emptyCtx = {
521
- buffer: [],
522
- optionsTerminated: false,
523
- usage: []
524
- };
525
- let candidateIndex = -1;
526
- let candidateCount = 0;
527
- for (let i$1 = 0; i$1 < syncParsers.length; i$1++) {
528
- const p = syncParsers[i$1];
529
- if (p.leadingNames.size > 0 || p.acceptingAnyToken) continue;
530
- const parseResult = p.parse({
531
- ...emptyCtx,
532
- state: annotateInitial(p.initialState)
533
- });
534
- if (!parseResult.success || parseResult.provisional) continue;
535
- candidateCount++;
536
- if (candidateIndex < 0) candidateIndex = i$1;
537
- if (candidateCount > 1) break;
538
- }
539
- if (candidateCount === 1 && candidateIndex >= 0) {
540
- const p = syncParsers[candidateIndex];
541
- const parseResult = p.parse({
542
- ...emptyCtx,
543
- state: annotateInitial(p.initialState)
544
- });
545
- if (parseResult.success) {
546
- const annotatedState = getAnnotatedChildState(state, parseResult.next.state, p);
547
- return p.complete(annotatedState, withChildExecPath(exec, candidateIndex));
548
- }
549
- }
550
- return {
551
- success: false,
552
- error: getNoMatchError(options, noMatchContext)
553
- };
554
- }, async () => {
555
- const emptyCtx = {
556
- buffer: [],
557
- optionsTerminated: false,
558
- usage: []
559
- };
560
- let candidateIndex = -1;
561
- let candidateCount = 0;
562
- for (let i$1 = 0; i$1 < parsers.length; i$1++) {
563
- const p = parsers[i$1];
564
- if (p.leadingNames.size > 0 || p.acceptingAnyToken) continue;
565
- const parseResult = await p.parse({
566
- ...emptyCtx,
567
- state: annotateInitial(p.initialState)
568
- });
569
- if (!parseResult.success || parseResult.provisional) continue;
570
- candidateCount++;
571
- if (candidateIndex < 0) candidateIndex = i$1;
572
- if (candidateCount > 1) break;
516
+ if (activeState == null) return require_mode_dispatch.dispatchByMode(mode, () => {
517
+ const emptyCtx = {
518
+ buffer: [],
519
+ optionsTerminated: false,
520
+ usage: []
521
+ };
522
+ let candidateIndex = -1;
523
+ let candidateCount = 0;
524
+ for (let i$1 = 0; i$1 < syncParsers.length; i$1++) {
525
+ const p = syncParsers[i$1];
526
+ if (p.leadingNames.size > 0 || p.acceptingAnyToken) continue;
527
+ const parseResult = p.parse({
528
+ ...emptyCtx,
529
+ state: getAnnotatedChildState(state, p.initialState, p)
530
+ });
531
+ if (!parseResult.success || parseResult.provisional) continue;
532
+ candidateCount++;
533
+ if (candidateIndex < 0) candidateIndex = i$1;
534
+ if (candidateCount > 1) break;
535
+ }
536
+ if (candidateCount === 1 && candidateIndex >= 0) {
537
+ const p = syncParsers[candidateIndex];
538
+ const parseResult = p.parse({
539
+ ...emptyCtx,
540
+ state: getAnnotatedChildState(state, p.initialState, p)
541
+ });
542
+ if (parseResult.success) {
543
+ const annotatedState = getAnnotatedChildState(state, parseResult.next.state, p);
544
+ return p.complete(annotatedState, withChildExecPath(exec, candidateIndex));
573
545
  }
574
- if (candidateCount === 1 && candidateIndex >= 0 && (parsers[candidateIndex].$mode === "sync" || exec?.phase !== "parse" && exec?.phase !== "suggest")) {
575
- const p = parsers[candidateIndex];
576
- const parseResult = await p.parse({
577
- ...emptyCtx,
578
- state: annotateInitial(p.initialState)
579
- });
580
- if (parseResult.success) {
581
- const annotatedState = getAnnotatedChildState(state, parseResult.next.state, p);
582
- return await p.complete(annotatedState, withChildExecPath(exec, candidateIndex));
583
- }
546
+ }
547
+ return {
548
+ success: false,
549
+ error: getNoMatchError(options, noMatchContext)
550
+ };
551
+ }, async () => {
552
+ const emptyCtx = {
553
+ buffer: [],
554
+ optionsTerminated: false,
555
+ usage: []
556
+ };
557
+ let candidateIndex = -1;
558
+ let candidateCount = 0;
559
+ for (let i$1 = 0; i$1 < parsers.length; i$1++) {
560
+ const p = parsers[i$1];
561
+ if (p.leadingNames.size > 0 || p.acceptingAnyToken) continue;
562
+ const parseResult = await p.parse({
563
+ ...emptyCtx,
564
+ state: getAnnotatedChildState(state, p.initialState, p)
565
+ });
566
+ if (!parseResult.success || parseResult.provisional) continue;
567
+ candidateCount++;
568
+ if (candidateIndex < 0) candidateIndex = i$1;
569
+ if (candidateCount > 1) break;
570
+ }
571
+ if (candidateCount === 1 && candidateIndex >= 0 && (parsers[candidateIndex].$mode === "sync" || exec?.phase !== "parse" && exec?.phase !== "suggest")) {
572
+ const p = parsers[candidateIndex];
573
+ const parseResult = await p.parse({
574
+ ...emptyCtx,
575
+ state: getAnnotatedChildState(state, p.initialState, p)
576
+ });
577
+ if (parseResult.success) {
578
+ const annotatedState = getAnnotatedChildState(state, parseResult.next.state, p);
579
+ return await p.complete(annotatedState, withChildExecPath(exec, candidateIndex));
584
580
  }
585
- return {
586
- success: false,
587
- error: getNoMatchError(options, noMatchContext)
588
- };
589
- });
590
- }
581
+ }
582
+ return {
583
+ success: false,
584
+ error: getNoMatchError(options, noMatchContext)
585
+ };
586
+ });
591
587
  const [i, result] = activeState;
592
588
  if (!result.success) return {
593
589
  success: false,
@@ -3843,6 +3839,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
3843
3839
  consumed: defaultResult.consumed
3844
3840
  };
3845
3841
  }
3842
+ if (!defaultResult.success && defaultResult.consumed > 0) return defaultResult;
3846
3843
  }
3847
3844
  return {
3848
3845
  success: false,
@@ -4013,6 +4010,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
4013
4010
  consumed: defaultResult.consumed
4014
4011
  };
4015
4012
  }
4013
+ if (!defaultResult.success && defaultResult.consumed > 0) return defaultResult;
4016
4014
  }
4017
4015
  return {
4018
4016
  success: false,
@@ -513,81 +513,77 @@ function createExclusiveComplete(parsers, options, noMatchContext, mode) {
513
513
  const syncParsers = parsers;
514
514
  return (state, exec) => {
515
515
  const activeState = normalizeExclusiveState(state);
516
- if (activeState == null) {
517
- const annotations = getAnnotations(state);
518
- const annotateInitial = (initial) => annotations != null && initial != null && typeof initial === "object" ? injectAnnotations(initial, annotations) : initial;
519
- return dispatchByMode(mode, () => {
520
- const emptyCtx = {
521
- buffer: [],
522
- optionsTerminated: false,
523
- usage: []
524
- };
525
- let candidateIndex = -1;
526
- let candidateCount = 0;
527
- for (let i$1 = 0; i$1 < syncParsers.length; i$1++) {
528
- const p = syncParsers[i$1];
529
- if (p.leadingNames.size > 0 || p.acceptingAnyToken) continue;
530
- const parseResult = p.parse({
531
- ...emptyCtx,
532
- state: annotateInitial(p.initialState)
533
- });
534
- if (!parseResult.success || parseResult.provisional) continue;
535
- candidateCount++;
536
- if (candidateIndex < 0) candidateIndex = i$1;
537
- if (candidateCount > 1) break;
538
- }
539
- if (candidateCount === 1 && candidateIndex >= 0) {
540
- const p = syncParsers[candidateIndex];
541
- const parseResult = p.parse({
542
- ...emptyCtx,
543
- state: annotateInitial(p.initialState)
544
- });
545
- if (parseResult.success) {
546
- const annotatedState = getAnnotatedChildState(state, parseResult.next.state, p);
547
- return p.complete(annotatedState, withChildExecPath(exec, candidateIndex));
548
- }
549
- }
550
- return {
551
- success: false,
552
- error: getNoMatchError(options, noMatchContext)
553
- };
554
- }, async () => {
555
- const emptyCtx = {
556
- buffer: [],
557
- optionsTerminated: false,
558
- usage: []
559
- };
560
- let candidateIndex = -1;
561
- let candidateCount = 0;
562
- for (let i$1 = 0; i$1 < parsers.length; i$1++) {
563
- const p = parsers[i$1];
564
- if (p.leadingNames.size > 0 || p.acceptingAnyToken) continue;
565
- const parseResult = await p.parse({
566
- ...emptyCtx,
567
- state: annotateInitial(p.initialState)
568
- });
569
- if (!parseResult.success || parseResult.provisional) continue;
570
- candidateCount++;
571
- if (candidateIndex < 0) candidateIndex = i$1;
572
- if (candidateCount > 1) break;
516
+ if (activeState == null) return dispatchByMode(mode, () => {
517
+ const emptyCtx = {
518
+ buffer: [],
519
+ optionsTerminated: false,
520
+ usage: []
521
+ };
522
+ let candidateIndex = -1;
523
+ let candidateCount = 0;
524
+ for (let i$1 = 0; i$1 < syncParsers.length; i$1++) {
525
+ const p = syncParsers[i$1];
526
+ if (p.leadingNames.size > 0 || p.acceptingAnyToken) continue;
527
+ const parseResult = p.parse({
528
+ ...emptyCtx,
529
+ state: getAnnotatedChildState(state, p.initialState, p)
530
+ });
531
+ if (!parseResult.success || parseResult.provisional) continue;
532
+ candidateCount++;
533
+ if (candidateIndex < 0) candidateIndex = i$1;
534
+ if (candidateCount > 1) break;
535
+ }
536
+ if (candidateCount === 1 && candidateIndex >= 0) {
537
+ const p = syncParsers[candidateIndex];
538
+ const parseResult = p.parse({
539
+ ...emptyCtx,
540
+ state: getAnnotatedChildState(state, p.initialState, p)
541
+ });
542
+ if (parseResult.success) {
543
+ const annotatedState = getAnnotatedChildState(state, parseResult.next.state, p);
544
+ return p.complete(annotatedState, withChildExecPath(exec, candidateIndex));
573
545
  }
574
- if (candidateCount === 1 && candidateIndex >= 0 && (parsers[candidateIndex].$mode === "sync" || exec?.phase !== "parse" && exec?.phase !== "suggest")) {
575
- const p = parsers[candidateIndex];
576
- const parseResult = await p.parse({
577
- ...emptyCtx,
578
- state: annotateInitial(p.initialState)
579
- });
580
- if (parseResult.success) {
581
- const annotatedState = getAnnotatedChildState(state, parseResult.next.state, p);
582
- return await p.complete(annotatedState, withChildExecPath(exec, candidateIndex));
583
- }
546
+ }
547
+ return {
548
+ success: false,
549
+ error: getNoMatchError(options, noMatchContext)
550
+ };
551
+ }, async () => {
552
+ const emptyCtx = {
553
+ buffer: [],
554
+ optionsTerminated: false,
555
+ usage: []
556
+ };
557
+ let candidateIndex = -1;
558
+ let candidateCount = 0;
559
+ for (let i$1 = 0; i$1 < parsers.length; i$1++) {
560
+ const p = parsers[i$1];
561
+ if (p.leadingNames.size > 0 || p.acceptingAnyToken) continue;
562
+ const parseResult = await p.parse({
563
+ ...emptyCtx,
564
+ state: getAnnotatedChildState(state, p.initialState, p)
565
+ });
566
+ if (!parseResult.success || parseResult.provisional) continue;
567
+ candidateCount++;
568
+ if (candidateIndex < 0) candidateIndex = i$1;
569
+ if (candidateCount > 1) break;
570
+ }
571
+ if (candidateCount === 1 && candidateIndex >= 0 && (parsers[candidateIndex].$mode === "sync" || exec?.phase !== "parse" && exec?.phase !== "suggest")) {
572
+ const p = parsers[candidateIndex];
573
+ const parseResult = await p.parse({
574
+ ...emptyCtx,
575
+ state: getAnnotatedChildState(state, p.initialState, p)
576
+ });
577
+ if (parseResult.success) {
578
+ const annotatedState = getAnnotatedChildState(state, parseResult.next.state, p);
579
+ return await p.complete(annotatedState, withChildExecPath(exec, candidateIndex));
584
580
  }
585
- return {
586
- success: false,
587
- error: getNoMatchError(options, noMatchContext)
588
- };
589
- });
590
- }
581
+ }
582
+ return {
583
+ success: false,
584
+ error: getNoMatchError(options, noMatchContext)
585
+ };
586
+ });
591
587
  const [i, result] = activeState;
592
588
  if (!result.success) return {
593
589
  success: false,
@@ -3843,6 +3839,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
3843
3839
  consumed: defaultResult.consumed
3844
3840
  };
3845
3841
  }
3842
+ if (!defaultResult.success && defaultResult.consumed > 0) return defaultResult;
3846
3843
  }
3847
3844
  return {
3848
3845
  success: false,
@@ -4013,6 +4010,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
4013
4010
  consumed: defaultResult.consumed
4014
4011
  };
4015
4012
  }
4013
+ if (!defaultResult.success && defaultResult.consumed > 0) return defaultResult;
4016
4014
  }
4017
4015
  return {
4018
4016
  success: false,
@@ -6,10 +6,10 @@ const require_parser = require('./parser.cjs');
6
6
 
7
7
  //#region src/modifiers.ts
8
8
  /**
9
- * Internal marker for optional-style wrappers (`optional()`, `withDefault()`).
10
- * Used by `object()`'s zero-consumption pass to skip these parsers, since they
11
- * should return `undefined`/default when the user provides no input rather than
12
- * running the inner parser.
9
+ * Internal marker for wrappers that should be skipped by `object()`'s
10
+ * zero-consumption pass. Set on `optional()`, `withDefault()`, and
11
+ * `prompt()`, since these wrappers have their own completion semantics
12
+ * that should not be short-circuited during parse.
13
13
  *
14
14
  * @internal
15
15
  */
@@ -4,10 +4,10 @@ import { Mode, Parser } from "./parser.cjs";
4
4
  //#region src/modifiers.d.ts
5
5
 
6
6
  /**
7
- * Internal marker for optional-style wrappers (`optional()`, `withDefault()`).
8
- * Used by `object()`'s zero-consumption pass to skip these parsers, since they
9
- * should return `undefined`/default when the user provides no input rather than
10
- * running the inner parser.
7
+ * Internal marker for wrappers that should be skipped by `object()`'s
8
+ * zero-consumption pass. Set on `optional()`, `withDefault()`, and
9
+ * `prompt()`, since these wrappers have their own completion semantics
10
+ * that should not be short-circuited during parse.
11
11
  *
12
12
  * @internal
13
13
  */
@@ -4,10 +4,10 @@ import { Mode, Parser } from "./parser.js";
4
4
  //#region src/modifiers.d.ts
5
5
 
6
6
  /**
7
- * Internal marker for optional-style wrappers (`optional()`, `withDefault()`).
8
- * Used by `object()`'s zero-consumption pass to skip these parsers, since they
9
- * should return `undefined`/default when the user provides no input rather than
10
- * running the inner parser.
7
+ * Internal marker for wrappers that should be skipped by `object()`'s
8
+ * zero-consumption pass. Set on `optional()`, `withDefault()`, and
9
+ * `prompt()`, since these wrappers have their own completion semantics
10
+ * that should not be short-circuited during parse.
11
11
  *
12
12
  * @internal
13
13
  */
package/dist/modifiers.js CHANGED
@@ -6,10 +6,10 @@ import { defineInheritedAnnotationParser, defineSourceBindingOnlyAnnotationCompl
6
6
 
7
7
  //#region src/modifiers.ts
8
8
  /**
9
- * Internal marker for optional-style wrappers (`optional()`, `withDefault()`).
10
- * Used by `object()`'s zero-consumption pass to skip these parsers, since they
11
- * should return `undefined`/default when the user provides no input rather than
12
- * running the inner parser.
9
+ * Internal marker for wrappers that should be skipped by `object()`'s
10
+ * zero-consumption pass. Set on `optional()`, `withDefault()`, and
11
+ * `prompt()`, since these wrappers have their own completion semantics
12
+ * that should not be short-circuited during parse.
13
13
  *
14
14
  * @internal
15
15
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.1699+b919c678",
3
+ "version": "1.0.0-dev.1703+58b70f2a",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",