Add tests for createLanguage and fix Rule

This commit is contained in:
Benny van Reeven
2017-12-09 17:05:11 +01:00
parent f9388a931a
commit 4e800c3dc5
2 changed files with 16 additions and 3 deletions
+2 -2
View File
@@ -6,7 +6,7 @@
// Benny van Reeven <https://github.com/bvanreeven>
// Leonard Thieu <https://github.com/leonard-thieu>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
// TypeScript Version: 2.2
/**
* **NOTE:** You probably will never need to use this function. Most parsing
@@ -75,7 +75,7 @@ declare namespace Parsimmon {
}
interface Rule {
[key: string]: (r?: Language) => Parser<any>;
[key: string]: (r: Language) => Parser<any>;
}
interface Language {
+14 -1
View File
@@ -1,5 +1,5 @@
import P = require('parsimmon');
import { Parser, Mark, Result, Index, Reply } from "parsimmon";
import { Parser, Mark, Result, Index, Reply, Language } from "parsimmon";
// -- -- -- -- -- -- -- -- -- -- -- -- --
@@ -191,3 +191,16 @@ strArrPar = P.sepBy1(P.string('foo'), P.string('bar'));
strPar = P.test((a: string) => false);
strPar = P.takeWhile((a: string) => true);
// -- -- -- -- -- -- -- -- -- -- -- -- --
let language: Language;
language = P.createLanguage({
SomeRule: r => P.alt(P.string(""), r.AnotherRule),
AnotherRule: () => P.string(""),
});
anyPar = language.SomeRule;
anyPar = language.AnotherRule;
anyPar = language.UndefinedRule;