mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
add custom type on parsimmon
Reference: https://github.com/jneen/parsimmon#adding-base-parsers
This commit is contained in:
@@ -110,6 +110,9 @@ fooPar = P.succeed(foo);
|
||||
fooArrPar = P.seq(fooPar, fooPar);
|
||||
anyArrPar = P.seq(barPar, fooPar, numPar);
|
||||
|
||||
fooPar = P.custom<Foo>((success, failure) => (stream, i) => { str = stream; num = i; return success(num, foo); });
|
||||
fooPar = P.custom<Foo>((success, failure) => (stream, i) => failure(num, str));
|
||||
|
||||
fooPar = P.alt(fooPar, fooPar);
|
||||
anyPar = P.alt(barPar, fooPar, numPar);
|
||||
|
||||
|
||||
Vendored
+11
-1
@@ -1,12 +1,14 @@
|
||||
// Type definitions for Parsimmon 0.5.0
|
||||
// Project: https://github.com/jneen/parsimmon
|
||||
// Definitions by: Bart van der Schoor <https://github.com/Bartvds>
|
||||
// Definitions by: Bart van der Schoor <https://github.com/Bartvds>, Mizunashi Mana <https://github.com/mizunashi-mana>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
// TODO convert to generics
|
||||
|
||||
declare module 'parsimmon' {
|
||||
module Parsimmon {
|
||||
|
||||
export type StreamType = string;
|
||||
|
||||
export interface Mark<T> {
|
||||
start: number;
|
||||
@@ -103,6 +105,14 @@ declare module 'parsimmon' {
|
||||
export function seq<U>(...parsers: Parser<U>[]): Parser<U[]>;
|
||||
export function seq(...parsers: Parser<any>[]): Parser<any[]>;
|
||||
|
||||
export type successFunctionType<U> = (index: number, result: U) => Result<U>;
|
||||
export type failureFunctionType<U> = (index: number, msg: string) => Result<U>;
|
||||
export type parseFunctionType<U> = (stream: StreamType, index: number) => Result<U>;
|
||||
/*
|
||||
allows to add custom primitive parsers.
|
||||
*/
|
||||
export function custom<U>(parsingFunction: (success: successFunctionType<U>, failure: failureFunctionType<U>) => parseFunctionType<U>): Parser<U>;
|
||||
|
||||
/*
|
||||
accepts a variable number of parsers, and yields the value of the first one that succeeds, backtracking in between.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user