mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-24 05:06:02 +08:00
[parsimmon] Update type definitions (#16790)
* Update type definitions for parsimmon. * dtslint bug workaround.
This commit is contained in:
committed by
Mohamed Hegazy
parent
2586975b36
commit
88f8173559
29
types/parsimmon/index.d.ts
vendored
29
types/parsimmon/index.d.ts
vendored
@@ -1,10 +1,12 @@
|
||||
// Type definitions for Parsimmon 1.0
|
||||
// Type definitions for Parsimmon 1.3
|
||||
// Project: https://github.com/jneen/parsimmon
|
||||
// Definitions by: Bart van der Schoor <https://github.com/Bartvds>
|
||||
// Mizunashi Mana <https://github.com/mizunashi-mana>
|
||||
// Boris Cherny <https://github.com/bcherny>
|
||||
// Benny van Reeven <https://github.com/bvanreeven>
|
||||
// Leonard Thieu <https://github.com/leonard-thieu>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.1
|
||||
|
||||
/**
|
||||
* **NOTE:** You probably will never need to use this function. Most parsing
|
||||
@@ -120,6 +122,18 @@ declare namespace Parsimmon {
|
||||
* expects otherParser after parser, but preserves the yield value of parser.
|
||||
*/
|
||||
skip<U>(otherParser: Parser<U>): Parser<T>;
|
||||
/**
|
||||
* Returns a parser that looks for anything but whatever anotherParser wants to
|
||||
* parse, and does not consume it. Yields the same result as parser. Equivalent to
|
||||
* parser.skip(Parsimmon.notFollowedBy(anotherParser)).
|
||||
*/
|
||||
notFollowedBy(anotherParser: Parser<any>): Parser<T>;
|
||||
/**
|
||||
* Returns a parser that looks for whatever arg wants to parse, but does not
|
||||
* consume it. Yields the same result as parser. Equivalent to
|
||||
* parser.skip(Parsimmon.lookahead(anotherParser)).
|
||||
*/
|
||||
lookahead(arg: Parser<any> | string | RegExp): Parser<T>;
|
||||
/**
|
||||
* expects parser zero or more times, and yields an array of the results.
|
||||
*/
|
||||
@@ -174,7 +188,7 @@ declare namespace Parsimmon {
|
||||
/**
|
||||
* Returns true if obj is a Parsimmon parser, otherwise false.
|
||||
*/
|
||||
function isParser(obj: any): boolean;
|
||||
function isParser(obj: any): obj is Parser<any>;
|
||||
|
||||
/**
|
||||
* is a parser that expects to find "my-string", and will yield the same.
|
||||
@@ -204,6 +218,17 @@ declare namespace Parsimmon {
|
||||
*/
|
||||
function regex(myregex: RegExp, group?: number): Parser<string>;
|
||||
|
||||
/**
|
||||
* Parses using parser, but does not consume what it parses. Yields null if the parser
|
||||
* does not match the input. Otherwise it fails.
|
||||
*/
|
||||
function notFollowedBy(parser: Parser<any>): Parser<null>;
|
||||
|
||||
/**
|
||||
* Parses using arg, but does not consume what it parses. Yields an empty string.
|
||||
*/
|
||||
function lookahead(arg: Parser<any> | string | RegExp): Parser<''>;
|
||||
|
||||
/**
|
||||
* Returns a parser that doesn't consume any of the string, and yields result.
|
||||
*/
|
||||
|
||||
@@ -28,6 +28,8 @@ let strPar: Parser<string>;
|
||||
let numPar: Parser<number>;
|
||||
let voidPar: Parser<void>;
|
||||
let anyPar: Parser<any>;
|
||||
let nullPar: Parser<null>;
|
||||
let emptyStrPar: Parser<''>;
|
||||
let indexPar: Parser<Index>;
|
||||
|
||||
let fooPar: Parser<Foo>;
|
||||
@@ -168,6 +170,11 @@ strPar = P.regex(/foo/, 3);
|
||||
strPar = P.regexp(/bar/);
|
||||
strPar = P.regexp(/bar/, 3);
|
||||
|
||||
nullPar = P.notFollowedBy(fooPar);
|
||||
emptyStrPar = P.lookahead(str);
|
||||
emptyStrPar = P.lookahead(/foo/);
|
||||
emptyStrPar = P.lookahead(fooPar);
|
||||
|
||||
fooPar = P.of(foo);
|
||||
|
||||
str = P.formatError('foo', strPar.parse('bar'));
|
||||
|
||||
Reference in New Issue
Block a user