Allow rules to consist of an array of sub-rules

This commit is contained in:
Paul Huynh
2018-08-11 12:03:53 +10:00
parent b3387d6338
commit 97ac17135a
2 changed files with 11 additions and 1 deletions

View File

@@ -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 {

View File

@@ -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) },
],
// ...
});