From 97ac17135aa2537069bcb969453c2bc821ef9ccb Mon Sep 17 00:00:00 2001 From: Paul Huynh Date: Sat, 11 Aug 2018 12:03:53 +1000 Subject: [PATCH] Allow rules to consist of an array of sub-rules --- types/moo/index.d.ts | 2 +- types/moo/moo-tests.ts | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/types/moo/index.d.ts b/types/moo/index.d.ts index 9cf67c3299..fa3a59d2ab 100644 --- a/types/moo/index.d.ts +++ b/types/moo/index.d.ts @@ -50,7 +50,7 @@ export interface Rule { }; } export interface Rules { - [x: string]: RegExp | string | string[] | Rule; + [x: string]: RegExp | string | string[] | Rule | Rule[]; } export interface Lexer { diff --git a/types/moo/moo-tests.ts b/types/moo/moo-tests.ts index 6f0c18ae2d..c82bedd219 100644 --- a/types/moo/moo-tests.ts +++ b/types/moo/moo-tests.ts @@ -75,3 +75,13 @@ lexer.next(); lexer.next(); lexer.reset('a different line\n', info); lexer.next(); + +// Transform: https://github.com/no-context/moo#transform +moo.compile({ + STRING: [ + { match: /"""[^]*?"""/, lineBreaks: true, value: x => x.slice(3, -3) }, + { match: /"(?:\\["\\rn]|[^"\\])*?"/, lineBreaks: true, value: x => x.slice(1, -1) }, + { match: /'(?:\\['\\rn]|[^'\\])*?'/, lineBreaks: true, value: x => x.slice(1, -1) }, + ], + // ... +});