@@ -3,29 +3,51 @@ import { configBrackets } from './bracket';
33import { configComments } from './comment' ;
44import { configNumbers } from './number' ;
55import { configOperators } from './operator' ;
6- import { fallbackRule } from './rules' ;
6+ import { createOrderedStateMap , fallbackRule } from './rules' ;
77import { configStrings } from './string' ;
88import { configSymbols } from './symbol' ;
99import { coerceToken } from './token' ;
10- import type { Lexer , LexerConfig , RegexRule , StatesMap , Token } from './types' ;
10+ import type {
11+ Lexer ,
12+ LexerConfig ,
13+ OrderedStatesMap ,
14+ RegexRule ,
15+ StatesMap ,
16+ Token ,
17+ } from './types' ;
1118
1219export * from './token' ;
1320export * from './types' ;
1421
15- export function configureLexerRules ( lexerConfig : LexerConfig ) : StatesMap {
22+ export function configureLexerRules (
23+ lexerConfig : LexerConfig
24+ ) : OrderedStatesMap {
1625 const whitespace : RegexRule = lexerConfig . joinLines
1726 ? {
1827 t : 'regex' ,
28+ type : 'whitespace' ,
1929 match : new RegExp ( `(?:${ lexerConfig . joinLines } \\r?\\n|[ \\t\\r])+` ) ,
2030 lineBreaks : true ,
31+ chunk : null ,
2132 }
22- : { t : 'regex' , match : / [ \t \r ] + / } ;
33+ : {
34+ t : 'regex' ,
35+ type : 'whitespace' ,
36+ match : / [ \t \r ] + / ,
37+ chunk : null ,
38+ } ;
2339
2440 let result : StatesMap = {
2541 $ : {
2642 whitespace,
27- newline : { t : 'regex' , match : / \r ? \n / , lineBreaks : true } ,
28- _ : fallbackRule ,
43+ newline : {
44+ t : 'regex' ,
45+ type : 'newline' ,
46+ match : / \r ? \n / ,
47+ chunk : null ,
48+ lineBreaks : true ,
49+ } ,
50+ _ : { ...fallbackRule , type : '_' } ,
2951 } ,
3052 } ;
3153
@@ -37,12 +59,14 @@ export function configureLexerRules(lexerConfig: LexerConfig): StatesMap {
3759 result = configBrackets ( result , brackets ) ;
3860 result = configStrings ( result , strings ) ;
3961 result = configNumbers ( result , { match : numbers } ) ;
40- return result ;
62+
63+ const orderedResult = createOrderedStateMap ( result ) ;
64+ return orderedResult ;
4165}
4266
4367export function createLexer ( options : LexerConfig ) : Lexer {
4468 const rules = configureLexerRules ( options ) ;
45- const mooLexer = mooStates ( rules ) ;
69+ const mooLexer = mooStates ( rules as never ) ;
4670
4771 const result : Lexer = {
4872 reset ( input ?: string ) {
0 commit comments