@optique/core 1.0.0-dev.921 → 1.0.1

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.
Files changed (109) hide show
  1. package/dist/annotation-state.cjs +425 -0
  2. package/dist/annotation-state.d.cts +24 -0
  3. package/dist/annotation-state.d.ts +24 -0
  4. package/dist/annotation-state.js +414 -0
  5. package/dist/annotations.cjs +2 -248
  6. package/dist/annotations.d.cts +2 -137
  7. package/dist/annotations.d.ts +2 -137
  8. package/dist/annotations.js +2 -238
  9. package/dist/completion.cjs +611 -100
  10. package/dist/completion.d.cts +1 -1
  11. package/dist/completion.d.ts +1 -1
  12. package/dist/completion.js +611 -100
  13. package/dist/constructs.cjs +3338 -827
  14. package/dist/constructs.d.cts +48 -7
  15. package/dist/constructs.d.ts +48 -7
  16. package/dist/constructs.js +3338 -827
  17. package/dist/context.cjs +0 -23
  18. package/dist/context.d.cts +119 -53
  19. package/dist/context.d.ts +119 -53
  20. package/dist/context.js +0 -22
  21. package/dist/dependency-metadata.cjs +139 -0
  22. package/dist/dependency-metadata.d.cts +112 -0
  23. package/dist/dependency-metadata.d.ts +112 -0
  24. package/dist/dependency-metadata.js +138 -0
  25. package/dist/dependency-runtime.cjs +698 -0
  26. package/dist/dependency-runtime.d.cts +149 -0
  27. package/dist/dependency-runtime.d.ts +149 -0
  28. package/dist/dependency-runtime.js +687 -0
  29. package/dist/dependency.cjs +7 -928
  30. package/dist/dependency.d.cts +2 -794
  31. package/dist/dependency.d.ts +2 -794
  32. package/dist/dependency.js +2 -899
  33. package/dist/displaywidth.cjs +44 -0
  34. package/dist/displaywidth.js +43 -0
  35. package/dist/doc.cjs +285 -23
  36. package/dist/doc.d.cts +57 -2
  37. package/dist/doc.d.ts +57 -2
  38. package/dist/doc.js +283 -25
  39. package/dist/execution-context.cjs +56 -0
  40. package/dist/execution-context.js +53 -0
  41. package/dist/extension.cjs +87 -0
  42. package/dist/extension.d.cts +97 -0
  43. package/dist/extension.d.ts +97 -0
  44. package/dist/extension.js +76 -0
  45. package/dist/facade.cjs +718 -525
  46. package/dist/facade.d.cts +59 -15
  47. package/dist/facade.d.ts +59 -15
  48. package/dist/facade.js +718 -525
  49. package/dist/index.cjs +14 -29
  50. package/dist/index.d.cts +10 -10
  51. package/dist/index.d.ts +10 -10
  52. package/dist/index.js +7 -7
  53. package/dist/input-trace.cjs +56 -0
  54. package/dist/input-trace.d.cts +77 -0
  55. package/dist/input-trace.d.ts +77 -0
  56. package/dist/input-trace.js +55 -0
  57. package/dist/internal/annotations.cjs +316 -0
  58. package/dist/internal/annotations.d.cts +140 -0
  59. package/dist/internal/annotations.d.ts +140 -0
  60. package/dist/internal/annotations.js +306 -0
  61. package/dist/internal/dependency.cjs +984 -0
  62. package/dist/internal/dependency.d.cts +539 -0
  63. package/dist/internal/dependency.d.ts +539 -0
  64. package/dist/internal/dependency.js +964 -0
  65. package/dist/{mode-dispatch.cjs → internal/mode-dispatch.cjs} +1 -3
  66. package/dist/{mode-dispatch.d.cts → internal/mode-dispatch.d.cts} +3 -7
  67. package/dist/{mode-dispatch.d.ts → internal/mode-dispatch.d.ts} +3 -7
  68. package/dist/{mode-dispatch.js → internal/mode-dispatch.js} +1 -3
  69. package/dist/internal/parser.cjs +728 -0
  70. package/dist/internal/parser.d.cts +947 -0
  71. package/dist/internal/parser.d.ts +947 -0
  72. package/dist/internal/parser.js +711 -0
  73. package/dist/message.cjs +84 -26
  74. package/dist/message.d.cts +49 -9
  75. package/dist/message.d.ts +49 -9
  76. package/dist/message.js +84 -27
  77. package/dist/modifiers.cjs +1023 -240
  78. package/dist/modifiers.d.cts +42 -1
  79. package/dist/modifiers.d.ts +42 -1
  80. package/dist/modifiers.js +1023 -240
  81. package/dist/parser.cjs +11 -463
  82. package/dist/parser.d.cts +3 -537
  83. package/dist/parser.d.ts +3 -537
  84. package/dist/parser.js +2 -433
  85. package/dist/phase2-seed.cjs +59 -0
  86. package/dist/phase2-seed.js +56 -0
  87. package/dist/primitives.cjs +557 -208
  88. package/dist/primitives.d.cts +10 -14
  89. package/dist/primitives.d.ts +10 -14
  90. package/dist/primitives.js +557 -208
  91. package/dist/program.cjs +5 -1
  92. package/dist/program.d.cts +5 -3
  93. package/dist/program.d.ts +5 -3
  94. package/dist/program.js +6 -1
  95. package/dist/suggestion.cjs +22 -8
  96. package/dist/suggestion.js +22 -8
  97. package/dist/usage-internals.cjs +3 -2
  98. package/dist/usage-internals.js +4 -2
  99. package/dist/usage.cjs +195 -40
  100. package/dist/usage.d.cts +92 -11
  101. package/dist/usage.d.ts +92 -11
  102. package/dist/usage.js +194 -41
  103. package/dist/validate.cjs +170 -0
  104. package/dist/validate.js +164 -0
  105. package/dist/valueparser.cjs +1270 -187
  106. package/dist/valueparser.d.cts +320 -14
  107. package/dist/valueparser.d.ts +320 -14
  108. package/dist/valueparser.js +1269 -188
  109. package/package.json +9 -9
