Merge pull request #21626 from chaosmail/update-parsimmon-1.6.2

Parsimmon: add createLanguage, Parser.trim and Parser.thru
This commit is contained in:
Armando Aguirre
2017-12-01 14:39:10 -08:00
committed by GitHub

View File

@@ -1,4 +1,4 @@
// Type definitions for Parsimmon 1.3
// Type definitions for Parsimmon 1.6
// Project: https://github.com/jneen/parsimmon
// Definitions by: Bart van der Schoor <https://github.com/Bartvds>
// Mizunashi Mana <https://github.com/mizunashi-mana>
@@ -74,6 +74,14 @@ declare namespace Parsimmon {
index: Index;
}
interface Rule {
[key: string]: (r?: Language) => Parser<any>;
}
interface Language {
[key: string]: Parser<any>;
}
interface Parser<T> {
/**
* parse the string
@@ -106,6 +114,15 @@ declare namespace Parsimmon {
*/
// tslint:disable-next-line:unified-signatures
then<U>(anotherParser: Parser<U>): Parser<U>;
/**
* returns wrapper(this) from the parser. Useful for custom functions used
* to wrap your parsers, while keeping with Parsimmon chaining style.
*/
thru<U>(call: (wrapper: Parser<U>) => Parser<T>): Parser<T>;
/**
* expects anotherParser before and after parser, yielding the result of parser
*/
trim<U>(anotherParser: Parser<U>): Parser<T>;
/**
* transforms the output of parser with the given function.
*/
@@ -171,6 +188,11 @@ declare namespace Parsimmon {
*/
function Parser<T>(fn: (input: string, i: number) => Parsimmon.Reply<T>): Parser<T>;
/**
* Starting point for building a language parser in Parsimmon
*/
function createLanguage(rules: Rule): Language;
/**
* To be used inside of Parsimmon(fn). Generates an object describing how
* far the successful parse went (index), and what value it created doing