mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-10 22:44:43 +08:00
Add fallback and simplify or
This commit is contained in:
15
parsimmon/index.d.ts
vendored
15
parsimmon/index.d.ts
vendored
@@ -83,8 +83,7 @@ declare namespace Parsimmon {
|
||||
/**
|
||||
* returns a new parser which tries parser, and if it fails uses otherParser.
|
||||
*/
|
||||
or(otherParser: Parser<T>): Parser<T>;
|
||||
or<U>(otherParser: Parser<U>): Parser<any>;
|
||||
or<U>(otherParser: Parser<U>): Parser<T | U>;
|
||||
/**
|
||||
* returns a new parser which tries parser, and on success calls the given function
|
||||
* with the result of the parse, which is expected to return another parser, which
|
||||
@@ -106,14 +105,18 @@ declare namespace Parsimmon {
|
||||
* transforms the output of parser with the given function.
|
||||
*/
|
||||
map<U>(call: (result: T) => U): Parser<U>;
|
||||
/**
|
||||
* expects otherParser after parser, but preserves the yield value of parser.
|
||||
*/
|
||||
skip<U>(otherParser: Parser<U>): Parser<T>;
|
||||
/**
|
||||
* returns a new parser with the same behavior, but which yields aResult.
|
||||
*/
|
||||
result<U>(aResult: U): Parser<U>;
|
||||
/**
|
||||
* returns a new parser that returns the fallback value if the first parser failed.
|
||||
*/
|
||||
fallback<U>(fallbackValue: U): Parser<T | U>;
|
||||
/**
|
||||
* expects otherParser after parser, but preserves the yield value of parser.
|
||||
*/
|
||||
skip<U>(otherParser: Parser<U>): Parser<T>;
|
||||
/**
|
||||
* expects parser zero or more times, and yields an array of the results.
|
||||
*/
|
||||
|
||||
@@ -38,6 +38,7 @@ var indexPar: Parser<Index>;
|
||||
|
||||
var fooPar: Parser<Foo>;
|
||||
var barPar: Parser<Bar>;
|
||||
var fooOrBarPar: Parser<Foo | Bar>;
|
||||
|
||||
// -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
|
||||
@@ -84,7 +85,7 @@ fooResult = fooPar.parse(str);
|
||||
foo = fooPar.tryParse(str);
|
||||
|
||||
fooPar = fooPar.or(fooPar);
|
||||
anyPar = fooPar.or(barPar);
|
||||
fooOrBarPar = fooPar.or(barPar);
|
||||
|
||||
barPar = fooPar.chain((f) => {
|
||||
foo = f;
|
||||
@@ -108,6 +109,8 @@ fooPar = fooPar.skip(barPar);
|
||||
|
||||
barPar = barPar = fooPar.result(bar);
|
||||
|
||||
fooOrBarPar = fooPar.fallback(bar);
|
||||
|
||||
// -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
|
||||
fooArrPar = fooPar.many();
|
||||
|
||||
Reference in New Issue
Block a user