@@ -1,6 +1,6 @@
1
1
  import { Message } from "./message.cjs";
2
2
  import { HiddenVisibility } from "./usage.cjs";
3
- import { CombineModes, InferValue, Mode, Parser, ParserResult } from "./parser.cjs";
3
+ import { CombineModes, InferValue, Mode, Parser, ParserResult } from "./internal/parser.cjs";
4
4
 
5
5
  //#region src/constructs.d.ts
6
6
 
@@ -730,6 +730,7 @@ declare function or<MA extends Mode, MB extends Mode, MC extends Mode, MD extend
730
730
  * @param options Custom error message options.
731
731
  * @return A {@link Parser} that tries to parse using the provided parsers
732
732
  * in order, returning the result of the first successful parser.
733
+ * @throws {TypeError} If no parser arguments are provided.
733
734
  * @since 0.5.0
734
735
  */
735
736
  declare function or<MA extends Mode, MB extends Mode, TA, TB, TStateA, TStateB>(a: Parser<MA, TA, TStateA>, b: Parser<MB, TB, TStateB>, options: OrOptions): Parser<CombineModes<readonly [MA, MB]>, TA | TB, undefined | [0, ParserResult<TStateA>] | [1, ParserResult<TStateB>]>;
@@ -751,6 +752,7 @@ declare function or<MA extends Mode, MB extends Mode, TA, TB, TStateA, TStateB>(
751
752
  * @param options Custom error message options.
752
753
  * @return A {@link Parser} that tries to parse using the provided parsers
753
754
  * in order, returning the result of the first successful parser.
755
+ * @throws {TypeError} If no parser arguments are provided.
754
756
  * @since 0.5.0
755
757
  */
756
758
  declare function or<MA extends Mode, MB extends Mode, MC extends Mode, TA, TB, TC, TStateA, TStateB, TStateC>(a: Parser<MA, TA, TStateA>, b: Parser<MB, TB, TStateB>, c: Parser<MC, TC, TStateC>, options: OrOptions): Parser<CombineModes<readonly [MA, MB, MC]>, TA | TB | TC, undefined | [0, ParserResult<TStateA>] | [1, ParserResult<TStateB>] | [2, ParserResult<TStateC>]>;
@@ -760,6 +762,7 @@ declare function or<MA extends Mode, MB extends Mode, MC extends Mode, TA, TB, T
760
762
  * @param rest Parsers to try, followed by {@link OrOptions} for error
761
763
  * customization.
762
764
  * @returns A parser that succeeds if any of the input parsers succeed.
765
+ * @throws {TypeError} If no parser arguments are provided.
763
766
  * @since 0.5.0
764
767
  */
765
768
  declare function or<const TParsers extends readonly Parser<Mode, unknown, unknown>[]>(...rest: [...parsers: TParsers, options: OrTailOptions] & OrArityGuard<TParsers>): Parser<CombineModes<{ readonly [K in keyof TParsers]: ExtractMode<TParsers[K]> }>, InferValue<TParsers[number]>, undefined | [number, ParserResult<unknown>]>;
@@ -767,6 +770,7 @@ declare function or<const TParsers extends readonly Parser<Mode, unknown, unknow
767
770
  * Creates a parser that tries each parser in sequence until one succeeds.
768
771
  * @param parsers Parsers to try in order.
769
772
  * @returns A parser that succeeds if any of the input parsers succeed.
773
+ * @throws {TypeError} If no parser arguments are provided.
770
774
  * @since 0.5.0
771
775
  */
772
776
  declare function or<const TParsers extends readonly Parser<Mode, unknown, unknown>[]>(...parsers: TParsers & OrArityGuard<TParsers>): Parser<CombineModes<{ readonly [K in keyof TParsers]: ExtractMode<TParsers[K]> }>, InferValue<TParsers[number]>, undefined | [number, ParserResult<unknown>]>;
@@ -860,6 +864,7 @@ declare function longestMatch<const TParsers extends readonly Parser<"sync", unk
860
864
  * @param rest Parsers to compare, followed by error customization options.
861
865
  * @returns A parser that yields the best successful branch result.
862
866
  * Type inference is precise for tuple calls up to 15 parser arguments.
867
+ * @throws {TypeError} If no parser arguments are provided.
863
868
  * @since 0.5.0
864
869
  */
865
870
  declare function longestMatch<const TParsers extends readonly Parser<"sync", unknown, unknown>[]>(...rest: [...parsers: TParsers, options: LongestMatchTailOptions] & LongestMatchArityGuard<TParsers>): Parser<"sync", InferValue<TParsers[number]>, LongestMatchState<TParsers>>;
@@ -870,6 +875,7 @@ declare function longestMatch<const TParsers extends readonly Parser<"sync", unk
870
875
  * @param rest Parsers to compare, followed by error customization options.
871
876
  * @returns A parser that yields the best successful branch result.
872
877
  * Type inference is precise for tuple calls up to 15 parser arguments.
878
+ * @throws {TypeError} If no parser arguments are provided.
873
879
  * @since 0.5.0
874
880
  */
875
881
  declare function longestMatch<const TParsers extends readonly Parser<Mode, unknown, unknown>[]>(...rest: [...parsers: TParsers, options: LongestMatchTailOptions] & LongestMatchArityGuard<TParsers>): Parser<CombineModes<{ readonly [K in keyof TParsers]: ExtractMode<TParsers[K]> }>, InferValue<TParsers[number]>, LongestMatchState<TParsers>>;
@@ -919,7 +925,8 @@ interface ObjectOptions {
919
925
  readonly errors?: ObjectErrorOptions;
920
926
  /**
921
927
  * When `true`, allows duplicate option names across different fields.
922
- * By default (`false`), duplicate option names will cause a parse error.
928
+ * By default (`false`), duplicate option names cause a construction-time
929
+ * error.
923
930
  *
924
931
  * @default `false`
925
932
  * @since 0.7.0
@@ -1017,6 +1024,8 @@ declare function object<T extends {
1017
1024
  * @returns A {@link Parser} that produces an object with the same keys as
1018
1025
  * the input, where each value is the result of the corresponding
1019
1026
  * parser.
1027
+ * @throws {TypeError} If the label is not a string, is empty,
1028
+ * whitespace-only, or contains control characters.
1020
1029
  */
1021
1030
  declare function object<T extends {
1022
1031
  readonly [key: string | symbol]: Parser<Mode, unknown, unknown>;
@@ -1034,6 +1043,8 @@ declare function object<T extends {
1034
1043
  * @returns A {@link Parser} that produces an object with the same keys as
1035
1044
  * the input, where each value is the result of the corresponding
1036
1045
  * parser.
1046
+ * @throws {TypeError} If the label is not a string, is empty,
1047
+ * whitespace-only, or contains control characters.
1037
1048
  * @since 0.5.0
1038
1049
  */
1039
1050
  declare function object<T extends {
@@ -1046,7 +1057,8 @@ declare function object<T extends {
1046
1057
  interface TupleOptions {
1047
1058
  /**
1048
1059
  * When `true`, allows duplicate option names across different parsers.
1049
- * By default (`false`), duplicate option names will cause a parse error.
1060
+ * By default (`false`), duplicate option names cause a construction-time
1061
+ * error.
1050
1062
  *
1051
1063
  * @default `false`
1052
1064
  * @since 0.7.0
@@ -1078,6 +1090,8 @@ declare function tuple<const T extends readonly Parser<Mode, unknown, unknown>[]
1078
1090
  * @returns A {@link Parser} that produces a readonly tuple with the same length
1079
1091
  * as the input array, where each element is the result of the
1080
1092
  * corresponding parser.
1093
+ * @throws {TypeError} If the label is not a string, is empty,
1094
+ * whitespace-only, or contains control characters.
1081
1095
  */
1082
1096
  declare function tuple<const T extends readonly Parser<Mode, unknown, unknown>[]>(label: string, parsers: T, options?: TupleOptions): Parser<CombineTupleModes<T>, { readonly [K in keyof T]: T[K]["$valueType"][number] extends (infer U) ? U : never }, { readonly [K in keyof T]: T[K]["$stateType"][number] extends (infer U2) ? U2 : never }>;
1083
1097
  /**
@@ -1097,7 +1111,8 @@ type ExtractObjectTypes<P> = P extends Parser<Mode, infer V, unknown> ? [AllObje
1097
1111
  interface MergeOptions {
1098
1112
  /**
1099
1113
  * When `true`, allows duplicate option names across merged parsers.
1100
- * By default (`false`), duplicate option names will cause a parse error.
1114
+ * By default (`false`), duplicate option names cause a construction-time
1115
+ * error.
1101
1116
  *
1102
1117
  * @default `false`
1103
1118
  * @since 0.7.0
@@ -1131,6 +1146,7 @@ type MergeReturnType<TParsers extends MergeParsers> = Parser<CombineModes<{ read
1131
1146
  * @param rest Parsers to merge, followed by merge options.
1132
1147
  * @returns A parser that merges parsed object fields from all parsers.
1133
1148
  * Type inference is precise for tuple calls up to 15 parser arguments.
1149
+ * @throws {TypeError} If no parser arguments are provided.
1134
1150
  * @since 0.7.0
1135
1151
  */
1136
1152
  declare function merge<const TParsers extends MergeParsers>(...rest: [...parsers: EnsureMergeParsers<TParsers>, options: MergeTailOptions] & MergeArityGuard<TParsers>): MergeReturnType<TParsers>;
@@ -1144,6 +1160,9 @@ declare function merge<const TParsers extends MergeParsers>(...rest: [...parsers
1144
1160
  * @param parsers Parsers to merge in declaration order.
1145
1161
  * @returns A parser that merges parsed object fields from all parsers.
1146
1162
  * Type inference is precise for tuple calls up to 15 parser arguments.
1163
+ * @throws {TypeError} If no parser arguments are provided.
1164
+ * @throws {TypeError} If the label is not a string, is empty,
1165
+ * whitespace-only, or contains control characters.
1147
1166
  * @since 0.4.0
1148
1167
  */
1149
1168
  declare function merge<const TParsers extends MergeParsers>(label: string, ...parsers: EnsureMergeParsers<TParsers> & MergeArityGuard<TParsers>): MergeReturnType<TParsers>;
@@ -1157,6 +1176,9 @@ declare function merge<const TParsers extends MergeParsers>(label: string, ...pa
1157
1176
  * @param rest Parsers to merge, followed by merge options.
1158
1177
  * @returns A parser that merges parsed object fields from all parsers.
1159
1178
  * Type inference is precise for tuple calls up to 15 parser arguments.
1179
+ * @throws {TypeError} If no parser arguments are provided.
1180
+ * @throws {TypeError} If the label is not a string, is empty,
1181
+ * whitespace-only, or contains control characters.
1160
1182
  * @since 0.7.0
1161
1183
  */
1162
1184
  declare function merge<const TParsers extends MergeParsers>(label: string, ...rest: [...parsers: EnsureMergeParsers<TParsers>, options: MergeTailOptions] & MergeArityGuard<TParsers>): MergeReturnType<TParsers>;
@@ -1169,6 +1191,7 @@ declare function merge<const TParsers extends MergeParsers>(label: string, ...re
1169
1191
  * @param parsers Parsers to merge in declaration order.
1170
1192
  * @returns A parser that merges parsed object fields from all parsers.
1171
1193
  * Type inference is precise for tuple calls up to 15 parser arguments.
1194
+ * @throws {TypeError} If no parser arguments are provided.
1172
1195
  * @since 0.1.0
1173
1196
  */
1174
1197
  declare function merge<const TParsers extends MergeParsers>(...parsers: EnsureMergeParsers<TParsers> & MergeArityGuard<TParsers>): MergeReturnType<TParsers>;
@@ -1216,6 +1239,7 @@ type ConcatValues<TParsers extends ConcatParsers> = IsTuple<TParsers> extends tr
1216
1239
  * @param parsers Tuple parsers to concatenate.
1217
1240
  * @returns A parser with flattened tuple values from all parsers.
1218
1241
  * Type inference is precise for tuple calls up to 15 parser arguments.
1242
+ * @throws {TypeError} If no parser arguments are provided.
1219
1243
  * @since 0.2.0
1220
1244
  */
1221
1245
  declare function concat<const TParsers extends ConcatParsers>(...parsers: TParsers & ConcatArityGuard<TParsers>): Parser<CombineModes<{ readonly [K in keyof TParsers]: ExtractMode<TParsers[K]> }>, ConcatValues<TParsers>, ConcatStates<TParsers>>;
@@ -1260,6 +1284,8 @@ declare function concat<const TParsers extends ConcatParsers>(...parsers: TParse
1260
1284
  * @param options Optional visibility controls for the wrapped parser terms.
1261
1285
  * @returns A new parser that behaves identically to the input parser
1262
1286
  * but generates documentation within a labeled section.
1287
+ * @throws {TypeError} If the label is not a string, is empty,
1288
+ * whitespace-only, or contains control characters.
1263
1289
  * @since 0.4.0
1264
1290
  */
1265
1291
  /**
@@ -1293,6 +1319,7 @@ interface ConditionalState<TDiscriminator extends string> {
1293
1319
  readonly discriminatorValue: TDiscriminator | undefined;
1294
1320
  readonly selectedBranch: SelectedBranch<TDiscriminator> | undefined;
1295
1321
  readonly branchState: unknown;
1322
+ readonly speculative?: true;
1296
1323
  }
1297
1324
  /**
1298
1325
  * Options for customizing error messages in the {@link conditional} combinator.
@@ -1303,11 +1330,25 @@ interface ConditionalErrorOptions {
1303
1330
  * Custom error message when branch parser fails.
1304
1331
  * Receives the discriminator value for context.
1305
1332
  */
1306
- branchError?: (discriminatorValue: string | undefined, error: Message) => Message;
1333
+ readonly branchError?: (discriminatorValue: string | undefined, error: Message) => Message;
1307
1334
  /**
1308
1335
  * Custom error message for no matching input.
1309
1336
  */
1310
- noMatch?: Message | ((context: NoMatchContext) => Message);
1337
+ readonly noMatch?: Message | ((context: NoMatchContext) => Message);
1338
+ /**
1339
+ * Custom error message when speculative branch parsing committed
1340
+ * to one branch but the resolved discriminator value names a
1341
+ * different branch. This is the contradictory-input case: tokens
1342
+ * specific to one branch were consumed during the parse phase,
1343
+ * but the discriminator (e.g., from `prompt()` or a deferred
1344
+ * config source) ultimately resolved to a different key.
1345
+ *
1346
+ * Receives both the discriminator value the parser actually
1347
+ * resolved to (`discriminatorValue`) and the speculative key the
1348
+ * branch tokens were committed to (`speculativeKey`).
1349
+ * @since 1.0.1
1350
+ */
1351
+ readonly branchMismatch?: (discriminatorValue: string, speculativeKey: string) => Message;
1311
1352
  }
1312
1353
  /**
1313
1354
  * Options for customizing the {@link conditional} combinator behavior.
@@ -1317,7 +1358,7 @@ interface ConditionalOptions {
1317
1358
  /**
1318
1359
  * Custom error messages.
1319
1360
  */
1320
- errors?: ConditionalErrorOptions;
1361
+ readonly errors?: ConditionalErrorOptions;
1321
1362
  }
1322
1363
  /**
1323
1364
  * Helper type to infer result type without default branch.
@@ -1,6 +1,6 @@
1
1
  import { Message } from "./message.js";
2
2
  import { HiddenVisibility } from "./usage.js";
3
- import { CombineModes, InferValue, Mode, Parser, ParserResult } from "./parser.js";
3
+ import { CombineModes, InferValue, Mode, Parser, ParserResult } from "./internal/parser.js";
4
4
 
5
5
  //#region src/constructs.d.ts
6
6
 
@@ -730,6 +730,7 @@ declare function or<MA extends Mode, MB extends Mode, MC extends Mode, MD extend
730
730
  * @param options Custom error message options.
731
731
  * @return A {@link Parser} that tries to parse using the provided parsers
732
732
  * in order, returning the result of the first successful parser.
733
+ * @throws {TypeError} If no parser arguments are provided.
733
734
  * @since 0.5.0
734
735
  */
735
736
  declare function or<MA extends Mode, MB extends Mode, TA, TB, TStateA, TStateB>(a: Parser<MA, TA, TStateA>, b: Parser<MB, TB, TStateB>, options: OrOptions): Parser<CombineModes<readonly [MA, MB]>, TA | TB, undefined | [0, ParserResult<TStateA>] | [1, ParserResult<TStateB>]>;
@@ -751,6 +752,7 @@ declare function or<MA extends Mode, MB extends Mode, TA, TB, TStateA, TStateB>(
751
752
  * @param options Custom error message options.
752
753
  * @return A {@link Parser} that tries to parse using the provided parsers
753
754
  * in order, returning the result of the first successful parser.
755
+ * @throws {TypeError} If no parser arguments are provided.
754
756
  * @since 0.5.0
755
757
  */
756
758
  declare function or<MA extends Mode, MB extends Mode, MC extends Mode, TA, TB, TC, TStateA, TStateB, TStateC>(a: Parser<MA, TA, TStateA>, b: Parser<MB, TB, TStateB>, c: Parser<MC, TC, TStateC>, options: OrOptions): Parser<CombineModes<readonly [MA, MB, MC]>, TA | TB | TC, undefined | [0, ParserResult<TStateA>] | [1, ParserResult<TStateB>] | [2, ParserResult<TStateC>]>;
@@ -760,6 +762,7 @@ declare function or<MA extends Mode, MB extends Mode, MC extends Mode, TA, TB, T
760
762
  * @param rest Parsers to try, followed by {@link OrOptions} for error
761
763
  * customization.
762
764
  * @returns A parser that succeeds if any of the input parsers succeed.
765
+ * @throws {TypeError} If no parser arguments are provided.
763
766
  * @since 0.5.0
764
767
  */
765
768
  declare function or<const TParsers extends readonly Parser<Mode, unknown, unknown>[]>(...rest: [...parsers: TParsers, options: OrTailOptions] & OrArityGuard<TParsers>): Parser<CombineModes<{ readonly [K in keyof TParsers]: ExtractMode<TParsers[K]> }>, InferValue<TParsers[number]>, undefined | [number, ParserResult<unknown>]>;
@@ -767,6 +770,7 @@ declare function or<const TParsers extends readonly Parser<Mode, unknown, unknow
767
770
  * Creates a parser that tries each parser in sequence until one succeeds.
768
771
  * @param parsers Parsers to try in order.
769
772
  * @returns A parser that succeeds if any of the input parsers succeed.
773
+ * @throws {TypeError} If no parser arguments are provided.
770
774
  * @since 0.5.0
771
775
  */
772
776
  declare function or<const TParsers extends readonly Parser<Mode, unknown, unknown>[]>(...parsers: TParsers & OrArityGuard<TParsers>): Parser<CombineModes<{ readonly [K in keyof TParsers]: ExtractMode<TParsers[K]> }>, InferValue<TParsers[number]>, undefined | [number, ParserResult<unknown>]>;
@@ -860,6 +864,7 @@ declare function longestMatch<const TParsers extends readonly Parser<"sync", unk
860
864
  * @param rest Parsers to compare, followed by error customization options.
861
865
  * @returns A parser that yields the best successful branch result.
862
866
  * Type inference is precise for tuple calls up to 15 parser arguments.
867
+ * @throws {TypeError} If no parser arguments are provided.
863
868
  * @since 0.5.0
864
869
  */
865
870
  declare function longestMatch<const TParsers extends readonly Parser<"sync", unknown, unknown>[]>(...rest: [...parsers: TParsers, options: LongestMatchTailOptions] & LongestMatchArityGuard<TParsers>): Parser<"sync", InferValue<TParsers[number]>, LongestMatchState<TParsers>>;
@@ -870,6 +875,7 @@ declare function longestMatch<const TParsers extends readonly Parser<"sync", unk
870
875
  * @param rest Parsers to compare, followed by error customization options.
871
876
  * @returns A parser that yields the best successful branch result.
872
877
  * Type inference is precise for tuple calls up to 15 parser arguments.
878
+ * @throws {TypeError} If no parser arguments are provided.
873
879
  * @since 0.5.0
874
880
  */
875
881
  declare function longestMatch<const TParsers extends readonly Parser<Mode, unknown, unknown>[]>(...rest: [...parsers: TParsers, options: LongestMatchTailOptions] & LongestMatchArityGuard<TParsers>): Parser<CombineModes<{ readonly [K in keyof TParsers]: ExtractMode<TParsers[K]> }>, InferValue<TParsers[number]>, LongestMatchState<TParsers>>;
@@ -919,7 +925,8 @@ interface ObjectOptions {
919
925
  readonly errors?: ObjectErrorOptions;
920
926
  /**
921
927
  * When `true`, allows duplicate option names across different fields.
922
- * By default (`false`), duplicate option names will cause a parse error.
928
+ * By default (`false`), duplicate option names cause a construction-time
929
+ * error.
923
930
  *
924
931
  * @default `false`
925
932
  * @since 0.7.0
@@ -1017,6 +1024,8 @@ declare function object<T extends {
1017
1024
  * @returns A {@link Parser} that produces an object with the same keys as
1018
1025
  * the input, where each value is the result of the corresponding
1019
1026
  * parser.
1027
+ * @throws {TypeError} If the label is not a string, is empty,
1028
+ * whitespace-only, or contains control characters.
1020
1029
  */
1021
1030
  declare function object<T extends {
1022
1031
  readonly [key: string | symbol]: Parser<Mode, unknown, unknown>;
@@ -1034,6 +1043,8 @@ declare function object<T extends {
1034
1043
  * @returns A {@link Parser} that produces an object with the same keys as
1035
1044
  * the input, where each value is the result of the corresponding
1036
1045
  * parser.
1046
+ * @throws {TypeError} If the label is not a string, is empty,
1047
+ * whitespace-only, or contains control characters.
1037
1048
  * @since 0.5.0
1038
1049
  */
1039
1050
  declare function object<T extends {
@@ -1046,7 +1057,8 @@ declare function object<T extends {
1046
1057
  interface TupleOptions {
1047
1058
  /**
1048
1059
  * When `true`, allows duplicate option names across different parsers.
1049
- * By default (`false`), duplicate option names will cause a parse error.
1060
+ * By default (`false`), duplicate option names cause a construction-time
1061
+ * error.
1050
1062
  *
1051
1063
  * @default `false`
1052
1064
  * @since 0.7.0
@@ -1078,6 +1090,8 @@ declare function tuple<const T extends readonly Parser<Mode, unknown, unknown>[]
1078
1090
  * @returns A {@link Parser} that produces a readonly tuple with the same length
1079
1091
  * as the input array, where each element is the result of the
1080
1092
  * corresponding parser.
1093
+ * @throws {TypeError} If the label is not a string, is empty,
1094
+ * whitespace-only, or contains control characters.
1081
1095
  */
1082
1096
  declare function tuple<const T extends readonly Parser<Mode, unknown, unknown>[]>(label: string, parsers: T, options?: TupleOptions): Parser<CombineTupleModes<T>, { readonly [K in keyof T]: T[K]["$valueType"][number] extends (infer U) ? U : never }, { readonly [K in keyof T]: T[K]["$stateType"][number] extends (infer U2) ? U2 : never }>;
1083
1097
  /**
@@ -1097,7 +1111,8 @@ type ExtractObjectTypes<P> = P extends Parser<Mode, infer V, unknown> ? [AllObje
1097
1111
  interface MergeOptions {
1098
1112
  /**
1099
1113
  * When `true`, allows duplicate option names across merged parsers.
1100
- * By default (`false`), duplicate option names will cause a parse error.
1114
+ * By default (`false`), duplicate option names cause a construction-time
1115
+ * error.
1101
1116
  *
1102
1117
  * @default `false`
1103
1118
  * @since 0.7.0
@@ -1131,6 +1146,7 @@ type MergeReturnType<TParsers extends MergeParsers> = Parser<CombineModes<{ read
1131
1146
  * @param rest Parsers to merge, followed by merge options.
1132
1147
  * @returns A parser that merges parsed object fields from all parsers.
1133
1148
  * Type inference is precise for tuple calls up to 15 parser arguments.
1149
+ * @throws {TypeError} If no parser arguments are provided.
1134
1150
  * @since 0.7.0
1135
1151
  */
1136
1152
  declare function merge<const TParsers extends MergeParsers>(...rest: [...parsers: EnsureMergeParsers<TParsers>, options: MergeTailOptions] & MergeArityGuard<TParsers>): MergeReturnType<TParsers>;
@@ -1144,6 +1160,9 @@ declare function merge<const TParsers extends MergeParsers>(...rest: [...parsers
1144
1160
  * @param parsers Parsers to merge in declaration order.
1145
1161
  * @returns A parser that merges parsed object fields from all parsers.
1146
1162
  * Type inference is precise for tuple calls up to 15 parser arguments.
1163
+ * @throws {TypeError} If no parser arguments are provided.
1164
+ * @throws {TypeError} If the label is not a string, is empty,
1165
+ * whitespace-only, or contains control characters.
1147
1166
  * @since 0.4.0
1148
1167
  */
1149
1168
  declare function merge<const TParsers extends MergeParsers>(label: string, ...parsers: EnsureMergeParsers<TParsers> & MergeArityGuard<TParsers>): MergeReturnType<TParsers>;
@@ -1157,6 +1176,9 @@ declare function merge<const TParsers extends MergeParsers>(label: string, ...pa
1157
1176
  * @param rest Parsers to merge, followed by merge options.
1158
1177
  * @returns A parser that merges parsed object fields from all parsers.
1159
1178
  * Type inference is precise for tuple calls up to 15 parser arguments.
1179
+ * @throws {TypeError} If no parser arguments are provided.
1180
+ * @throws {TypeError} If the label is not a string, is empty,
1181
+ * whitespace-only, or contains control characters.
1160
1182
  * @since 0.7.0
1161
1183
  */
1162
1184
  declare function merge<const TParsers extends MergeParsers>(label: string, ...rest: [...parsers: EnsureMergeParsers<TParsers>, options: MergeTailOptions] & MergeArityGuard<TParsers>): MergeReturnType<TParsers>;
@@ -1169,6 +1191,7 @@ declare function merge<const TParsers extends MergeParsers>(label: string, ...re
1169
1191
  * @param parsers Parsers to merge in declaration order.
1170
1192
  * @returns A parser that merges parsed object fields from all parsers.
1171
1193
  * Type inference is precise for tuple calls up to 15 parser arguments.
1194
+ * @throws {TypeError} If no parser arguments are provided.
1172
1195
  * @since 0.1.0
1173
1196
  */
1174
1197
  declare function merge<const TParsers extends MergeParsers>(...parsers: EnsureMergeParsers<TParsers> & MergeArityGuard<TParsers>): MergeReturnType<TParsers>;
@@ -1216,6 +1239,7 @@ type ConcatValues<TParsers extends ConcatParsers> = IsTuple<TParsers> extends tr
1216
1239
  * @param parsers Tuple parsers to concatenate.
1217
1240
  * @returns A parser with flattened tuple values from all parsers.
1218
1241
  * Type inference is precise for tuple calls up to 15 parser arguments.
1242
+ * @throws {TypeError} If no parser arguments are provided.
1219
1243
  * @since 0.2.0
1220
1244
  */
1221
1245
  declare function concat<const TParsers extends ConcatParsers>(...parsers: TParsers & ConcatArityGuard<TParsers>): Parser<CombineModes<{ readonly [K in keyof TParsers]: ExtractMode<TParsers[K]> }>, ConcatValues<TParsers>, ConcatStates<TParsers>>;
@@ -1260,6 +1284,8 @@ declare function concat<const TParsers extends ConcatParsers>(...parsers: TParse
1260
1284
  * @param options Optional visibility controls for the wrapped parser terms.
1261
1285
  * @returns A new parser that behaves identically to the input parser
1262
1286
  * but generates documentation within a labeled section.
1287
+ * @throws {TypeError} If the label is not a string, is empty,
1288
+ * whitespace-only, or contains control characters.
1263
1289
  * @since 0.4.0
1264
1290
  */
1265
1291
  /**
@@ -1293,6 +1319,7 @@ interface ConditionalState<TDiscriminator extends string> {
1293
1319
  readonly discriminatorValue: TDiscriminator | undefined;
1294
1320
  readonly selectedBranch: SelectedBranch<TDiscriminator> | undefined;
1295
1321
  readonly branchState: unknown;
1322
+ readonly speculative?: true;
1296
1323
  }
1297
1324
  /**
1298
1325
  * Options for customizing error messages in the {@link conditional} combinator.
@@ -1303,11 +1330,25 @@ interface ConditionalErrorOptions {
1303
1330
  * Custom error message when branch parser fails.
1304
1331
  * Receives the discriminator value for context.
1305
1332
  */
1306
- branchError?: (discriminatorValue: string | undefined, error: Message) => Message;
1333
+ readonly branchError?: (discriminatorValue: string | undefined, error: Message) => Message;
1307
1334
  /**
1308
1335
  * Custom error message for no matching input.
1309
1336
  */
1310
- noMatch?: Message | ((context: NoMatchContext) => Message);
1337
+ readonly noMatch?: Message | ((context: NoMatchContext) => Message);
1338
+ /**
1339
+ * Custom error message when speculative branch parsing committed
1340
+ * to one branch but the resolved discriminator value names a
1341
+ * different branch. This is the contradictory-input case: tokens
1342
+ * specific to one branch were consumed during the parse phase,
1343
+ * but the discriminator (e.g., from `prompt()` or a deferred
1344
+ * config source) ultimately resolved to a different key.
1345
+ *
1346
+ * Receives both the discriminator value the parser actually
1347
+ * resolved to (`discriminatorValue`) and the speculative key the
1348
+ * branch tokens were committed to (`speculativeKey`).
1349
+ * @since 1.0.1
1350
+ */
1351
+ readonly branchMismatch?: (discriminatorValue: string, speculativeKey: string) => Message;
1311
1352
  }
1312
1353
  /**
1313
1354
  * Options for customizing the {@link conditional} combinator behavior.
@@ -1317,7 +1358,7 @@ interface ConditionalOptions {
1317
1358
  /**
1318
1359
  * Custom error messages.
1319
1360
  */
1320
- errors?: ConditionalErrorOptions;
1361
+ readonly errors?: ConditionalErrorOptions;
1321
1362
  }
1322
1363
  /**
1323
1364
  * Helper type to infer result type without default branch.