Merge pull request #2351 from Bartvds/def/parsimmon

updated parsimmon to v0.5.0
This commit is contained in:
Bart van der Schoor
2014-06-16 04:28:30 +02:00
2 changed files with 22 additions and 4 deletions

View File

@@ -3,6 +3,7 @@
import P = require('parsimmon');
import Parser = P.Parser;
import Mark = P.Mark;
import Result = P.Result;
// -- -- -- -- -- -- -- -- -- -- -- -- --
@@ -17,6 +18,7 @@ class Bar {
// -- -- -- -- -- -- -- -- -- -- -- -- --
var str: string;
var bool: boolean;
var num: number;
var regex: RegExp;
@@ -50,7 +52,16 @@ var fooMarkPar: Parser<Mark<Foo>>;
// -- -- -- -- -- -- -- -- -- -- -- -- --
foo = fooPar.parse(str);
var fooResult: Result<Foo>;
bool = fooResult.status;
foo = fooResult.value;
str = fooResult.expected;
num = fooResult.index;
// -- -- -- -- -- -- -- -- -- -- -- -- --
fooResult = fooPar.parse(str);
fooPar = fooPar.or(fooPar);
anyPar = fooPar.or(barPar);

View File

@@ -1,5 +1,5 @@
// Type definitions for Parsimmon 0.4.0
// Project: https://github.com/jayferd/parsimmon
// Type definitions for Parsimmon 0.5.0
// Project: https://github.com/jneen/parsimmon
// Definitions by: Bart van der Schoor <https://github.com/Bartvds>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
@@ -14,11 +14,18 @@ declare module 'parsimmon' {
value: T;
}
export interface Result<T> {
status: boolean;
value?: T;
expected?: string;
index?: number;
}
export interface Parser<T> {
/*
parse the string
*/
parse(input: string): T;
parse(input: string): Result<T>;
/*
returns a new parser which tries parser, and if it fails uses otherParser.
*/