mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-06 07:47:04 +00:00
Merge pull request #32574 from akshaykarthik/moo-0.5
[moo 0.5] Add type definitions for keywords value transform
This commit is contained in:
Vendored
+15
-4
@@ -1,4 +1,4 @@
|
||||
// Type definitions for moo 0.4
|
||||
// Type definitions for moo 0.5
|
||||
// Project: https://github.com/tjvr/moo#readme
|
||||
// Definitions by: Nikita Litvin <https://github.com/deltaidea>
|
||||
// Jörg Vehlow <https://github.com/MofX>
|
||||
@@ -11,6 +11,15 @@ export as namespace moo;
|
||||
*/
|
||||
export const error: { error: true };
|
||||
|
||||
/**
|
||||
* Reserved token for indicating a fallback rule.
|
||||
*/
|
||||
export const fallback: { fallback: true };
|
||||
|
||||
export type TypeMapper = (x: string) => string;
|
||||
|
||||
export function keywords(kws: {[k: string]: string | string[]}): TypeMapper;
|
||||
|
||||
export function compile(rules: Rules): Lexer;
|
||||
|
||||
export function states(states: {[x: string]: Rules}, start?: string): Lexer;
|
||||
@@ -45,9 +54,11 @@ export interface Rule {
|
||||
*/
|
||||
value?: (x: string) => string;
|
||||
|
||||
keywords?: {
|
||||
[x: string]: string | string[]
|
||||
};
|
||||
/**
|
||||
* Used for mapping one set of types to another.
|
||||
* See https://github.com/no-context/moo#keywords for an example
|
||||
*/
|
||||
type?: TypeMapper;
|
||||
}
|
||||
export interface Rules {
|
||||
[x: string]: RegExp | string | string[] | Rule | Rule[];
|
||||
|
||||
@@ -20,20 +20,21 @@ lexer = moo.compile({
|
||||
|
||||
lexer = moo.compile({
|
||||
IDEN: {
|
||||
match: /[a-zA-Z]+/, keywords: {
|
||||
match: /[a-zA-Z]+/,
|
||||
type: moo.keywords({
|
||||
KW: ['while', 'if', 'else', 'moo', 'reloacows']
|
||||
}
|
||||
})
|
||||
},
|
||||
SPACE: { match: /\s+/, lineBreaks: true }
|
||||
});
|
||||
|
||||
lexer = moo.compile({
|
||||
name: {
|
||||
match: /[a-zA-Z]+/, keywords: {
|
||||
match: /[a-zA-Z]+/, type: moo.keywords({
|
||||
'kw-class': 'class',
|
||||
'kw-def': 'def',
|
||||
'kw-if': 'if',
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user