import { Message } from "./message.cjs"; import { HiddenVisibility } from "./usage.cjs"; import { CombineModes, InferValue, Mode, Parser, ParserResult } from "./internal/parser.cjs"; //#region src/constructs.d.ts /** * Helper type to extract Mode from a Parser. * @internal */ type ExtractMode = T extends Parser ? M : never; /** * Helper type to combine modes from an object of parsers. * Returns "async" if any parser is async, otherwise "sync". * @internal */ type CombineObjectModes; }> = CombineModes<{ [K in keyof T]: ExtractMode }[keyof T] extends infer M ? M extends Mode ? readonly [M] : never : never>; /** * Helper type to combine modes from a tuple of parsers. * Returns "async" if any parser is async, otherwise "sync". * @internal */ type CombineTupleModes[]> = CombineModes<{ readonly [K in keyof T]: ExtractMode }>; /** * Options for customizing error messages in the {@link or} combinator. * @since 0.5.0 */ interface OrOptions { /** * Error message customization options. */ errors?: OrErrorOptions; } /** * Context information about what types of inputs are expected, * used for generating contextual error messages. * @since 0.7.0 */ interface NoMatchContext { /** * Whether any of the parsers expect options. */ readonly hasOptions: boolean; /** * Whether any of the parsers expect commands. */ readonly hasCommands: boolean; /** * Whether any of the parsers expect arguments. */ readonly hasArguments: boolean; } /** * Options for customizing error messages in the {@link or} parser. * @since 0.5.0 */ interface OrErrorOptions { /** * Custom error message when no parser matches. * Can be a static message or a function that receives context about what * types of inputs are expected, allowing for more precise error messages. * * @example * ```typescript * // Static message (overrides all cases) * { noMatch: message`Invalid input.` } * * // Dynamic message based on context (for i18n, etc.) * { * noMatch: ({ hasOptions, hasCommands, hasArguments }) => { * if (hasArguments && !hasOptions && !hasCommands) { * return message`인수가 필요합니다.`; // Korean: "Argument required" * } * // ... other cases * } * } * ``` * @since 0.9.0 - Function form added */ noMatch?: Message | ((context: NoMatchContext) => Message); /** * Custom error message for unexpected input. * Can be a static message or a function that receives the unexpected token. */ unexpectedInput?: Message | ((token: string) => Message); /** * Custom function to format suggestion messages. * If provided, this will be used instead of the default "Did you mean?" * formatting. The function receives an array of similar valid options/commands * and should return a formatted message to append to the error. * * @param suggestions Array of similar valid option/command names * @returns Formatted message to append to the error (can be empty array for no suggestions) * @since 0.7.0 */ suggestions?: (suggestions: readonly string[]) => Message; } /** * Error class thrown when duplicate option names are detected during parser * construction. This is a programmer error, not a user error. */ declare class DuplicateOptionError extends Error { readonly optionName: string; readonly sources: readonly (string | symbol)[]; constructor(optionName: string, sources: readonly (string | symbol)[]); } type OrParserArity = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15; type OrArityLimitError = { readonly __optiqueOrArityLimit: "or() requires between 1 and 15 parser arguments. Nest or() to combine more."; }; type OrTailOptions = OrOptions & { readonly $valueType?: never; }; type IsTuple = number extends T["length"] ? false : true; type OrArityGuard = IsTuple extends true ? TParsers["length"] extends OrParserArity ? unknown : OrArityLimitError : unknown; /** * Creates a parser that combines two mutually exclusive parsers into one. * The resulting parser will try each of the provided parsers in order, * and return the result of the first successful parser. * @template MA The mode of the first parser. * @template MB The mode of the second parser. * @template TA The type of the value returned by the first parser. * @template TB The type of the value returned by the second parser. * @template TStateA The type of the state used by the first parser. * @template TStateB The type of the state used by the second parser. * @param a The first {@link Parser} to try. * @param b The second {@link Parser} to try. * @return A {@link Parser} that tries to parse using the provided parsers * in order, returning the result of the first successful parser. * @since 0.3.0 */ declare function or(a: Parser, b: Parser): Parser, TA | TB, undefined | [0, ParserResult] | [1, ParserResult]>; /** * Creates a parser that combines three mutually exclusive parsers into one. * The resulting parser will try each of the provided parsers in order, * and return the result of the first successful parser. * @template MA The mode of the first parser. * @template MB The mode of the second parser. * @template MC The mode of the third parser. * @template TA The type of the value returned by the first parser. * @template TB The type of the value returned by the second parser. * @template TC The type of the value returned by the third parser. * @template TStateA The type of the state used by the first parser. * @template TStateB The type of the state used by the second parser. * @template TStateC The type of the state used by the third parser. * @param a The first {@link Parser} to try. * @param b The second {@link Parser} to try. * @param c The third {@link Parser} to try. * @return A {@link Parser} that tries to parse using the provided parsers * in order, returning the result of the first successful parser. * @since 0.3.0 */ declare function or(a: Parser, b: Parser, c: Parser): Parser, TA | TB | TC, undefined | [0, ParserResult] | [1, ParserResult] | [2, ParserResult]>; /** * Creates a parser that combines four mutually exclusive parsers into one. * The resulting parser will try each of the provided parsers in order, * and return the result of the first successful parser. * @template MA The mode of the first parser. * @template MB The mode of the second parser. * @template MC The mode of the third parser. * @template MD The mode of the fourth parser. * @template TA The type of the value returned by the first parser. * @template TB The type of the value returned by the second parser. * @template TC The type of the value returned by the third parser. * @template TD The type of the value returned by the fourth parser. * @template TStateA The type of the state used by the first parser. * @template TStateB The type of the state used by the second parser. * @template TStateC The type of the state used by the third parser. * @template TStateD The type of the state used by the fourth parser. * @param a The first {@link Parser} to try. * @param b The second {@link Parser} to try. * @param c The third {@link Parser} to try. * @param d The fourth {@link Parser} to try. * @return A {@link Parser} that tries to parse using the provided parsers * in order, returning the result of the first successful parser. * @since 0.3.0 */ declare function or(a: Parser, b: Parser, c: Parser, d: Parser): Parser, TA | TB | TC | TD, undefined | [0, ParserResult] | [1, ParserResult] | [2, ParserResult] | [3, ParserResult]>; /** * Creates a parser that combines five mutually exclusive parsers into one. * The resulting parser will try each of the provided parsers in order, * and return the result of the first successful parser. * @template MA The mode of the first parser. * @template MB The mode of the second parser. * @template MC The mode of the third parser. * @template MD The mode of the fourth parser. * @template ME The mode of the fifth parser. * @template TA The type of the value returned by the first parser. * @template TB The type of the value returned by the second parser. * @template TC The type of the value returned by the third parser. * @template TD The type of the value returned by the fourth parser. * @template TE The type of the value returned by the fifth parser. * @template TStateA The type of the state used by the first parser. * @template TStateB The type of the state used by the second parser. * @template TStateC The type of the state used by the third parser. * @template TStateD The type of the state used by the fourth parser. * @template TStateE The type of the state used by the fifth parser. * @param a The first {@link Parser} to try. * @param b The second {@link Parser} to try. * @param c The third {@link Parser} to try. * @param d The fourth {@link Parser} to try. * @param e The fifth {@link Parser} to try. * @return A {@link Parser} that tries to parse using the provided parsers * in order, returning the result of the first successful parser. */ declare function or(a: Parser, b: Parser, c: Parser, d: Parser, e: Parser): Parser, TA | TB | TC | TD | TE, undefined | [0, ParserResult] | [1, ParserResult] | [2, ParserResult] | [3, ParserResult] | [4, ParserResult]>; /** * Creates a parser that combines six mutually exclusive parsers into one. * The resulting parser will try each of the provided parsers in order, * and return the result of the first successful parser. * @template MA The mode of the first parser. * @template MB The mode of the second parser. * @template MC The mode of the third parser. * @template MD The mode of the fourth parser. * @template ME The mode of the fifth parser. * @template MF The mode of the sixth parser. * @template TA The type of the value returned by the first parser. * @template TB The type of the value returned by the second parser. * @template TC The type of the value returned by the third parser. * @template TD The type of the value returned by the fourth parser. * @template TE The type of the value returned by the fifth parser. * @template TF The type of the value returned by the sixth parser. * @template TStateA The type of the state used by the first parser. * @template TStateB The type of the state used by the second parser. * @template TStateC The type of the state used by the third parser. * @template TStateD The type of the state used by the fourth parser. * @template TStateE The type of the state used by the fifth parser. * @template TStateF The type of the state used by the sixth parser. * @param a The first {@link Parser} to try. * @param b The second {@link Parser} to try. * @param c The third {@link Parser} to try. * @param d The fourth {@link Parser} to try. * @param e The fifth {@link Parser} to try. * @param f The sixth {@link Parser} to try. * @return A {@link Parser} that tries to parse using the provided parsers * in order, returning the result of the first successful parser. * @since 0.3.0 */ declare function or(a: Parser, b: Parser, c: Parser, d: Parser, e: Parser, f: Parser): Parser, TA | TB | TC | TD | TE | TF, undefined | [0, ParserResult] | [1, ParserResult] | [2, ParserResult] | [3, ParserResult] | [4, ParserResult] | [5, ParserResult]>; /** * Creates a parser that combines seven mutually exclusive parsers into one. * The resulting parser will try each of the provided parsers in order, * and return the result of the first successful parser. * @template MA The mode of the first parser. * @template MB The mode of the second parser. * @template MC The mode of the third parser. * @template MD The mode of the fourth parser. * @template ME The mode of the fifth parser. * @template MF The mode of the sixth parser. * @template MG The mode of the seventh parser. * @template TA The type of the value returned by the first parser. * @template TB The type of the value returned by the second parser. * @template TC The type of the value returned by the third parser. * @template TD The type of the value returned by the fourth parser. * @template TE The type of the value returned by the fifth parser. * @template TF The type of the value returned by the sixth parser. * @template TG The type of the value returned by the seventh parser. * @template TStateA The type of the state used by the first parser. * @template TStateB The type of the state used by the second parser. * @template TStateC The type of the state used by the third parser. * @template TStateD The type of the state used by the fourth parser. * @template TStateE The type of the state used by the fifth parser. * @template TStateF The type of the state used by the sixth parser. * @template TStateG The type of the state used by the seventh parser. * @param a The first {@link Parser} to try. * @param b The second {@link Parser} to try. * @param c The third {@link Parser} to try. * @param d The fourth {@link Parser} to try. * @param e The fifth {@link Parser} to try. * @param f The sixth {@link Parser} to try. * @param g The seventh {@link Parser} to try. * @return A {@link Parser} that tries to parse using the provided parsers * in order, returning the result of the first successful parser. * @since 0.3.0 */ declare function or(a: Parser, b: Parser, c: Parser, d: Parser, e: Parser, f: Parser, g: Parser): Parser, TA | TB | TC | TD | TE | TF | TG, undefined | [0, ParserResult] | [1, ParserResult] | [2, ParserResult] | [3, ParserResult] | [4, ParserResult] | [5, ParserResult] | [6, ParserResult]>; /** * Creates a parser that combines eight mutually exclusive parsers into one. * The resulting parser will try each of the provided parsers in order, * and return the result of the first successful parser. * @template MA The mode of the first parser. * @template MB The mode of the second parser. * @template MC The mode of the third parser. * @template MD The mode of the fourth parser. * @template ME The mode of the fifth parser. * @template MF The mode of the sixth parser. * @template MG The mode of the seventh parser. * @template MH The mode of the eighth parser. * @template TA The type of the value returned by the first parser. * @template TB The type of the value returned by the second parser. * @template TC The type of the value returned by the third parser. * @template TD The type of the value returned by the fourth parser. * @template TE The type of the value returned by the fifth parser. * @template TF The type of the value returned by the sixth parser. * @template TG The type of the value returned by the seventh parser. * @template TH The type of the value returned by the eighth parser. * @template TStateA The type of the state used by the first parser. * @template TStateB The type of the state used by the second parser. * @template TStateC The type of the state used by the third parser. * @template TStateD The type of the state used by the fourth parser. * @template TStateE The type of the state used by the fifth parser. * @template TStateF The type of the state used by the sixth parser. * @template TStateG The type of the state used by the seventh parser. * @template TStateH The type of the state used by the eighth parser. * @param a The first {@link Parser} to try. * @param b The second {@link Parser} to try. * @param c The third {@link Parser} to try. * @param d The fourth {@link Parser} to try. * @param e The fifth {@link Parser} to try. * @param f The sixth {@link Parser} to try. * @param g The seventh {@link Parser} to try. * @param h The eighth {@link Parser} to try. * @return A {@link Parser} that tries to parse using the provided parsers * in order, returning the result of the first successful parser. * @since 0.3.0 */ declare function or(a: Parser, b: Parser, c: Parser, d: Parser, e: Parser, f: Parser, g: Parser, h: Parser): Parser, TA | TB | TC | TD | TE | TF | TG | TH, undefined | [0, ParserResult] | [1, ParserResult] | [2, ParserResult] | [3, ParserResult] | [4, ParserResult] | [5, ParserResult] | [6, ParserResult] | [7, ParserResult]>; /** * Creates a parser that combines nine mutually exclusive parsers into one. * The resulting parser will try each of the provided parsers in order, * and return the result of the first successful parser. * @template MA The mode of the first parser. * @template MB The mode of the second parser. * @template MC The mode of the third parser. * @template MD The mode of the fourth parser. * @template ME The mode of the fifth parser. * @template MF The mode of the sixth parser. * @template MG The mode of the seventh parser. * @template MH The mode of the eighth parser. * @template MI The mode of the ninth parser. * @template TA The type of the value returned by the first parser. * @template TB The type of the value returned by the second parser. * @template TC The type of the value returned by the third parser. * @template TD The type of the value returned by the fourth parser. * @template TE The type of the value returned by the fifth parser. * @template TF The type of the value returned by the sixth parser. * @template TG The type of the value returned by the seventh parser. * @template TH The type of the value returned by the eighth parser. * @template TI The type of the value returned by the ninth parser. * @template TStateA The type of the state used by the first parser. * @template TStateB The type of the state used by the second parser. * @template TStateC The type of the state used by the third parser. * @template TStateD The type of the state used by the fourth parser. * @template TStateE The type of the state used by the fifth parser. * @template TStateF The type of the state used by the sixth parser. * @template TStateG The type of the state used by the seventh parser. * @template TStateH The type of the state used by the eighth parser. * @template TStateI The type of the state used by the ninth parser. * @param a The first {@link Parser} to try. * @param b The second {@link Parser} to try. * @param c The third {@link Parser} to try. * @param d The fourth {@link Parser} to try. * @param e The fifth {@link Parser} to try. * @param f The sixth {@link Parser} to try. * @param g The seventh {@link Parser} to try. * @param h The eighth {@link Parser} to try. * @param i The ninth {@link Parser} to try. * @return A {@link Parser} that tries to parse using the provided parsers * in order, returning the result of the first successful parser. * @since 0.3.0 */ declare function or(a: Parser, b: Parser, c: Parser, d: Parser, e: Parser, f: Parser, g: Parser, h: Parser, i: Parser): Parser, TA | TB | TC | TD | TE | TF | TG | TH | TI, undefined | [0, ParserResult] | [1, ParserResult] | [2, ParserResult] | [3, ParserResult] | [4, ParserResult] | [5, ParserResult] | [6, ParserResult] | [7, ParserResult] | [8, ParserResult]>; /** * Creates a parser that combines ten mutually exclusive parsers into one. * The resulting parser will try each of the provided parsers in order, * and return the result of the first successful parser. * @template MA The mode of the first parser. * @template MB The mode of the second parser. * @template MC The mode of the third parser. * @template MD The mode of the fourth parser. * @template ME The mode of the fifth parser. * @template MF The mode of the sixth parser. * @template MG The mode of the seventh parser. * @template MH The mode of the eighth parser. * @template MI The mode of the ninth parser. * @template MJ The mode of the tenth parser. * @template TA The type of the value returned by the first parser. * @template TB The type of the value returned by the second parser. * @template TC The type of the value returned by the third parser. * @template TD The type of the value returned by the fourth parser. * @template TE The type of the value returned by the fifth parser. * @template TF The type of the value returned by the sixth parser. * @template TG The type of the value returned by the seventh parser. * @template TH The type of the value returned by the eighth parser. * @template TI The type of the value returned by the ninth parser. * @template TJ The type of the value returned by the tenth parser. * @template TStateA The type of the state used by the first parser. * @template TStateB The type of the state used by the second parser. * @template TStateC The type of the state used by the third parser. * @template TStateD The type of the state used by the fourth parser. * @template TStateE The type of the state used by the fifth parser. * @template TStateF The type of the state used by the sixth parser. * @template TStateG The type of the state used by the seventh parser. * @template TStateH The type of the state used by the eighth parser. * @template TStateI The type of the state used by the ninth parser. * @template TStateJ The type of the state used by the tenth parser. * @param a The first {@link Parser} to try. * @param b The second {@link Parser} to try. * @param c The third {@link Parser} to try. * @param d The fourth {@link Parser} to try. * @param e The fifth {@link Parser} to try. * @param f The sixth {@link Parser} to try. * @param g The seventh {@link Parser} to try. * @param h The eighth {@link Parser} to try. * @param i The ninth {@link Parser} to try. * @param j The tenth {@link Parser} to try. * @return A {@link Parser} that tries to parse using the provided parsers * in order, returning the result of the first successful parser. * @since 0.3.0 */ declare function or(a: Parser, b: Parser, c: Parser, d: Parser, e: Parser, f: Parser, g: Parser, h: Parser, i: Parser, j: Parser): Parser, TA | TB | TC | TD | TE | TF | TG | TH | TI | TJ, undefined | [0, ParserResult] | [1, ParserResult] | [2, ParserResult] | [3, ParserResult] | [4, ParserResult] | [5, ParserResult] | [6, ParserResult] | [7, ParserResult] | [8, ParserResult] | [9, ParserResult]>; /** * Creates a parser that combines eleven mutually exclusive parsers into one. * The resulting parser will try each of the provided parsers in order, * and return the result of the first successful parser. * @template MA The mode of the first parser. * @template MB The mode of the second parser. * @template MC The mode of the third parser. * @template MD The mode of the fourth parser. * @template ME The mode of the fifth parser. * @template MF The mode of the sixth parser. * @template MG The mode of the seventh parser. * @template MH The mode of the eighth parser. * @template MI The mode of the ninth parser. * @template MJ The mode of the tenth parser. * @template MK The mode of the eleventh parser. * @template TA The type of the value returned by the first parser. * @template TB The type of the value returned by the second parser. * @template TC The type of the value returned by the third parser. * @template TD The type of the value returned by the fourth parser. * @template TE The type of the value returned by the fifth parser. * @template TF The type of the value returned by the sixth parser. * @template TG The type of the value returned by the seventh parser. * @template TH The type of the value returned by the eighth parser. * @template TI The type of the value returned by the ninth parser. * @template TJ The type of the value returned by the tenth parser. * @template TK The type of the value returned by the eleventh parser. * @template TStateA The type of the state used by the first parser. * @template TStateB The type of the state used by the second parser. * @template TStateC The type of the state used by the third parser. * @template TStateD The type of the state used by the fourth parser. * @template TStateE The type of the state used by the fifth parser. * @template TStateF The type of the state used by the sixth parser. * @template TStateG The type of the state used by the seventh parser. * @template TStateH The type of the state used by the eighth parser. * @template TStateI The type of the state used by the ninth parser. * @template TStateJ The type of the state used by the tenth parser. * @template TStateK The type of the state used by the eleventh parser. * @param a The first {@link Parser} to try. * @param b The second {@link Parser} to try. * @param c The third {@link Parser} to try. * @param d The fourth {@link Parser} to try. * @param e The fifth {@link Parser} to try. * @param f The sixth {@link Parser} to try. * @param g The seventh {@link Parser} to try. * @param h The eighth {@link Parser} to try. * @param i The ninth {@link Parser} to try. * @param j The tenth {@link Parser} to try. * @param k The eleventh {@link Parser} to try. * @return A {@link Parser} that tries to parse using the provided parsers * in order, returning the result of the first successful parser. * @since 1.0.0 */ declare function or(a: Parser, b: Parser, c: Parser, d: Parser, e: Parser, f: Parser, g: Parser, h: Parser, i: Parser, j: Parser, k: Parser): Parser, TA | TB | TC | TD | TE | TF | TG | TH | TI | TJ | TK, undefined | [0, ParserResult] | [1, ParserResult] | [2, ParserResult] | [3, ParserResult] | [4, ParserResult] | [5, ParserResult] | [6, ParserResult] | [7, ParserResult] | [8, ParserResult] | [9, ParserResult] | [10, ParserResult]>; /** * Creates a parser that combines twelve mutually exclusive parsers into one. * The resulting parser will try each of the provided parsers in order, * and return the result of the first successful parser. * @template MA The mode of the first parser. * @template MB The mode of the second parser. * @template MC The mode of the third parser. * @template MD The mode of the fourth parser. * @template ME The mode of the fifth parser. * @template MF The mode of the sixth parser. * @template MG The mode of the seventh parser. * @template MH The mode of the eighth parser. * @template MI The mode of the ninth parser. * @template MJ The mode of the tenth parser. * @template MK The mode of the eleventh parser. * @template ML The mode of the twelfth parser. * @template TA The type of the value returned by the first parser. * @template TB The type of the value returned by the second parser. * @template TC The type of the value returned by the third parser. * @template TD The type of the value returned by the fourth parser. * @template TE The type of the value returned by the fifth parser. * @template TF The type of the value returned by the sixth parser. * @template TG The type of the value returned by the seventh parser. * @template TH The type of the value returned by the eighth parser. * @template TI The type of the value returned by the ninth parser. * @template TJ The type of the value returned by the tenth parser. * @template TK The type of the value returned by the eleventh parser. * @template TL The type of the value returned by the twelfth parser. * @template TStateA The type of the state used by the first parser. * @template TStateB The type of the state used by the second parser. * @template TStateC The type of the state used by the third parser. * @template TStateD The type of the state used by the fourth parser. * @template TStateE The type of the state used by the fifth parser. * @template TStateF The type of the state used by the sixth parser. * @template TStateG The type of the state used by the seventh parser. * @template TStateH The type of the state used by the eighth parser. * @template TStateI The type of the state used by the ninth parser. * @template TStateJ The type of the state used by the tenth parser. * @template TStateK The type of the state used by the eleventh parser. * @template TStateL The type of the state used by the twelfth parser. * @param a The first {@link Parser} to try. * @param b The second {@link Parser} to try. * @param c The third {@link Parser} to try. * @param d The fourth {@link Parser} to try. * @param e The fifth {@link Parser} to try. * @param f The sixth {@link Parser} to try. * @param g The seventh {@link Parser} to try. * @param h The eighth {@link Parser} to try. * @param i The ninth {@link Parser} to try. * @param j The tenth {@link Parser} to try. * @param k The eleventh {@link Parser} to try. * @param l The twelfth {@link Parser} to try. * @return A {@link Parser} that tries to parse using the provided parsers * in order, returning the result of the first successful parser. * @since 1.0.0 */ declare function or(a: Parser, b: Parser, c: Parser, d: Parser, e: Parser, f: Parser, g: Parser, h: Parser, i: Parser, j: Parser, k: Parser, l: Parser): Parser, TA | TB | TC | TD | TE | TF | TG | TH | TI | TJ | TK | TL, undefined | [0, ParserResult] | [1, ParserResult] | [2, ParserResult] | [3, ParserResult] | [4, ParserResult] | [5, ParserResult] | [6, ParserResult] | [7, ParserResult] | [8, ParserResult] | [9, ParserResult] | [10, ParserResult] | [11, ParserResult]>; /** * Creates a parser that combines thirteen mutually exclusive parsers into one. * The resulting parser will try each of the provided parsers in order, * and return the result of the first successful parser. * @template MA The mode of the first parser. * @template MB The mode of the second parser. * @template MC The mode of the third parser. * @template MD The mode of the fourth parser. * @template ME The mode of the fifth parser. * @template MF The mode of the sixth parser. * @template MG The mode of the seventh parser. * @template MH The mode of the eighth parser. * @template MI The mode of the ninth parser. * @template MJ The mode of the tenth parser. * @template MK The mode of the eleventh parser. * @template ML The mode of the twelfth parser. * @template MM The mode of the thirteenth parser. * @template TA The type of the value returned by the first parser. * @template TB The type of the value returned by the second parser. * @template TC The type of the value returned by the third parser. * @template TD The type of the value returned by the fourth parser. * @template TE The type of the value returned by the fifth parser. * @template TF The type of the value returned by the sixth parser. * @template TG The type of the value returned by the seventh parser. * @template TH The type of the value returned by the eighth parser. * @template TI The type of the value returned by the ninth parser. * @template TJ The type of the value returned by the tenth parser. * @template TK The type of the value returned by the eleventh parser. * @template TL The type of the value returned by the twelfth parser. * @template TM The type of the value returned by the thirteenth parser. * @template TStateA The type of the state used by the first parser. * @template TStateB The type of the state used by the second parser. * @template TStateC The type of the state used by the third parser. * @template TStateD The type of the state used by the fourth parser. * @template TStateE The type of the state used by the fifth parser. * @template TStateF The type of the state used by the sixth parser. * @template TStateG The type of the state used by the seventh parser. * @template TStateH The type of the state used by the eighth parser. * @template TStateI The type of the state used by the ninth parser. * @template TStateJ The type of the state used by the tenth parser. * @template TStateK The type of the state used by the eleventh parser. * @template TStateL The type of the state used by the twelfth parser. * @template TStateM The type of the state used by the thirteenth parser. * @param a The first {@link Parser} to try. * @param b The second {@link Parser} to try. * @param c The third {@link Parser} to try. * @param d The fourth {@link Parser} to try. * @param e The fifth {@link Parser} to try. * @param f The sixth {@link Parser} to try. * @param g The seventh {@link Parser} to try. * @param h The eighth {@link Parser} to try. * @param i The ninth {@link Parser} to try. * @param j The tenth {@link Parser} to try. * @param k The eleventh {@link Parser} to try. * @param l The twelfth {@link Parser} to try. * @param m The thirteenth {@link Parser} to try. * @return A {@link Parser} that tries to parse using the provided parsers * in order, returning the result of the first successful parser. * @since 1.0.0 */ declare function or(a: Parser, b: Parser, c: Parser, d: Parser, e: Parser, f: Parser, g: Parser, h: Parser, i: Parser, j: Parser, k: Parser, l: Parser, m: Parser): Parser, TA | TB | TC | TD | TE | TF | TG | TH | TI | TJ | TK | TL | TM, undefined | [0, ParserResult] | [1, ParserResult] | [2, ParserResult] | [3, ParserResult] | [4, ParserResult] | [5, ParserResult] | [6, ParserResult] | [7, ParserResult] | [8, ParserResult] | [9, ParserResult] | [10, ParserResult] | [11, ParserResult] | [12, ParserResult]>; /** * Creates a parser that combines fourteen mutually exclusive parsers into one. * The resulting parser will try each of the provided parsers in order, * and return the result of the first successful parser. * @template MA The mode of the first parser. * @template MB The mode of the second parser. * @template MC The mode of the third parser. * @template MD The mode of the fourth parser. * @template ME The mode of the fifth parser. * @template MF The mode of the sixth parser. * @template MG The mode of the seventh parser. * @template MH The mode of the eighth parser. * @template MI The mode of the ninth parser. * @template MJ The mode of the tenth parser. * @template MK The mode of the eleventh parser. * @template ML The mode of the twelfth parser. * @template MM The mode of the thirteenth parser. * @template MN The mode of the fourteenth parser. * @template TA The type of the value returned by the first parser. * @template TB The type of the value returned by the second parser. * @template TC The type of the value returned by the third parser. * @template TD The type of the value returned by the fourth parser. * @template TE The type of the value returned by the fifth parser. * @template TF The type of the value returned by the sixth parser. * @template TG The type of the value returned by the seventh parser. * @template TH The type of the value returned by the eighth parser. * @template TI The type of the value returned by the ninth parser. * @template TJ The type of the value returned by the tenth parser. * @template TK The type of the value returned by the eleventh parser. * @template TL The type of the value returned by the twelfth parser. * @template TM The type of the value returned by the thirteenth parser. * @template TN The type of the value returned by the fourteenth parser. * @template TStateA The type of the state used by the first parser. * @template TStateB The type of the state used by the second parser. * @template TStateC The type of the state used by the third parser. * @template TStateD The type of the state used by the fourth parser. * @template TStateE The type of the state used by the fifth parser. * @template TStateF The type of the state used by the sixth parser. * @template TStateG The type of the state used by the seventh parser. * @template TStateH The type of the state used by the eighth parser. * @template TStateI The type of the state used by the ninth parser. * @template TStateJ The type of the state used by the tenth parser. * @template TStateK The type of the state used by the eleventh parser. * @template TStateL The type of the state used by the twelfth parser. * @template TStateM The type of the state used by the thirteenth parser. * @template TStateN The type of the state used by the fourteenth parser. * @param a The first {@link Parser} to try. * @param b The second {@link Parser} to try. * @param c The third {@link Parser} to try. * @param d The fourth {@link Parser} to try. * @param e The fifth {@link Parser} to try. * @param f The sixth {@link Parser} to try. * @param g The seventh {@link Parser} to try. * @param h The eighth {@link Parser} to try. * @param i The ninth {@link Parser} to try. * @param j The tenth {@link Parser} to try. * @param k The eleventh {@link Parser} to try. * @param l The twelfth {@link Parser} to try. * @param m The thirteenth {@link Parser} to try. * @param n The fourteenth {@link Parser} to try. * @return A {@link Parser} that tries to parse using the provided parsers * in order, returning the result of the first successful parser. * @since 1.0.0 */ declare function or(a: Parser, b: Parser, c: Parser, d: Parser, e: Parser, f: Parser, g: Parser, h: Parser, i: Parser, j: Parser, k: Parser, l: Parser, m: Parser, n: Parser): Parser, TA | TB | TC | TD | TE | TF | TG | TH | TI | TJ | TK | TL | TM | TN, undefined | [0, ParserResult] | [1, ParserResult] | [2, ParserResult] | [3, ParserResult] | [4, ParserResult] | [5, ParserResult] | [6, ParserResult] | [7, ParserResult] | [8, ParserResult] | [9, ParserResult] | [10, ParserResult] | [11, ParserResult] | [12, ParserResult] | [13, ParserResult]>; /** * Creates a parser that combines fifteen mutually exclusive parsers into one. * The resulting parser will try each of the provided parsers in order, * and return the result of the first successful parser. * @template MA The mode of the first parser. * @template MB The mode of the second parser. * @template MC The mode of the third parser. * @template MD The mode of the fourth parser. * @template ME The mode of the fifth parser. * @template MF The mode of the sixth parser. * @template MG The mode of the seventh parser. * @template MH The mode of the eighth parser. * @template MI The mode of the ninth parser. * @template MJ The mode of the tenth parser. * @template MK The mode of the eleventh parser. * @template ML The mode of the twelfth parser. * @template MM The mode of the thirteenth parser. * @template MN The mode of the fourteenth parser. * @template MO The mode of the fifteenth parser. * @template TA The type of the value returned by the first parser. * @template TB The type of the value returned by the second parser. * @template TC The type of the value returned by the third parser. * @template TD The type of the value returned by the fourth parser. * @template TE The type of the value returned by the fifth parser. * @template TF The type of the value returned by the sixth parser. * @template TG The type of the value returned by the seventh parser. * @template TH The type of the value returned by the eighth parser. * @template TI The type of the value returned by the ninth parser. * @template TJ The type of the value returned by the tenth parser. * @template TK The type of the value returned by the eleventh parser. * @template TL The type of the value returned by the twelfth parser. * @template TM The type of the value returned by the thirteenth parser. * @template TN The type of the value returned by the fourteenth parser. * @template TO The type of the value returned by the fifteenth parser. * @template TStateA The type of the state used by the first parser. * @template TStateB The type of the state used by the second parser. * @template TStateC The type of the state used by the third parser. * @template TStateD The type of the state used by the fourth parser. * @template TStateE The type of the state used by the fifth parser. * @template TStateF The type of the state used by the sixth parser. * @template TStateG The type of the state used by the seventh parser. * @template TStateH The type of the state used by the eighth parser. * @template TStateI The type of the state used by the ninth parser. * @template TStateJ The type of the state used by the tenth parser. * @template TStateK The type of the state used by the eleventh parser. * @template TStateL The type of the state used by the twelfth parser. * @template TStateM The type of the state used by the thirteenth parser. * @template TStateN The type of the state used by the fourteenth parser. * @template TStateO The type of the state used by the fifteenth parser. * @param a The first {@link Parser} to try. * @param b The second {@link Parser} to try. * @param c The third {@link Parser} to try. * @param d The fourth {@link Parser} to try. * @param e The fifth {@link Parser} to try. * @param f The sixth {@link Parser} to try. * @param g The seventh {@link Parser} to try. * @param h The eighth {@link Parser} to try. * @param i The ninth {@link Parser} to try. * @param j The tenth {@link Parser} to try. * @param k The eleventh {@link Parser} to try. * @param l The twelfth {@link Parser} to try. * @param m The thirteenth {@link Parser} to try. * @param n The fourteenth {@link Parser} to try. * @param o The fifteenth {@link Parser} to try. * @return A {@link Parser} that tries to parse using the provided parsers * in order, returning the result of the first successful parser. * @since 1.0.0 */ declare function or(a: Parser, b: Parser, c: Parser, d: Parser, e: Parser, f: Parser, g: Parser, h: Parser, i: Parser, j: Parser, k: Parser, l: Parser, m: Parser, n: Parser, o: Parser): Parser, TA | TB | TC | TD | TE | TF | TG | TH | TI | TJ | TK | TL | TM | TN | TO, undefined | [0, ParserResult] | [1, ParserResult] | [2, ParserResult] | [3, ParserResult] | [4, ParserResult] | [5, ParserResult] | [6, ParserResult] | [7, ParserResult] | [8, ParserResult] | [9, ParserResult] | [10, ParserResult] | [11, ParserResult] | [12, ParserResult] | [13, ParserResult] | [14, ParserResult]>; /** * Creates a parser that combines two mutually exclusive parsers into one, * with custom error message options. * @template MA The mode of the first parser. * @template MB The mode of the second parser. * @template TA The type of the value returned by the first parser. * @template TB The type of the value returned by the second parser. * @template TStateA The type of the state used by the first parser. * @template TStateB The type of the state used by the second parser. * @param a The first {@link Parser} to try. * @param b The second {@link Parser} to try. * @param options Custom error message options. * @return A {@link Parser} that tries to parse using the provided parsers * in order, returning the result of the first successful parser. * @throws {TypeError} If no parser arguments are provided. * @since 0.5.0 */ declare function or(a: Parser, b: Parser, options: OrOptions): Parser, TA | TB, undefined | [0, ParserResult] | [1, ParserResult]>; /** * Creates a parser that combines three mutually exclusive parsers into one, * with custom error message options. * @template MA The mode of the first parser. * @template MB The mode of the second parser. * @template MC The mode of the third parser. * @template TA The type of the value returned by the first parser. * @template TB The type of the value returned by the second parser. * @template TC The type of the value returned by the third parser. * @template TStateA The type of the state used by the first parser. * @template TStateB The type of the state used by the second parser. * @template TStateC The type of the state used by the third parser. * @param a The first {@link Parser} to try. * @param b The second {@link Parser} to try. * @param c The third {@link Parser} to try. * @param options Custom error message options. * @return A {@link Parser} that tries to parse using the provided parsers * in order, returning the result of the first successful parser. * @throws {TypeError} If no parser arguments are provided. * @since 0.5.0 */ declare function or(a: Parser, b: Parser, c: Parser, options: OrOptions): Parser, TA | TB | TC, undefined | [0, ParserResult] | [1, ParserResult] | [2, ParserResult]>; /** * Creates a parser that tries each parser in sequence until one succeeds, * with custom error message options. * @param rest Parsers to try, followed by {@link OrOptions} for error * customization. * @returns A parser that succeeds if any of the input parsers succeed. * @throws {TypeError} If no parser arguments are provided. * @since 0.5.0 */ declare function or[]>(...rest: [...parsers: TParsers, options: OrTailOptions] & OrArityGuard): Parser }>, InferValue, undefined | [number, ParserResult]>; /** * Creates a parser that tries each parser in sequence until one succeeds. * @param parsers Parsers to try in order. * @returns A parser that succeeds if any of the input parsers succeed. * @throws {TypeError} If no parser arguments are provided. * @since 0.5.0 */ declare function or[]>(...parsers: TParsers & OrArityGuard): Parser }>, InferValue, undefined | [number, ParserResult]>; /** * Options for customizing error messages in the {@link longestMatch} * combinator. * @since 0.5.0 */ interface LongestMatchOptions { /** * Error message customization options. */ errors?: LongestMatchErrorOptions; } /** * Options for customizing error messages in the {@link longestMatch} parser. * @since 0.5.0 */ interface LongestMatchErrorOptions { /** * Custom error message when no parser matches. * Can be a static message or a function that receives context about what * types of inputs are expected, allowing for more precise error messages. * * @example * ```typescript * // Static message (overrides all cases) * { noMatch: message`Invalid input.` } * * // Dynamic message based on context (for i18n, etc.) * { * noMatch: ({ hasOptions, hasCommands, hasArguments }) => { * if (hasArguments && !hasOptions && !hasCommands) { * return message`引数が必要です。`; // Japanese: "Argument required" * } * // ... other cases * } * } * ``` * @since 0.9.0 - Function form added */ noMatch?: Message | ((context: NoMatchContext) => Message); /** * Custom error message for unexpected input. * Can be a static message or a function that receives the unexpected token. */ unexpectedInput?: Message | ((token: string) => Message); /** * Custom function to format suggestion messages. * If provided, this will be used instead of the default "Did you mean?" * formatting. The function receives an array of similar valid options/commands * and should return a formatted message to append to the error. * * @param suggestions Array of similar valid option/command names * @returns Formatted message to append to the error (can be empty array for no suggestions) * @since 0.7.0 */ suggestions?: (suggestions: readonly string[]) => Message; } type LongestMatchParserArity = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15; type LongestMatchArityLimitError = { readonly __optiqueLongestMatchArityLimit: "longestMatch() requires between 1 and 15 parser arguments. Nest longestMatch() to combine more."; }; type LongestMatchTailOptions = LongestMatchOptions & { readonly $valueType?: never; }; type TupleKeys = Exclude; type LongestMatchTupleState[]> = { [K in TupleKeys]: TParsers[K] extends Parser ? K extends `${infer TIndex extends number}` ? [TIndex, ParserResult] : never : never }[TupleKeys]; type LongestMatchState[]> = IsTuple extends true ? undefined | LongestMatchTupleState : undefined | [number, ParserResult]; type LongestMatchArityGuard = IsTuple extends true ? TParsers["length"] extends LongestMatchParserArity ? unknown : LongestMatchArityLimitError : unknown; /** * Creates a parser that selects the successful branch that consumed * the most input tokens. * * The resulting parser tries every given parser and returns the * successful result that consumed more input than the others. * * @param parsers Parsers to evaluate and compare by consumed input. * @returns A parser that yields the best successful branch result. * Type inference is precise for tuple calls up to 15 parser arguments. * @since 0.3.0 */ declare function longestMatch[]>(...parsers: TParsers & LongestMatchArityGuard): Parser<"sync", InferValue, LongestMatchState>; /** * Creates a parser that selects the successful branch that consumed * the most input tokens, with custom error options. * * The resulting parser tries every given parser and returns the * successful result that consumed more input than the others. * * @param rest Parsers to compare, followed by error customization options. * @returns A parser that yields the best successful branch result. * Type inference is precise for tuple calls up to 15 parser arguments. * @throws {TypeError} If no parser arguments are provided. * @since 0.5.0 */ declare function longestMatch[]>(...rest: [...parsers: TParsers, options: LongestMatchTailOptions] & LongestMatchArityGuard): Parser<"sync", InferValue, LongestMatchState>; /** * Creates a parser that selects the successful branch that consumed * the most input tokens, with custom error options. * * @param rest Parsers to compare, followed by error customization options. * @returns A parser that yields the best successful branch result. * Type inference is precise for tuple calls up to 15 parser arguments. * @throws {TypeError} If no parser arguments are provided. * @since 0.5.0 */ declare function longestMatch[]>(...rest: [...parsers: TParsers, options: LongestMatchTailOptions] & LongestMatchArityGuard): Parser }>, InferValue, LongestMatchState>; /** * Creates a parser that selects the successful branch that consumed * the most input tokens. * * The resulting parser tries every given parser and returns the * successful result that consumed more input than the others. * * @param parsers Parsers to evaluate and compare by consumed input. * @returns A parser that yields the best successful branch result. * Type inference is precise for tuple calls up to 15 parser arguments. * @since 0.3.0 */ declare function longestMatch[]>(...parsers: TParsers & LongestMatchArityGuard): Parser }>, InferValue, LongestMatchState>; /** * Creates a parser that selects the successful branch that consumed * the most input tokens from a homogeneous parser list. * * This overload is intended for spread arrays whose element types are * homogeneous enough that callers only need the shared value type. * * @param parsers Parsers to evaluate and compare by consumed input. * @returns A parser that preserves the shared parser mode and value type. * @since 1.0.0 */ declare function longestMatch[]>(...parsers: TParsers & LongestMatchArityGuard): Parser; /** * Creates a parser that selects the successful branch that consumed * the most input tokens from a homogeneous parser list, with custom * error options. * * @param rest Parsers to compare, followed by error customization options. * @returns A parser that preserves the shared parser mode and value type. * @since 1.0.0 */ declare function longestMatch[]>(...rest: [...parsers: TParsers, options: LongestMatchTailOptions] & LongestMatchArityGuard): Parser; /** * Options for the {@link object} parser. * @since 0.5.0 */ interface ObjectOptions { /** * Error messages customization. */ readonly errors?: ObjectErrorOptions; /** * When `true`, allows duplicate option names across different fields. * By default (`false`), duplicate option names cause a construction-time * error. * * @default `false` * @since 0.7.0 */ readonly allowDuplicates?: boolean; /** * Controls visibility of all terms emitted by this object parser. * @since 1.0.0 */ readonly hidden?: HiddenVisibility; } /** * Options for customizing error messages in the {@link object} parser. * @since 0.5.0 */ interface ObjectErrorOptions { /** * Error message when an unexpected option or argument is encountered. */ readonly unexpectedInput?: Message | ((token: string) => Message); /** * Error message when end of input is reached unexpectedly. * Can be a static message or a function that receives context about what * types of inputs are expected, allowing for more precise error messages. * * @example * ```typescript * // Static message (overrides all cases) * { endOfInput: message`Invalid input.` } * * // Dynamic message based on context (for i18n, etc.) * { * endOfInput: ({ hasOptions, hasCommands, hasArguments }) => { * if (hasArguments && !hasOptions && !hasCommands) { * return message`Argument manquant.`; // French: "Missing argument" * } * // ... other cases * } * } * ``` * @since 0.9.0 - Function form added */ readonly endOfInput?: Message | ((context: NoMatchContext) => Message); /** * Custom function to format suggestion messages. * If provided, this will be used instead of the default "Did you mean?" * formatting. The function receives an array of similar valid options/commands * and should return a formatted message to append to the error. * * @param suggestions Array of similar valid option/command names * @returns Formatted message to append to the error (can be empty array for no suggestions) * @since 0.7.0 */ readonly suggestions?: (suggestions: readonly string[]) => Message; } /** * Creates a parser that combines multiple parsers into a single object parser. * Each parser in the object is applied to parse different parts of the input, * and the results are combined into an object with the same structure. * @template T A record type where each value is a {@link Parser}. * @param parsers An object containing named parsers that will be combined * into a single object parser. * @returns A {@link Parser} that produces an object with the same keys as * the input, where each value is the result of the corresponding * parser. */ declare function object; }>(parsers: T): Parser, { 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 }>; /** * Creates a parser that combines multiple parsers into a single object parser. * Each parser in the object is applied to parse different parts of the input, * and the results are combined into an object with the same structure. * @template T A record type where each value is a {@link Parser}. * @param parsers An object containing named parsers that will be combined * into a single object parser. * @param options Optional configuration for error customization. * See {@link ObjectOptions}. * @returns A {@link Parser} that produces an object with the same keys as * the input, where each value is the result of the corresponding * parser. * @since 0.5.0 */ declare function object; }>(parsers: T, options: ObjectOptions): Parser, { 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 }>; /** * Creates a labeled parser that combines multiple parsers into a single * object parser with an associated label for documentation or error reporting. * @template T A record type where each value is a {@link Parser}. * @param label A descriptive label for this parser group, used for * documentation and error messages. * @param parsers An object containing named parsers that will be combined * into a single object parser. * @returns A {@link Parser} that produces an object with the same keys as * the input, where each value is the result of the corresponding * parser. * @throws {TypeError} If the label is not a string, is empty, * whitespace-only, or contains control characters. */ declare function object; }>(label: string, parsers: T): Parser, { 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 }>; /** * Creates a labeled parser that combines multiple parsers into a single * object parser with an associated label for documentation or error reporting. * @template T A record type where each value is a {@link Parser}. * @param label A descriptive label for this parser group, used for * documentation and error messages. * @param parsers An object containing named parsers that will be combined * into a single object parser. * @param options Optional configuration for error customization. * See {@link ObjectOptions}. * @returns A {@link Parser} that produces an object with the same keys as * the input, where each value is the result of the corresponding * parser. * @throws {TypeError} If the label is not a string, is empty, * whitespace-only, or contains control characters. * @since 0.5.0 */ declare function object; }>(label: string, parsers: T, options: ObjectOptions): Parser, { 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 }>; /** * Options for the {@link tuple} parser. * @since 0.7.0 */ interface TupleOptions { /** * When `true`, allows duplicate option names across different parsers. * By default (`false`), duplicate option names cause a construction-time * error. * * @default `false` * @since 0.7.0 */ readonly allowDuplicates?: boolean; } /** * Options for the {@link seq} parser. * @since 1.1.0 */ interface SeqOptions { /** * When `true`, allows duplicate option names even when they can be active * at the same sequential position. By default (`false`), duplicate option * names at the same position cause a construction-time error. * * @default `false` * @since 1.1.0 */ readonly allowDuplicates?: boolean; } type SeqTailOptions = SeqOptions & { readonly $valueType?: never; }; interface SeqState { readonly index: number; readonly states: readonly unknown[]; } /** * Creates a parser that combines multiple parsers into a sequential tuple parser. * The parsers are applied in the order they appear in the array, and all must * succeed for the tuple parser to succeed. * @template T A readonly array type where each element is a {@link Parser}. * @param parsers An array of parsers that will be applied sequentially * to create a tuple of their results. * @param options Optional configuration for the tuple parser. * @returns A {@link Parser} that produces a readonly tuple with the same length * as the input array, where each element is the result of the * corresponding parser. */ declare function tuple[]>(parsers: T, options?: TupleOptions): Parser, { 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 }>; /** * Creates a labeled parser that combines multiple parsers into a sequential * tuple parser with an associated label for documentation or error reporting. * @template T A readonly array type where each element is a {@link Parser}. * @param label A descriptive label for this parser group, used for * documentation and error messages. * @param parsers An array of parsers that will be applied sequentially * to create a tuple of their results. * @param options Optional configuration for the tuple parser. * @returns A {@link Parser} that produces a readonly tuple with the same length * as the input array, where each element is the result of the * corresponding parser. * @throws {TypeError} If the label is not a string, is empty, * whitespace-only, or contains control characters. */ declare function tuple[]>(label: string, parsers: T, options?: TupleOptions): Parser, { 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 }>; /** * Creates an ordered parser that applies child parsers in declaration order. * * Unlike {@link tuple}, which lets child parsers compete for a shared input * buffer by priority, `seq()` keeps a cursor and only parses the current child. * A child may be skipped when its {@link Parser.canSkip} predicate reports * that it can complete without consuming more CLI input. * * @template T A readonly array type where each element is a {@link Parser}. * @param parsers Parsers to apply in the order they are provided. * @returns A parser that produces a readonly tuple of child values. * @since 1.1.0 */ declare function seq[]>(...parsers: T): Parser, { readonly [K in keyof T]: T[K]["$valueType"][number] extends (infer U) ? U : never }, SeqState>; /** * Creates an ordered parser with a label for generated documentation. * * @template T A readonly array type where each element is a {@link Parser}. * @param label A descriptive label for this parser group. * @param parsers Parsers to apply in the order they are provided. * @returns A parser that produces a readonly tuple of child values. * @throws {TypeError} If the label is empty, whitespace-only, or contains * control characters. * @since 1.1.0 */ declare function seq[]>(label: string, ...parsers: T): Parser, { readonly [K in keyof T]: T[K]["$valueType"][number] extends (infer U) ? U : never }, SeqState>; /** * Creates an ordered parser with options. * * @template T A readonly array type where each element is a {@link Parser}. * @param parsers Parsers to apply in the order they are provided, followed by * {@link SeqOptions}. * @returns A parser that produces a readonly tuple of child values. * @since 1.1.0 */ declare function seq[]>(...args: readonly [...T, SeqTailOptions]): Parser, { readonly [K in keyof T]: T[K]["$valueType"][number] extends (infer U) ? U : never }, SeqState>; /** * Creates a labeled ordered parser with options. * * @template T A readonly array type where each element is a {@link Parser}. * @param label A descriptive label for this parser group. * @param args Parsers to apply in the order they are provided, followed by * {@link SeqOptions}. * @returns A parser that produces a readonly tuple of child values. * @throws {TypeError} If the label is empty, whitespace-only, or contains * control characters. * @since 1.1.0 */ declare function seq[]>(label: string, ...args: readonly [...T, SeqTailOptions]): Parser, { readonly [K in keyof T]: T[K]["$valueType"][number] extends (infer U) ? U : never }, SeqState>; /** * Helper type to check if all members of a union are object-like. * This allows merge() to work with parsers like withDefault() that produce union types. */ type AllObjectLike = T extends readonly unknown[] ? never : T extends Record ? T : never; /** * Helper type to extract object-like types from parser value types, * including union types where all members are objects. */ type ExtractObjectTypes

