@@ -8,11 +8,11 @@ export interface Token<T = TokenType, V = string> {
8
8
}
9
9
10
10
// Checks for WGSL-specific `fn foo(`, `var bar =`, `let baz =`, `const qux =`
11
- const isWGSL = /* @__PURE__ */ RegExp . prototype . test . bind ( / \b f n \s + \w + \s * \( | \b ( v a r | l e t | c o n s t ) \s + \w + \s * [: = ] / )
11
+ const WGSL_REGEX = / \b f n \s + \w + \s * \( | \b ( v a r | l e t | c o n s t ) \s + \w + \s * [: = ] /
12
12
13
- const isFloat = /* @__PURE__ */ RegExp . prototype . test . bind ( / ^ ( \d + \. \d * | \d * \. \d + ) ( [ e E p P ] [ - + ] ? \d + ) ? [ f F h H ] ? $ / )
14
- const isInt = /* @__PURE__ */ RegExp . prototype . test . bind ( / ^ ( 0 [ x X ] [ \w \d ] + | \d + ) [ i I u U ] ? $ / )
15
- const isBool = /* @__PURE__ */ RegExp . prototype . test . bind ( / ^ ( t r u e | f a l s e ) $ / )
13
+ const FLOAT_REGEX = / ^ ( \d + \. \d * | \d * \. \d + ) ( [ e E p P ] [ - + ] ? \d + ) ? [ f F h H ] ? $ /
14
+ const INT_REGEX = / ^ ( 0 [ x X ] [ \w \d ] + | \d + ) [ i I u U ] ? $ /
15
+ const BOOL_REGEX = / ^ ( t r u e | f a l s e ) $ /
16
16
17
17
const ZERO = 48
18
18
const NINE = 57
@@ -43,7 +43,7 @@ export function tokenize(code: string, index: number = 0): Token[] {
43
43
const tokens : Token [ ] = [ ]
44
44
45
45
let prev : number = - 1
46
- const [ KEYWORDS , SYMBOLS ] = isWGSL ( code ) ? [ WGSL_KEYWORDS , WGSL_SYMBOLS ] : [ GLSL_KEYWORDS , GLSL_SYMBOLS ]
46
+ const [ KEYWORDS , SYMBOLS ] = WGSL_REGEX . test ( code ) ? [ WGSL_KEYWORDS , WGSL_SYMBOLS ] : [ GLSL_KEYWORDS , GLSL_SYMBOLS ]
47
47
while ( index < code . length ) {
48
48
let value = code [ index ]
49
49
const char = code . charCodeAt ( index ++ )
@@ -52,12 +52,12 @@ export function tokenize(code: string, index: number = 0): Token[] {
52
52
while ( isSpace ( code . charCodeAt ( index ) ) ) value += code [ index ++ ]
53
53
tokens . push ( { type : 'whitespace' , value } )
54
54
} else if ( isDigit ( char ) || ( char === DOT && isDigit ( code . charCodeAt ( index ) ) ) ) {
55
- while ( isFloat ( value + code [ index ] ) || isInt ( value + code [ index ] ) ) value += code [ index ++ ]
56
- if ( isFloat ( value ) ) tokens . push ( { type : 'float' , value } )
55
+ while ( FLOAT_REGEX . test ( value + code [ index ] ) || INT_REGEX . test ( value + code [ index ] ) ) value += code [ index ++ ]
56
+ if ( FLOAT_REGEX . test ( value ) ) tokens . push ( { type : 'float' , value } )
57
57
else tokens . push ( { type : 'int' , value } )
58
58
} else if ( isIdent ( char ) ) {
59
59
while ( isIdent ( code . charCodeAt ( index ) ) ) value += code [ index ++ ]
60
- if ( isBool ( value ) ) tokens . push ( { type : 'bool' , value } )
60
+ if ( BOOL_REGEX . test ( value ) ) tokens . push ( { type : 'bool' , value } )
61
61
else if ( KEYWORDS . includes ( isMacro ( prev ) ? String . fromCharCode ( prev ) + value : value ) )
62
62
tokens . push ( { type : 'keyword' , value } )
63
63
else tokens . push ( { type : 'identifier' , value } )
0 commit comments