@types/parsimmon
Advanced tools
Comparing version 1.6.0 to 1.6.1
@@ -9,3 +9,3 @@ // Type definitions for Parsimmon 1.6 | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
// TypeScript Version: 2.1 | ||
// TypeScript Version: 2.2 | ||
@@ -79,3 +79,3 @@ /** | ||
interface Rule { | ||
[key: string]: (r?: Language) => Parser<any>; | ||
[key: string]: (r: Language) => Parser<any>; | ||
} | ||
@@ -87,2 +87,10 @@ | ||
type TypedRule<TLanguageSpec> = { | ||
[P in keyof TLanguageSpec]: (r: TypedLanguage<TLanguageSpec>) => Parser<TLanguageSpec[P]>; | ||
}; | ||
type TypedLanguage<TLanguageSpec> = { | ||
[P in keyof TLanguageSpec]: Parser<TLanguageSpec[P]>; | ||
}; | ||
interface Parser<T> { | ||
@@ -195,5 +203,47 @@ /** | ||
/** | ||
* Starting point for building a language parser in Parsimmon | ||
* Starting point for building a language parser in Parsimmon. | ||
* | ||
* For having the resulting language rules return typed parsers, e.g. `Parser<Foo>` instead of | ||
* `Parser<any>`, pass a language specification as type parameter to this function. The language | ||
* specification should be of the following form: | ||
* | ||
* ```javascript | ||
* { | ||
* rule1: type; | ||
* rule2: type; | ||
* } | ||
* ``` | ||
* | ||
* For example: | ||
* | ||
* ```javascript | ||
* const language = Parsimmon.createLanguage<{ | ||
* expr: Expr; | ||
* numberLiteral: number; | ||
* stringLiteral: string; | ||
* }>({ | ||
* expr: r => (some expression that yields Parser<Expr>), | ||
* numberLiteral: r => (some expression that yields Parser<number>), | ||
* stringLiteral: r => (some expression that yields Parser<string>) | ||
* }); | ||
* ``` | ||
* | ||
* Now both `language` and the parameter `r` that is passed into every parser rule will be of the | ||
* following type: | ||
* | ||
* ```javascript | ||
* { | ||
* expr: Parser<Expr>; | ||
* numberLiteral: Parser<number>; | ||
* stringLiteral: Parser<string>; | ||
* } | ||
* ``` | ||
* | ||
* Another benefit is that both the `rules` parameter and the resulting `language` should match the | ||
* properties defined in the language specification type, which means that the compiler checks that | ||
* there are no missing or superfluous rules in the language definition, and that the rules you access | ||
* on the resulting language do actually exist. | ||
*/ | ||
function createLanguage(rules: Rule): Language; | ||
function createLanguage<TLanguageSpec>(rules: TypedRule<TLanguageSpec>): TypedLanguage<TLanguageSpec>; | ||
@@ -200,0 +250,0 @@ /** |
{ | ||
"name": "@types/parsimmon", | ||
"version": "1.6.0", | ||
"version": "1.6.1", | ||
"description": "TypeScript definitions for Parsimmon", | ||
@@ -40,4 +40,4 @@ "license": "MIT", | ||
"dependencies": {}, | ||
"typesPublisherContentHash": "3c10c93564d49d9a8441778d412623e33d05380cf8cdf32e27195b8f8ba69ce5", | ||
"typeScriptVersion": "2.1" | ||
"typesPublisherContentHash": "dfc07124d92dc7282c636417e97b996b4dd8706bd0a6b134d5ae8f2349c16a08", | ||
"typeScriptVersion": "2.2" | ||
} |
@@ -11,3 +11,3 @@ # Installation | ||
Additional Details | ||
* Last updated: Sun, 03 Dec 2017 16:31:01 GMT | ||
* Last updated: Mon, 11 Dec 2017 19:14:19 GMT | ||
* Dependencies: none | ||
@@ -14,0 +14,0 @@ * Global values: none |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19077
416