@optique/core 1.0.0-dev.489 → 1.0.0-dev.491
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.
- package/dist/constructs.d.cts +42 -2
- package/dist/constructs.d.ts +42 -2
- package/dist/parser.cjs +15 -3
- package/dist/parser.js +15 -3
- package/dist/primitives.cjs +1 -0
- package/dist/primitives.d.cts +14 -1
- package/dist/primitives.d.ts +14 -1
- package/dist/primitives.js +1 -0
- package/dist/usage.cjs +6 -0
- package/dist/usage.d.cts +17 -0
- package/dist/usage.d.ts +17 -0
- package/dist/usage.js +6 -0
- package/package.json +1 -1
package/dist/constructs.d.cts
CHANGED
|
@@ -106,6 +106,11 @@ declare class DuplicateOptionError extends Error {
|
|
|
106
106
|
readonly sources: readonly (string | symbol)[];
|
|
107
107
|
constructor(optionName: string, sources: readonly (string | symbol)[]);
|
|
108
108
|
}
|
|
109
|
+
type OrParserArity = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15;
|
|
110
|
+
type OrArityLimitError = {
|
|
111
|
+
readonly __optiqueOrArityLimit: "or() supports up to 15 parser arguments. Nest or() to combine more.";
|
|
112
|
+
};
|
|
113
|
+
type OrArityGuard<TParsers extends readonly unknown[]> = TParsers["length"] extends OrParserArity ? unknown : OrArityLimitError;
|
|
109
114
|
/**
|
|
110
115
|
* Creates a parser that combines two mutually exclusive parsers into one.
|
|
111
116
|
* The resulting parser will try each of the provided parsers in order,
|
|
@@ -399,6 +404,41 @@ declare function or<MA extends Mode, MB extends Mode, MC extends Mode, MD extend
|
|
|
399
404
|
* @since 0.3.0
|
|
400
405
|
*/
|
|
401
406
|
declare function or<MA extends Mode, MB extends Mode, MC extends Mode, MD extends Mode, ME extends Mode, MF extends Mode, MG extends Mode, MH extends Mode, MI extends Mode, MJ extends Mode, TA, TB, TC, TD, TE, TF, TG, TH, TI, TJ, TStateA, TStateB, TStateC, TStateD, TStateE, TStateF, TStateG, TStateH, TStateI, TStateJ>(a: Parser<MA, TA, TStateA>, b: Parser<MB, TB, TStateB>, c: Parser<MC, TC, TStateC>, d: Parser<MD, TD, TStateD>, e: Parser<ME, TE, TStateE>, f: Parser<MF, TF, TStateF>, g: Parser<MG, TG, TStateG>, h: Parser<MH, TH, TStateH>, i: Parser<MI, TI, TStateI>, j: Parser<MJ, TJ, TStateJ>): Parser<CombineModes<readonly [MA, MB, MC, MD, ME, MF, MG, MH, MI, MJ]>, TA | TB | TC | TD | TE | TF | TG | TH | TI | TJ, undefined | [0, ParserResult<TStateA>] | [1, ParserResult<TStateB>] | [2, ParserResult<TStateC>] | [3, ParserResult<TStateD>] | [4, ParserResult<TStateE>] | [5, ParserResult<TStateF>] | [6, ParserResult<TStateG>] | [7, ParserResult<TStateH>] | [8, ParserResult<TStateI>] | [9, ParserResult<TStateJ>]>;
|
|
407
|
+
/**
|
|
408
|
+
* Creates a parser that combines eleven mutually exclusive parsers into one.
|
|
409
|
+
* The resulting parser will try each of the provided parsers in order,
|
|
410
|
+
* and return the result of the first successful parser.
|
|
411
|
+
* @since 0.9.0
|
|
412
|
+
*/
|
|
413
|
+
declare function or<MA extends Mode, MB extends Mode, MC extends Mode, MD extends Mode, ME extends Mode, MF extends Mode, MG extends Mode, MH extends Mode, MI extends Mode, MJ extends Mode, MK extends Mode, TA, TB, TC, TD, TE, TF, TG, TH, TI, TJ, TK, TStateA, TStateB, TStateC, TStateD, TStateE, TStateF, TStateG, TStateH, TStateI, TStateJ, TStateK>(a: Parser<MA, TA, TStateA>, b: Parser<MB, TB, TStateB>, c: Parser<MC, TC, TStateC>, d: Parser<MD, TD, TStateD>, e: Parser<ME, TE, TStateE>, f: Parser<MF, TF, TStateF>, g: Parser<MG, TG, TStateG>, h: Parser<MH, TH, TStateH>, i: Parser<MI, TI, TStateI>, j: Parser<MJ, TJ, TStateJ>, k: Parser<MK, TK, TStateK>): Parser<CombineModes<readonly [MA, MB, MC, MD, ME, MF, MG, MH, MI, MJ, MK]>, TA | TB | TC | TD | TE | TF | TG | TH | TI | TJ | TK, undefined | [0, ParserResult<TStateA>] | [1, ParserResult<TStateB>] | [2, ParserResult<TStateC>] | [3, ParserResult<TStateD>] | [4, ParserResult<TStateE>] | [5, ParserResult<TStateF>] | [6, ParserResult<TStateG>] | [7, ParserResult<TStateH>] | [8, ParserResult<TStateI>] | [9, ParserResult<TStateJ>] | [10, ParserResult<TStateK>]>;
|
|
414
|
+
/**
|
|
415
|
+
* Creates a parser that combines twelve mutually exclusive parsers into one.
|
|
416
|
+
* The resulting parser will try each of the provided parsers in order,
|
|
417
|
+
* and return the result of the first successful parser.
|
|
418
|
+
* @since 0.9.0
|
|
419
|
+
*/
|
|
420
|
+
declare function or<MA extends Mode, MB extends Mode, MC extends Mode, MD extends Mode, ME extends Mode, MF extends Mode, MG extends Mode, MH extends Mode, MI extends Mode, MJ extends Mode, MK extends Mode, ML extends Mode, TA, TB, TC, TD, TE, TF, TG, TH, TI, TJ, TK, TL, TStateA, TStateB, TStateC, TStateD, TStateE, TStateF, TStateG, TStateH, TStateI, TStateJ, TStateK, TStateL>(a: Parser<MA, TA, TStateA>, b: Parser<MB, TB, TStateB>, c: Parser<MC, TC, TStateC>, d: Parser<MD, TD, TStateD>, e: Parser<ME, TE, TStateE>, f: Parser<MF, TF, TStateF>, g: Parser<MG, TG, TStateG>, h: Parser<MH, TH, TStateH>, i: Parser<MI, TI, TStateI>, j: Parser<MJ, TJ, TStateJ>, k: Parser<MK, TK, TStateK>, l: Parser<ML, TL, TStateL>): Parser<CombineModes<readonly [MA, MB, MC, MD, ME, MF, MG, MH, MI, MJ, MK, ML]>, TA | TB | TC | TD | TE | TF | TG | TH | TI | TJ | TK | TL, undefined | [0, ParserResult<TStateA>] | [1, ParserResult<TStateB>] | [2, ParserResult<TStateC>] | [3, ParserResult<TStateD>] | [4, ParserResult<TStateE>] | [5, ParserResult<TStateF>] | [6, ParserResult<TStateG>] | [7, ParserResult<TStateH>] | [8, ParserResult<TStateI>] | [9, ParserResult<TStateJ>] | [10, ParserResult<TStateK>] | [11, ParserResult<TStateL>]>;
|
|
421
|
+
/**
|
|
422
|
+
* Creates a parser that combines thirteen mutually exclusive parsers into one.
|
|
423
|
+
* The resulting parser will try each of the provided parsers in order,
|
|
424
|
+
* and return the result of the first successful parser.
|
|
425
|
+
* @since 0.9.0
|
|
426
|
+
*/
|
|
427
|
+
declare function or<MA extends Mode, MB extends Mode, MC extends Mode, MD extends Mode, ME extends Mode, MF extends Mode, MG extends Mode, MH extends Mode, MI extends Mode, MJ extends Mode, MK extends Mode, ML extends Mode, MM extends Mode, TA, TB, TC, TD, TE, TF, TG, TH, TI, TJ, TK, TL, TM, TStateA, TStateB, TStateC, TStateD, TStateE, TStateF, TStateG, TStateH, TStateI, TStateJ, TStateK, TStateL, TStateM>(a: Parser<MA, TA, TStateA>, b: Parser<MB, TB, TStateB>, c: Parser<MC, TC, TStateC>, d: Parser<MD, TD, TStateD>, e: Parser<ME, TE, TStateE>, f: Parser<MF, TF, TStateF>, g: Parser<MG, TG, TStateG>, h: Parser<MH, TH, TStateH>, i: Parser<MI, TI, TStateI>, j: Parser<MJ, TJ, TStateJ>, k: Parser<MK, TK, TStateK>, l: Parser<ML, TL, TStateL>, m: Parser<MM, TM, TStateM>): Parser<CombineModes<readonly [MA, MB, MC, MD, ME, MF, MG, MH, MI, MJ, MK, ML, MM]>, TA | TB | TC | TD | TE | TF | TG | TH | TI | TJ | TK | TL | TM, undefined | [0, ParserResult<TStateA>] | [1, ParserResult<TStateB>] | [2, ParserResult<TStateC>] | [3, ParserResult<TStateD>] | [4, ParserResult<TStateE>] | [5, ParserResult<TStateF>] | [6, ParserResult<TStateG>] | [7, ParserResult<TStateH>] | [8, ParserResult<TStateI>] | [9, ParserResult<TStateJ>] | [10, ParserResult<TStateK>] | [11, ParserResult<TStateL>] | [12, ParserResult<TStateM>]>;
|
|
428
|
+
/**
|
|
429
|
+
* Creates a parser that combines fourteen mutually exclusive parsers into one.
|
|
430
|
+
* The resulting parser will try each of the provided parsers in order,
|
|
431
|
+
* and return the result of the first successful parser.
|
|
432
|
+
* @since 0.9.0
|
|
433
|
+
*/
|
|
434
|
+
declare function or<MA extends Mode, MB extends Mode, MC extends Mode, MD extends Mode, ME extends Mode, MF extends Mode, MG extends Mode, MH extends Mode, MI extends Mode, MJ extends Mode, MK extends Mode, ML extends Mode, MM extends Mode, MN extends Mode, TA, TB, TC, TD, TE, TF, TG, TH, TI, TJ, TK, TL, TM, TN, TStateA, TStateB, TStateC, TStateD, TStateE, TStateF, TStateG, TStateH, TStateI, TStateJ, TStateK, TStateL, TStateM, TStateN>(a: Parser<MA, TA, TStateA>, b: Parser<MB, TB, TStateB>, c: Parser<MC, TC, TStateC>, d: Parser<MD, TD, TStateD>, e: Parser<ME, TE, TStateE>, f: Parser<MF, TF, TStateF>, g: Parser<MG, TG, TStateG>, h: Parser<MH, TH, TStateH>, i: Parser<MI, TI, TStateI>, j: Parser<MJ, TJ, TStateJ>, k: Parser<MK, TK, TStateK>, l: Parser<ML, TL, TStateL>, m: Parser<MM, TM, TStateM>, n: Parser<MN, TN, TStateN>): Parser<CombineModes<readonly [MA, MB, MC, MD, ME, MF, MG, MH, MI, MJ, MK, ML, MM, MN]>, TA | TB | TC | TD | TE | TF | TG | TH | TI | TJ | TK | TL | TM | TN, undefined | [0, ParserResult<TStateA>] | [1, ParserResult<TStateB>] | [2, ParserResult<TStateC>] | [3, ParserResult<TStateD>] | [4, ParserResult<TStateE>] | [5, ParserResult<TStateF>] | [6, ParserResult<TStateG>] | [7, ParserResult<TStateH>] | [8, ParserResult<TStateI>] | [9, ParserResult<TStateJ>] | [10, ParserResult<TStateK>] | [11, ParserResult<TStateL>] | [12, ParserResult<TStateM>] | [13, ParserResult<TStateN>]>;
|
|
435
|
+
/**
|
|
436
|
+
* Creates a parser that combines fifteen mutually exclusive parsers into one.
|
|
437
|
+
* The resulting parser will try each of the provided parsers in order,
|
|
438
|
+
* and return the result of the first successful parser.
|
|
439
|
+
* @since 0.9.0
|
|
440
|
+
*/
|
|
441
|
+
declare function or<MA extends Mode, MB extends Mode, MC extends Mode, MD extends Mode, ME extends Mode, MF extends Mode, MG extends Mode, MH extends Mode, MI extends Mode, MJ extends Mode, MK extends Mode, ML extends Mode, MM extends Mode, MN extends Mode, MO extends Mode, TA, TB, TC, TD, TE, TF, TG, TH, TI, TJ, TK, TL, TM, TN, TO, TStateA, TStateB, TStateC, TStateD, TStateE, TStateF, TStateG, TStateH, TStateI, TStateJ, TStateK, TStateL, TStateM, TStateN, TStateO>(a: Parser<MA, TA, TStateA>, b: Parser<MB, TB, TStateB>, c: Parser<MC, TC, TStateC>, d: Parser<MD, TD, TStateD>, e: Parser<ME, TE, TStateE>, f: Parser<MF, TF, TStateF>, g: Parser<MG, TG, TStateG>, h: Parser<MH, TH, TStateH>, i: Parser<MI, TI, TStateI>, j: Parser<MJ, TJ, TStateJ>, k: Parser<MK, TK, TStateK>, l: Parser<ML, TL, TStateL>, m: Parser<MM, TM, TStateM>, n: Parser<MN, TN, TStateN>, o: Parser<MO, TO, TStateO>): Parser<CombineModes<readonly [MA, MB, MC, MD, ME, MF, MG, MH, MI, MJ, MK, ML, MM, MN, MO]>, TA | TB | TC | TD | TE | TF | TG | TH | TI | TJ | TK | TL | TM | TN | TO, undefined | [0, ParserResult<TStateA>] | [1, ParserResult<TStateB>] | [2, ParserResult<TStateC>] | [3, ParserResult<TStateD>] | [4, ParserResult<TStateE>] | [5, ParserResult<TStateF>] | [6, ParserResult<TStateG>] | [7, ParserResult<TStateH>] | [8, ParserResult<TStateI>] | [9, ParserResult<TStateJ>] | [10, ParserResult<TStateK>] | [11, ParserResult<TStateL>] | [12, ParserResult<TStateM>] | [13, ParserResult<TStateN>] | [14, ParserResult<TStateO>]>;
|
|
402
442
|
/**
|
|
403
443
|
* Creates a parser that combines two mutually exclusive parsers into one,
|
|
404
444
|
* with custom error message options.
|
|
@@ -425,7 +465,6 @@ declare function or<TA extends Parser<Mode, unknown, unknown>, TB extends Parser
|
|
|
425
465
|
* @since 0.5.0
|
|
426
466
|
*/
|
|
427
467
|
declare function or<TA extends Parser<Mode, unknown, unknown>, TB extends Parser<Mode, unknown, unknown>, TC extends Parser<Mode, unknown, unknown>>(a: TA, b: TB, c: TC, options: OrOptions): Parser<CombineModes<readonly [ExtractMode<TA>, ExtractMode<TB>, ExtractMode<TC>]>, InferValue<TA> | InferValue<TB> | InferValue<TC>, undefined | [number, ParserResult<unknown>]>;
|
|
428
|
-
declare function or(...parsers: Parser<Mode, unknown, unknown>[]): Parser<Mode, unknown, undefined | [number, ParserResult<unknown>]>;
|
|
429
468
|
/**
|
|
430
469
|
* Creates a parser that tries each parser in sequence until one succeeds,
|
|
431
470
|
* with custom error message options.
|
|
@@ -434,7 +473,8 @@ declare function or(...parsers: Parser<Mode, unknown, unknown>[]): Parser<Mode,
|
|
|
434
473
|
* @returns A parser that succeeds if any of the input parsers succeed.
|
|
435
474
|
* @since 0.5.0
|
|
436
475
|
*/
|
|
437
|
-
declare function or
|
|
476
|
+
declare function or<const TParsers extends readonly Parser<Mode, unknown, unknown>[]>(...rest: [...parsers: TParsers, options: OrOptions] & OrArityGuard<TParsers>): Parser<CombineModes<{ readonly [K in keyof TParsers]: ExtractMode<TParsers[K]> }>, InferValue<TParsers[number]>, undefined | [number, ParserResult<unknown>]>;
|
|
477
|
+
declare function or<const TParsers extends readonly Parser<Mode, unknown, unknown>[]>(...parsers: TParsers & OrArityGuard<TParsers>): Parser<Mode, unknown, undefined | [number, ParserResult<unknown>]>;
|
|
438
478
|
/**
|
|
439
479
|
* Options for customizing error messages in the {@link longestMatch}
|
|
440
480
|
* combinator.
|
package/dist/constructs.d.ts
CHANGED
|
@@ -106,6 +106,11 @@ declare class DuplicateOptionError extends Error {
|
|
|
106
106
|
readonly sources: readonly (string | symbol)[];
|
|
107
107
|
constructor(optionName: string, sources: readonly (string | symbol)[]);
|
|
108
108
|
}
|
|
109
|
+
type OrParserArity = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15;
|
|
110
|
+
type OrArityLimitError = {
|
|
111
|
+
readonly __optiqueOrArityLimit: "or() supports up to 15 parser arguments. Nest or() to combine more.";
|
|
112
|
+
};
|
|
113
|
+
type OrArityGuard<TParsers extends readonly unknown[]> = TParsers["length"] extends OrParserArity ? unknown : OrArityLimitError;
|
|
109
114
|
/**
|
|
110
115
|
* Creates a parser that combines two mutually exclusive parsers into one.
|
|
111
116
|
* The resulting parser will try each of the provided parsers in order,
|
|
@@ -399,6 +404,41 @@ declare function or<MA extends Mode, MB extends Mode, MC extends Mode, MD extend
|
|
|
399
404
|
* @since 0.3.0
|
|
400
405
|
*/
|
|
401
406
|
declare function or<MA extends Mode, MB extends Mode, MC extends Mode, MD extends Mode, ME extends Mode, MF extends Mode, MG extends Mode, MH extends Mode, MI extends Mode, MJ extends Mode, TA, TB, TC, TD, TE, TF, TG, TH, TI, TJ, TStateA, TStateB, TStateC, TStateD, TStateE, TStateF, TStateG, TStateH, TStateI, TStateJ>(a: Parser<MA, TA, TStateA>, b: Parser<MB, TB, TStateB>, c: Parser<MC, TC, TStateC>, d: Parser<MD, TD, TStateD>, e: Parser<ME, TE, TStateE>, f: Parser<MF, TF, TStateF>, g: Parser<MG, TG, TStateG>, h: Parser<MH, TH, TStateH>, i: Parser<MI, TI, TStateI>, j: Parser<MJ, TJ, TStateJ>): Parser<CombineModes<readonly [MA, MB, MC, MD, ME, MF, MG, MH, MI, MJ]>, TA | TB | TC | TD | TE | TF | TG | TH | TI | TJ, undefined | [0, ParserResult<TStateA>] | [1, ParserResult<TStateB>] | [2, ParserResult<TStateC>] | [3, ParserResult<TStateD>] | [4, ParserResult<TStateE>] | [5, ParserResult<TStateF>] | [6, ParserResult<TStateG>] | [7, ParserResult<TStateH>] | [8, ParserResult<TStateI>] | [9, ParserResult<TStateJ>]>;
|
|
407
|
+
/**
|
|
408
|
+
* Creates a parser that combines eleven mutually exclusive parsers into one.
|
|
409
|
+
* The resulting parser will try each of the provided parsers in order,
|
|
410
|
+
* and return the result of the first successful parser.
|
|
411
|
+
* @since 0.9.0
|
|
412
|
+
*/
|
|
413
|
+
declare function or<MA extends Mode, MB extends Mode, MC extends Mode, MD extends Mode, ME extends Mode, MF extends Mode, MG extends Mode, MH extends Mode, MI extends Mode, MJ extends Mode, MK extends Mode, TA, TB, TC, TD, TE, TF, TG, TH, TI, TJ, TK, TStateA, TStateB, TStateC, TStateD, TStateE, TStateF, TStateG, TStateH, TStateI, TStateJ, TStateK>(a: Parser<MA, TA, TStateA>, b: Parser<MB, TB, TStateB>, c: Parser<MC, TC, TStateC>, d: Parser<MD, TD, TStateD>, e: Parser<ME, TE, TStateE>, f: Parser<MF, TF, TStateF>, g: Parser<MG, TG, TStateG>, h: Parser<MH, TH, TStateH>, i: Parser<MI, TI, TStateI>, j: Parser<MJ, TJ, TStateJ>, k: Parser<MK, TK, TStateK>): Parser<CombineModes<readonly [MA, MB, MC, MD, ME, MF, MG, MH, MI, MJ, MK]>, TA | TB | TC | TD | TE | TF | TG | TH | TI | TJ | TK, undefined | [0, ParserResult<TStateA>] | [1, ParserResult<TStateB>] | [2, ParserResult<TStateC>] | [3, ParserResult<TStateD>] | [4, ParserResult<TStateE>] | [5, ParserResult<TStateF>] | [6, ParserResult<TStateG>] | [7, ParserResult<TStateH>] | [8, ParserResult<TStateI>] | [9, ParserResult<TStateJ>] | [10, ParserResult<TStateK>]>;
|
|
414
|
+
/**
|
|
415
|
+
* Creates a parser that combines twelve mutually exclusive parsers into one.
|
|
416
|
+
* The resulting parser will try each of the provided parsers in order,
|
|
417
|
+
* and return the result of the first successful parser.
|
|
418
|
+
* @since 0.9.0
|
|
419
|
+
*/
|
|
420
|
+
declare function or<MA extends Mode, MB extends Mode, MC extends Mode, MD extends Mode, ME extends Mode, MF extends Mode, MG extends Mode, MH extends Mode, MI extends Mode, MJ extends Mode, MK extends Mode, ML extends Mode, TA, TB, TC, TD, TE, TF, TG, TH, TI, TJ, TK, TL, TStateA, TStateB, TStateC, TStateD, TStateE, TStateF, TStateG, TStateH, TStateI, TStateJ, TStateK, TStateL>(a: Parser<MA, TA, TStateA>, b: Parser<MB, TB, TStateB>, c: Parser<MC, TC, TStateC>, d: Parser<MD, TD, TStateD>, e: Parser<ME, TE, TStateE>, f: Parser<MF, TF, TStateF>, g: Parser<MG, TG, TStateG>, h: Parser<MH, TH, TStateH>, i: Parser<MI, TI, TStateI>, j: Parser<MJ, TJ, TStateJ>, k: Parser<MK, TK, TStateK>, l: Parser<ML, TL, TStateL>): Parser<CombineModes<readonly [MA, MB, MC, MD, ME, MF, MG, MH, MI, MJ, MK, ML]>, TA | TB | TC | TD | TE | TF | TG | TH | TI | TJ | TK | TL, undefined | [0, ParserResult<TStateA>] | [1, ParserResult<TStateB>] | [2, ParserResult<TStateC>] | [3, ParserResult<TStateD>] | [4, ParserResult<TStateE>] | [5, ParserResult<TStateF>] | [6, ParserResult<TStateG>] | [7, ParserResult<TStateH>] | [8, ParserResult<TStateI>] | [9, ParserResult<TStateJ>] | [10, ParserResult<TStateK>] | [11, ParserResult<TStateL>]>;
|
|
421
|
+
/**
|
|
422
|
+
* Creates a parser that combines thirteen mutually exclusive parsers into one.
|
|
423
|
+
* The resulting parser will try each of the provided parsers in order,
|
|
424
|
+
* and return the result of the first successful parser.
|
|
425
|
+
* @since 0.9.0
|
|
426
|
+
*/
|
|
427
|
+
declare function or<MA extends Mode, MB extends Mode, MC extends Mode, MD extends Mode, ME extends Mode, MF extends Mode, MG extends Mode, MH extends Mode, MI extends Mode, MJ extends Mode, MK extends Mode, ML extends Mode, MM extends Mode, TA, TB, TC, TD, TE, TF, TG, TH, TI, TJ, TK, TL, TM, TStateA, TStateB, TStateC, TStateD, TStateE, TStateF, TStateG, TStateH, TStateI, TStateJ, TStateK, TStateL, TStateM>(a: Parser<MA, TA, TStateA>, b: Parser<MB, TB, TStateB>, c: Parser<MC, TC, TStateC>, d: Parser<MD, TD, TStateD>, e: Parser<ME, TE, TStateE>, f: Parser<MF, TF, TStateF>, g: Parser<MG, TG, TStateG>, h: Parser<MH, TH, TStateH>, i: Parser<MI, TI, TStateI>, j: Parser<MJ, TJ, TStateJ>, k: Parser<MK, TK, TStateK>, l: Parser<ML, TL, TStateL>, m: Parser<MM, TM, TStateM>): Parser<CombineModes<readonly [MA, MB, MC, MD, ME, MF, MG, MH, MI, MJ, MK, ML, MM]>, TA | TB | TC | TD | TE | TF | TG | TH | TI | TJ | TK | TL | TM, undefined | [0, ParserResult<TStateA>] | [1, ParserResult<TStateB>] | [2, ParserResult<TStateC>] | [3, ParserResult<TStateD>] | [4, ParserResult<TStateE>] | [5, ParserResult<TStateF>] | [6, ParserResult<TStateG>] | [7, ParserResult<TStateH>] | [8, ParserResult<TStateI>] | [9, ParserResult<TStateJ>] | [10, ParserResult<TStateK>] | [11, ParserResult<TStateL>] | [12, ParserResult<TStateM>]>;
|
|
428
|
+
/**
|
|
429
|
+
* Creates a parser that combines fourteen mutually exclusive parsers into one.
|
|
430
|
+
* The resulting parser will try each of the provided parsers in order,
|
|
431
|
+
* and return the result of the first successful parser.
|
|
432
|
+
* @since 0.9.0
|
|
433
|
+
*/
|
|
434
|
+
declare function or<MA extends Mode, MB extends Mode, MC extends Mode, MD extends Mode, ME extends Mode, MF extends Mode, MG extends Mode, MH extends Mode, MI extends Mode, MJ extends Mode, MK extends Mode, ML extends Mode, MM extends Mode, MN extends Mode, TA, TB, TC, TD, TE, TF, TG, TH, TI, TJ, TK, TL, TM, TN, TStateA, TStateB, TStateC, TStateD, TStateE, TStateF, TStateG, TStateH, TStateI, TStateJ, TStateK, TStateL, TStateM, TStateN>(a: Parser<MA, TA, TStateA>, b: Parser<MB, TB, TStateB>, c: Parser<MC, TC, TStateC>, d: Parser<MD, TD, TStateD>, e: Parser<ME, TE, TStateE>, f: Parser<MF, TF, TStateF>, g: Parser<MG, TG, TStateG>, h: Parser<MH, TH, TStateH>, i: Parser<MI, TI, TStateI>, j: Parser<MJ, TJ, TStateJ>, k: Parser<MK, TK, TStateK>, l: Parser<ML, TL, TStateL>, m: Parser<MM, TM, TStateM>, n: Parser<MN, TN, TStateN>): Parser<CombineModes<readonly [MA, MB, MC, MD, ME, MF, MG, MH, MI, MJ, MK, ML, MM, MN]>, TA | TB | TC | TD | TE | TF | TG | TH | TI | TJ | TK | TL | TM | TN, undefined | [0, ParserResult<TStateA>] | [1, ParserResult<TStateB>] | [2, ParserResult<TStateC>] | [3, ParserResult<TStateD>] | [4, ParserResult<TStateE>] | [5, ParserResult<TStateF>] | [6, ParserResult<TStateG>] | [7, ParserResult<TStateH>] | [8, ParserResult<TStateI>] | [9, ParserResult<TStateJ>] | [10, ParserResult<TStateK>] | [11, ParserResult<TStateL>] | [12, ParserResult<TStateM>] | [13, ParserResult<TStateN>]>;
|
|
435
|
+
/**
|
|
436
|
+
* Creates a parser that combines fifteen mutually exclusive parsers into one.
|
|
437
|
+
* The resulting parser will try each of the provided parsers in order,
|
|
438
|
+
* and return the result of the first successful parser.
|
|
439
|
+
* @since 0.9.0
|
|
440
|
+
*/
|
|
441
|
+
declare function or<MA extends Mode, MB extends Mode, MC extends Mode, MD extends Mode, ME extends Mode, MF extends Mode, MG extends Mode, MH extends Mode, MI extends Mode, MJ extends Mode, MK extends Mode, ML extends Mode, MM extends Mode, MN extends Mode, MO extends Mode, TA, TB, TC, TD, TE, TF, TG, TH, TI, TJ, TK, TL, TM, TN, TO, TStateA, TStateB, TStateC, TStateD, TStateE, TStateF, TStateG, TStateH, TStateI, TStateJ, TStateK, TStateL, TStateM, TStateN, TStateO>(a: Parser<MA, TA, TStateA>, b: Parser<MB, TB, TStateB>, c: Parser<MC, TC, TStateC>, d: Parser<MD, TD, TStateD>, e: Parser<ME, TE, TStateE>, f: Parser<MF, TF, TStateF>, g: Parser<MG, TG, TStateG>, h: Parser<MH, TH, TStateH>, i: Parser<MI, TI, TStateI>, j: Parser<MJ, TJ, TStateJ>, k: Parser<MK, TK, TStateK>, l: Parser<ML, TL, TStateL>, m: Parser<MM, TM, TStateM>, n: Parser<MN, TN, TStateN>, o: Parser<MO, TO, TStateO>): Parser<CombineModes<readonly [MA, MB, MC, MD, ME, MF, MG, MH, MI, MJ, MK, ML, MM, MN, MO]>, TA | TB | TC | TD | TE | TF | TG | TH | TI | TJ | TK | TL | TM | TN | TO, undefined | [0, ParserResult<TStateA>] | [1, ParserResult<TStateB>] | [2, ParserResult<TStateC>] | [3, ParserResult<TStateD>] | [4, ParserResult<TStateE>] | [5, ParserResult<TStateF>] | [6, ParserResult<TStateG>] | [7, ParserResult<TStateH>] | [8, ParserResult<TStateI>] | [9, ParserResult<TStateJ>] | [10, ParserResult<TStateK>] | [11, ParserResult<TStateL>] | [12, ParserResult<TStateM>] | [13, ParserResult<TStateN>] | [14, ParserResult<TStateO>]>;
|
|
402
442
|
/**
|
|
403
443
|
* Creates a parser that combines two mutually exclusive parsers into one,
|
|
404
444
|
* with custom error message options.
|
|
@@ -425,7 +465,6 @@ declare function or<TA extends Parser<Mode, unknown, unknown>, TB extends Parser
|
|
|
425
465
|
* @since 0.5.0
|
|
426
466
|
*/
|
|
427
467
|
declare function or<TA extends Parser<Mode, unknown, unknown>, TB extends Parser<Mode, unknown, unknown>, TC extends Parser<Mode, unknown, unknown>>(a: TA, b: TB, c: TC, options: OrOptions): Parser<CombineModes<readonly [ExtractMode<TA>, ExtractMode<TB>, ExtractMode<TC>]>, InferValue<TA> | InferValue<TB> | InferValue<TC>, undefined | [number, ParserResult<unknown>]>;
|
|
428
|
-
declare function or(...parsers: Parser<Mode, unknown, unknown>[]): Parser<Mode, unknown, undefined | [number, ParserResult<unknown>]>;
|
|
429
468
|
/**
|
|
430
469
|
* Creates a parser that tries each parser in sequence until one succeeds,
|
|
431
470
|
* with custom error message options.
|
|
@@ -434,7 +473,8 @@ declare function or(...parsers: Parser<Mode, unknown, unknown>[]): Parser<Mode,
|
|
|
434
473
|
* @returns A parser that succeeds if any of the input parsers succeed.
|
|
435
474
|
* @since 0.5.0
|
|
436
475
|
*/
|
|
437
|
-
declare function or
|
|
476
|
+
declare function or<const TParsers extends readonly Parser<Mode, unknown, unknown>[]>(...rest: [...parsers: TParsers, options: OrOptions] & OrArityGuard<TParsers>): Parser<CombineModes<{ readonly [K in keyof TParsers]: ExtractMode<TParsers[K]> }>, InferValue<TParsers[number]>, undefined | [number, ParserResult<unknown>]>;
|
|
477
|
+
declare function or<const TParsers extends readonly Parser<Mode, unknown, unknown>[]>(...parsers: TParsers & OrArityGuard<TParsers>): Parser<Mode, unknown, undefined | [number, ParserResult<unknown>]>;
|
|
438
478
|
/**
|
|
439
479
|
* Options for customizing error messages in the {@link longestMatch}
|
|
440
480
|
* combinator.
|
package/dist/parser.cjs
CHANGED
|
@@ -416,14 +416,26 @@ function buildDocPage(parser, context, args) {
|
|
|
416
416
|
}
|
|
417
417
|
const sections = buildingSections;
|
|
418
418
|
const usage = [...require_usage.normalizeUsage(parser.usage)];
|
|
419
|
+
const maybeApplyCommandUsageLine = (term, arg, isLastArg, usageIndex) => {
|
|
420
|
+
if (term?.type !== "command" || term.name !== arg || !isLastArg || term.usageLine == null) return;
|
|
421
|
+
const defaultUsageLine = usage.slice(usageIndex + 1);
|
|
422
|
+
const customUsageLine = typeof term.usageLine === "function" ? term.usageLine(defaultUsageLine) : term.usageLine;
|
|
423
|
+
const normalizedCustomUsageLine = require_usage.normalizeUsage(customUsageLine);
|
|
424
|
+
usage.splice(usageIndex + 1, usage.length - (usageIndex + 1), ...normalizedCustomUsageLine);
|
|
425
|
+
};
|
|
419
426
|
let i = 0;
|
|
420
|
-
for (
|
|
427
|
+
for (let argIndex = 0; argIndex < args.length; argIndex++) {
|
|
428
|
+
const arg = args[argIndex];
|
|
421
429
|
if (i >= usage.length) break;
|
|
422
|
-
|
|
430
|
+
let term = usage[i];
|
|
423
431
|
if (term.type === "exclusive") {
|
|
424
432
|
const found = findCommandInExclusive(term, arg);
|
|
425
|
-
if (found)
|
|
433
|
+
if (found) {
|
|
434
|
+
usage.splice(i, 1, ...found);
|
|
435
|
+
term = usage[i];
|
|
436
|
+
}
|
|
426
437
|
}
|
|
438
|
+
maybeApplyCommandUsageLine(term, arg, argIndex === args.length - 1, i);
|
|
427
439
|
i++;
|
|
428
440
|
}
|
|
429
441
|
return {
|
package/dist/parser.js
CHANGED
|
@@ -416,14 +416,26 @@ function buildDocPage(parser, context, args) {
|
|
|
416
416
|
}
|
|
417
417
|
const sections = buildingSections;
|
|
418
418
|
const usage = [...normalizeUsage(parser.usage)];
|
|
419
|
+
const maybeApplyCommandUsageLine = (term, arg, isLastArg, usageIndex) => {
|
|
420
|
+
if (term?.type !== "command" || term.name !== arg || !isLastArg || term.usageLine == null) return;
|
|
421
|
+
const defaultUsageLine = usage.slice(usageIndex + 1);
|
|
422
|
+
const customUsageLine = typeof term.usageLine === "function" ? term.usageLine(defaultUsageLine) : term.usageLine;
|
|
423
|
+
const normalizedCustomUsageLine = normalizeUsage(customUsageLine);
|
|
424
|
+
usage.splice(usageIndex + 1, usage.length - (usageIndex + 1), ...normalizedCustomUsageLine);
|
|
425
|
+
};
|
|
419
426
|
let i = 0;
|
|
420
|
-
for (
|
|
427
|
+
for (let argIndex = 0; argIndex < args.length; argIndex++) {
|
|
428
|
+
const arg = args[argIndex];
|
|
421
429
|
if (i >= usage.length) break;
|
|
422
|
-
|
|
430
|
+
let term = usage[i];
|
|
423
431
|
if (term.type === "exclusive") {
|
|
424
432
|
const found = findCommandInExclusive(term, arg);
|
|
425
|
-
if (found)
|
|
433
|
+
if (found) {
|
|
434
|
+
usage.splice(i, 1, ...found);
|
|
435
|
+
term = usage[i];
|
|
436
|
+
}
|
|
426
437
|
}
|
|
438
|
+
maybeApplyCommandUsageLine(term, arg, argIndex === args.length - 1, i);
|
|
427
439
|
i++;
|
|
428
440
|
}
|
|
429
441
|
return {
|
package/dist/primitives.cjs
CHANGED
|
@@ -927,6 +927,7 @@ function command(name, parser, options = {}) {
|
|
|
927
927
|
usage: [{
|
|
928
928
|
type: "command",
|
|
929
929
|
name,
|
|
930
|
+
...options.usageLine != null && { usageLine: options.usageLine },
|
|
930
931
|
...options.hidden != null && { hidden: options.hidden }
|
|
931
932
|
}, ...parser.usage],
|
|
932
933
|
initialState: void 0,
|
package/dist/primitives.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Message } from "./message.cjs";
|
|
2
|
-
import { HiddenVisibility, OptionName } from "./usage.cjs";
|
|
2
|
+
import { HiddenVisibility, OptionName, Usage } from "./usage.cjs";
|
|
3
3
|
import { ValueParser, ValueParserResult } from "./valueparser.cjs";
|
|
4
4
|
import { DeferredParseState, PendingDependencySourceState } from "./dependency.cjs";
|
|
5
5
|
import { Mode, Parser } from "./parser.cjs";
|
|
@@ -326,6 +326,19 @@ interface CommandOptions {
|
|
|
326
326
|
* @since 0.6.0
|
|
327
327
|
*/
|
|
328
328
|
readonly footer?: Message;
|
|
329
|
+
/**
|
|
330
|
+
* Usage line override for this command's own help page.
|
|
331
|
+
*
|
|
332
|
+
* This option customizes the usage tail shown when rendering help for this
|
|
333
|
+
* command itself (e.g., `myapp config --help`). It does not change parsing
|
|
334
|
+
* behavior or shell completion.
|
|
335
|
+
*
|
|
336
|
+
* - `Usage`: Replaces the default usage tail.
|
|
337
|
+
* - `(defaultUsageLine) => Usage`: Computes the usage tail from the default.
|
|
338
|
+
*
|
|
339
|
+
* @since 1.0.0
|
|
340
|
+
*/
|
|
341
|
+
readonly usageLine?: Usage | ((defaultUsageLine: Usage) => Usage);
|
|
329
342
|
/**
|
|
330
343
|
* Controls command visibility:
|
|
331
344
|
*
|
package/dist/primitives.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Message } from "./message.js";
|
|
2
|
-
import { HiddenVisibility, OptionName } from "./usage.js";
|
|
2
|
+
import { HiddenVisibility, OptionName, Usage } from "./usage.js";
|
|
3
3
|
import { ValueParser, ValueParserResult } from "./valueparser.js";
|
|
4
4
|
import { DeferredParseState, PendingDependencySourceState } from "./dependency.js";
|
|
5
5
|
import { Mode, Parser } from "./parser.js";
|
|
@@ -326,6 +326,19 @@ interface CommandOptions {
|
|
|
326
326
|
* @since 0.6.0
|
|
327
327
|
*/
|
|
328
328
|
readonly footer?: Message;
|
|
329
|
+
/**
|
|
330
|
+
* Usage line override for this command's own help page.
|
|
331
|
+
*
|
|
332
|
+
* This option customizes the usage tail shown when rendering help for this
|
|
333
|
+
* command itself (e.g., `myapp config --help`). It does not change parsing
|
|
334
|
+
* behavior or shell completion.
|
|
335
|
+
*
|
|
336
|
+
* - `Usage`: Replaces the default usage tail.
|
|
337
|
+
* - `(defaultUsageLine) => Usage`: Computes the usage tail from the default.
|
|
338
|
+
*
|
|
339
|
+
* @since 1.0.0
|
|
340
|
+
*/
|
|
341
|
+
readonly usageLine?: Usage | ((defaultUsageLine: Usage) => Usage);
|
|
329
342
|
/**
|
|
330
343
|
* Controls command visibility:
|
|
331
344
|
*
|
package/dist/primitives.js
CHANGED
|
@@ -927,6 +927,7 @@ function command(name, parser, options = {}) {
|
|
|
927
927
|
usage: [{
|
|
928
928
|
type: "command",
|
|
929
929
|
name,
|
|
930
|
+
...options.usageLine != null && { usageLine: options.usageLine },
|
|
930
931
|
...options.hidden != null && { hidden: options.hidden }
|
|
931
932
|
}, ...parser.usage],
|
|
932
933
|
initialState: void 0,
|
package/dist/usage.cjs
CHANGED
|
@@ -419,6 +419,12 @@ function* formatUsageTermInternal(term, options) {
|
|
|
419
419
|
text: options?.colors ? `\x1b[2m${text}\x1b[0m` : text,
|
|
420
420
|
width: 5
|
|
421
421
|
};
|
|
422
|
+
} else if (term.type === "ellipsis") {
|
|
423
|
+
const text = "...";
|
|
424
|
+
yield {
|
|
425
|
+
text: options?.colors ? `\x1b[2m${text}\x1b[0m` : text,
|
|
426
|
+
width: 3
|
|
427
|
+
};
|
|
422
428
|
} else throw new TypeError(`Unknown usage term type: ${term["type"]}.`);
|
|
423
429
|
}
|
|
424
430
|
|
package/dist/usage.d.cts
CHANGED
|
@@ -98,6 +98,12 @@ type UsageTerm =
|
|
|
98
98
|
* in the command-line usage.
|
|
99
99
|
*/
|
|
100
100
|
readonly name: string;
|
|
101
|
+
/**
|
|
102
|
+
* Optional usage line override for this command's own help page.
|
|
103
|
+
* This affects help/documentation rendering only.
|
|
104
|
+
* @since 1.0.0
|
|
105
|
+
*/
|
|
106
|
+
readonly usageLine?: Usage | ((defaultUsageLine: Usage) => Usage);
|
|
101
107
|
/**
|
|
102
108
|
* Visibility controls for this term.
|
|
103
109
|
* @since 0.9.0
|
|
@@ -181,6 +187,17 @@ type UsageTerm =
|
|
|
181
187
|
* @since 0.9.0
|
|
182
188
|
*/
|
|
183
189
|
readonly hidden?: HiddenVisibility;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* An ellipsis term, which represents a summary placeholder in usage output.
|
|
193
|
+
* Unlike {@link passthrough}, this term has no parsing semantics and is used
|
|
194
|
+
* only for display.
|
|
195
|
+
* @since 1.0.0
|
|
196
|
+
*/ | {
|
|
197
|
+
/**
|
|
198
|
+
* The type of the term, which is always `"ellipsis"` for this term.
|
|
199
|
+
*/
|
|
200
|
+
readonly type: "ellipsis";
|
|
184
201
|
};
|
|
185
202
|
/**
|
|
186
203
|
* Represents a command-line usage description, which is a sequence of
|
package/dist/usage.d.ts
CHANGED
|
@@ -98,6 +98,12 @@ type UsageTerm =
|
|
|
98
98
|
* in the command-line usage.
|
|
99
99
|
*/
|
|
100
100
|
readonly name: string;
|
|
101
|
+
/**
|
|
102
|
+
* Optional usage line override for this command's own help page.
|
|
103
|
+
* This affects help/documentation rendering only.
|
|
104
|
+
* @since 1.0.0
|
|
105
|
+
*/
|
|
106
|
+
readonly usageLine?: Usage | ((defaultUsageLine: Usage) => Usage);
|
|
101
107
|
/**
|
|
102
108
|
* Visibility controls for this term.
|
|
103
109
|
* @since 0.9.0
|
|
@@ -181,6 +187,17 @@ type UsageTerm =
|
|
|
181
187
|
* @since 0.9.0
|
|
182
188
|
*/
|
|
183
189
|
readonly hidden?: HiddenVisibility;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* An ellipsis term, which represents a summary placeholder in usage output.
|
|
193
|
+
* Unlike {@link passthrough}, this term has no parsing semantics and is used
|
|
194
|
+
* only for display.
|
|
195
|
+
* @since 1.0.0
|
|
196
|
+
*/ | {
|
|
197
|
+
/**
|
|
198
|
+
* The type of the term, which is always `"ellipsis"` for this term.
|
|
199
|
+
*/
|
|
200
|
+
readonly type: "ellipsis";
|
|
184
201
|
};
|
|
185
202
|
/**
|
|
186
203
|
* Represents a command-line usage description, which is a sequence of
|
package/dist/usage.js
CHANGED
|
@@ -418,6 +418,12 @@ function* formatUsageTermInternal(term, options) {
|
|
|
418
418
|
text: options?.colors ? `\x1b[2m${text}\x1b[0m` : text,
|
|
419
419
|
width: 5
|
|
420
420
|
};
|
|
421
|
+
} else if (term.type === "ellipsis") {
|
|
422
|
+
const text = "...";
|
|
423
|
+
yield {
|
|
424
|
+
text: options?.colors ? `\x1b[2m${text}\x1b[0m` : text,
|
|
425
|
+
width: 3
|
|
426
|
+
};
|
|
421
427
|
} else throw new TypeError(`Unknown usage term type: ${term["type"]}.`);
|
|
422
428
|
}
|
|
423
429
|
|