= P extends Parser ? [AllObjectLike] extends [never] ? never : V : never; /** * Options for the {@link merge} parser. * @since 0.7.0 */ interface MergeOptions { /** * When `true`, allows duplicate option names across merged parsers. * By default (`false`), duplicate option names cause a construction-time * error. * * @default `false` * @since 0.7.0 */ readonly allowDuplicates?: boolean; /** * Controls visibility of all terms emitted by this merged parser. * @since 1.0.0 */ readonly hidden?: HiddenVisibility; } type MergeParserArity = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15; type MergeArityLimitError = { readonly __optiqueMergeArityLimit: "merge() requires between 1 and 15 parser arguments. Nest merge() to combine more."; }; type MergeTailOptions = MergeOptions & { readonly $valueType?: never; }; type MergeArityGuard = IsTuple extends true ? TParsers["length"] extends MergeParserArity ? unknown : MergeArityLimitError : unknown; type MergeParsers = readonly Parser[]; type EnsureMergeParsers = { readonly [K in keyof TParsers]: ExtractObjectTypes extends never ? never : TParsers[K] }; type IntersectMergeValues = TParsers extends readonly [infer THead extends Parser, ...infer TRest extends MergeParsers] ? ExtractObjectTypes & IntersectMergeValues : unknown; type MergeValues = IsTuple extends true ? IntersectMergeValues : Record; type MergeReturnType = Parser }>, MergeValues, Record>; /** * Merges multiple object-like parsers into one parser, with options. * * This is useful for combining separate object parsers into one * unified parser while keeping fields grouped by parser boundaries. * * @param rest Parsers to merge, followed by merge options. * @returns A parser that merges parsed object fields from all parsers. * Type inference is precise for tuple calls up to 15 parser arguments. * @throws {TypeError} If no parser arguments are provided. * @since 0.7.0 */ declare function merge(...rest: [...parsers: EnsureMergeParsers, options: MergeTailOptions] & MergeArityGuard): MergeReturnType; /** * Merges multiple object-like parsers into one labeled parser. * * This is useful for combining separate object parsers into one * unified parser while keeping fields grouped by parser boundaries. * * @param label Label used in documentation output. * @param parsers Parsers to merge in declaration order. * @returns A parser that merges parsed object fields from all parsers. * Type inference is precise for tuple calls up to 15 parser arguments. * @throws {TypeError} If no parser arguments are provided. * @throws {TypeError} If the label is not a string, is empty, * whitespace-only, or contains control characters. * @since 0.4.0 */ declare function merge(label: string, ...parsers: EnsureMergeParsers & MergeArityGuard): MergeReturnType; /** * Merges multiple object-like parsers into one labeled parser, with options. * * This is useful for combining separate object parsers into one * unified parser while keeping fields grouped by parser boundaries. * * @param label Label used in documentation output. * @param rest Parsers to merge, followed by merge options. * @returns A parser that merges parsed object fields from all parsers. * Type inference is precise for tuple calls up to 15 parser arguments. * @throws {TypeError} If no parser arguments are provided. * @throws {TypeError} If the label is not a string, is empty, * whitespace-only, or contains control characters. * @since 0.7.0 */ declare function merge(label: string, ...rest: [...parsers: EnsureMergeParsers, options: MergeTailOptions] & MergeArityGuard): MergeReturnType; /** * Merges multiple object-like parsers into one parser. * * This is useful for combining separate object parsers into one * unified parser while keeping fields grouped by parser boundaries. * * @param parsers Parsers to merge in declaration order. * @returns A parser that merges parsed object fields from all parsers. * Type inference is precise for tuple calls up to 15 parser arguments. * @throws {TypeError} If no parser arguments are provided. * @since 0.1.0 */ declare function merge(...parsers: EnsureMergeParsers & MergeArityGuard): MergeReturnType; type ConcatParserArity = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15; type ConcatArityLimitError = { readonly __optiqueConcatArityLimit: "concat() requires between 1 and 15 parser arguments. Nest concat() to combine more."; }; type ConcatParsers = readonly Parser[]; type ConcatArityGuard = IsTuple extends true ? TParsers["length"] extends ConcatParserArity ? unknown : ConcatArityLimitError : unknown; type ConcatStates = { [K in keyof TParsers]: TParsers[K] extends Parser ? TState : never }; type ConcatTupleValues = TParsers extends readonly [Parser, ...infer TRest extends ConcatParsers] ? [...THead, ...ConcatTupleValues] : []; type ConcatValues = IsTuple extends true ? ConcatTupleValues : readonly unknown[]; /** * Concatenates tuple parsers into one parser with a flattened tuple value. * * Unlike {@link merge}, which combines object fields, this combines tuple * entries in order into one flattened tuple value. * * @example * ```typescript * import { parse } from "@optique/core/parser"; * import { option } from "@optique/core/primitives"; * import { integer, string } from "@optique/core/valueparser"; * * const basicTuple = tuple([ * option("-v", "--verbose"), * option("-p", "--port", integer()), * ]); * * const serverTuple = tuple([ * option("-h", "--host", string()), * option("-d", "--debug"), * ]); * * const combined = concat(basicTuple, serverTuple); * // Inferred type: Parser<..., [boolean, number, string, boolean], ...> * * const result = parse( * combined, * ["-v", "-p", "8080", "-h", "localhost", "-d"], * ); * // result.value: [true, 8080, "localhost", true] * ``` * * @param parsers Tuple parsers to concatenate. * @returns A parser with flattened tuple values from all parsers. * Type inference is precise for tuple calls up to 15 parser arguments. * @throws {TypeError} If no parser arguments are provided. * @since 0.2.0 */ declare function concat(...parsers: TParsers & ConcatArityGuard): Parser }>, ConcatValues, ConcatStates>; /** * Wraps a parser with a group label for documentation purposes. * * The `group()` function is a documentation-only wrapper that applies a label * to any parser for help text organization. This allows you to use clean code * structure with combinators like {@link merge} while maintaining well-organized * help text through group labeling. * * The wrapped parser has identical parsing behavior but generates documentation * fragments wrapped in a labeled section. This is particularly useful when * combining parsers using {@link merge}—you can wrap the merged result with * `group()` to add a section header in help output. * * @example * ```typescript * const apiOptions = merge( * object({ endpoint: option("--endpoint", string()) }), * object({ timeout: option("--timeout", integer()) }) * ); * * const groupedApiOptions = group("API Options", apiOptions); * // Now produces a labeled "API Options" section in help text * ``` * * @example * ```typescript * // Can be used with any parser, not just merge() * const verboseGroup = group("Verbosity", object({ * verbose: option("-v", "--verbose"), * quiet: option("-q", "--quiet") * })); * ``` * * @template TValue The value type of the wrapped parser. * @template TState The state type of the wrapped parser. * @param label A descriptive label for this parser group, used for * documentation and help text organization. * @param parser The parser to wrap with a group label. * @param options Optional visibility controls for the wrapped parser terms. * @returns A new parser that behaves identically to the input parser * but generates documentation within a labeled section. * @throws {TypeError} If the label is not a string, is empty, * whitespace-only, or contains control characters. * @since 0.4.0 */ /** * Options for the {@link group} parser wrapper. * @since 1.0.0 */ interface GroupOptions { /** * Controls visibility of all terms emitted by this group. */ readonly hidden?: HiddenVisibility; } declare function group(label: string, parser: Parser, options?: GroupOptions): Parser; /** * Tagged union type representing which branch is selected. * Uses tagged union to avoid collision with discriminator values. * @internal */ type SelectedBranch = { readonly kind: "branch"; readonly key: TDiscriminator; } | { readonly kind: "default"; }; /** * State type for the conditional parser. * @internal */ interface ConditionalState { readonly discriminatorState: unknown; readonly discriminatorValue: TDiscriminator | undefined; readonly selectedBranch: SelectedBranch | undefined; readonly branchState: unknown; readonly speculative?: true; } /** * Options for customizing error messages in the {@link conditional} combinator. * @since 0.8.0 */ interface ConditionalErrorOptions { /** * Custom error message when branch parser fails. * Receives the discriminator value for context. */ readonly branchError?: (discriminatorValue: string | undefined, error: Message) => Message; /** * Custom error message for no matching input. */ readonly noMatch?: Message | ((context: NoMatchContext) => Message); /** * Custom error message when speculative branch parsing committed * to one branch but the resolved discriminator value names a * different branch. This is the contradictory-input case: tokens * specific to one branch were consumed during the parse phase, * but the discriminator (e.g., from `prompt()` or a deferred * config source) ultimately resolved to a different key. * * Receives both the discriminator value the parser actually * resolved to (`discriminatorValue`) and the speculative key the * branch tokens were committed to (`speculativeKey`). * @since 1.0.1 */ readonly branchMismatch?: (discriminatorValue: string, speculativeKey: string) => Message; } /** * Options for customizing the {@link conditional} combinator behavior. * @since 0.8.0 */ interface ConditionalOptions { /** * Custom error messages. */ readonly errors?: ConditionalErrorOptions; } /** * Helper type to infer result type without default branch. * @internal */ type ConditionalResultWithoutDefault>> = { [K in keyof TBranches & string]: readonly [K, InferValue] }[keyof TBranches & string]; /** * Helper type to infer result type with default branch. * @internal */ type ConditionalResultWithDefault>, TDefault extends Parser> = ConditionalResultWithoutDefault | readonly [undefined, InferValue]; /** * Creates a conditional parser without a default branch. * The discriminator option is required; parsing fails if not provided. * * @template TDiscriminator The string literal union type of discriminator values. * @template TBranches Record mapping discriminator values to branch parsers. * @param discriminator Parser for the discriminator option (typically using choice()). * @param branches Object mapping each discriminator value to its branch parser. * @returns A parser that produces a tuple `[discriminatorValue, branchResult]`. * @since 0.8.0 */ declare function conditional }, TD extends Parser>(discriminator: TD, branches: TBranches): Parser, ...{ [K in keyof TBranches]: ExtractMode }[keyof TBranches][]]>, ConditionalResultWithoutDefault, ConditionalState>; /** * Creates a conditional parser with a default branch. * The default branch is used when the discriminator option is not provided. * * @template TDiscriminator The string literal union type of discriminator values. * @template TBranches Record mapping discriminator values to branch parsers. * @template TDefault The default branch parser type. * @param discriminator Parser for the discriminator option (typically using choice()). * @param branches Object mapping each discriminator value to its branch parser. * @param defaultBranch Parser to use when discriminator is not provided. * @param options Optional configuration for error messages. * @returns A parser that produces a tuple `[discriminatorValue | undefined, branchResult]`. * @since 0.8.0 */ declare function conditional }, TDefault extends Parser, TD extends Parser>(discriminator: TD, branches: TBranches, defaultBranch: TDefault, options?: ConditionalOptions): Parser, ExtractMode, ...{ [K in keyof TBranches]: ExtractMode }[keyof TBranches][]]>, ConditionalResultWithDefault, ConditionalState>; //#endregion export { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, GroupOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, SeqOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, seq, tuple };