@@ -13,11 +13,22 @@ import { TrieNode } from "../utils/utils.js";
13
13
14
14
/* Lexer */
15
15
export class Lexer {
16
+ /* Properties */
16
17
private readonly code : string ;
17
18
private readonly tokens : Token . Token [ ] ;
18
19
private curPos : number ;
19
20
private curChar : string ;
20
21
22
+ /* Properties for constants */
23
+ public CONSTANT_KEYWORDS = CONSTANT_KEYWORDS ;
24
+ public KEYWORDS = KEYWORDS ;
25
+ public OPERATOR_KEYWORDS = OPERATOR_KEYWORDS ;
26
+ public OPERATOR_TRIE = OPERATOR_TRIE ;
27
+ public SPECIAL_CHARS_MAP = SPECIAL_CHARS_MAP ;
28
+ public TOKENIZER_ESCAPED_CHARACTER_CONVERSIONS =
29
+ TOKENIZER_ESCAPED_CHARACTER_CONVERSIONS ;
30
+ public VALID_CHARACTERS = VALID_CHARACTERS ;
31
+
21
32
/* Constructor */
22
33
constructor ( code : string ) {
23
34
this . code = code ;
@@ -49,7 +60,7 @@ export class Lexer {
49
60
}
50
61
private throwUnexpectedCharacterError ( expected : string ) : never {
51
62
const convertedCurrentChar =
52
- SPECIAL_CHARS_MAP [ this . curChar ] ?? this . curChar ;
63
+ this . SPECIAL_CHARS_MAP [ this . curChar ] ?? this . curChar ;
53
64
Lexer . throwError (
54
65
`Unexpected character '${ convertedCurrentChar } ', expected '${ expected } '` ,
55
66
) ;
@@ -132,7 +143,7 @@ export class Lexer {
132
143
// Checks if the next character sequence is an operator,
133
144
// if so, consumes it and returns the operator string.
134
145
private consumeOperatorIfPossible ( ) : string | false {
135
- let node : TrieNode = OPERATOR_TRIE ;
146
+ let node : TrieNode = this . OPERATOR_TRIE ;
136
147
let operator : string | undefined ;
137
148
138
149
const currentCharPos = this . curPos ;
@@ -255,7 +266,7 @@ export class Lexer {
255
266
if ( this . curChar === "\\" ) {
256
267
this . advance ( 1 ) ; // Skip the "\"
257
268
const escapedChar =
258
- TOKENIZER_ESCAPED_CHARACTER_CONVERSIONS [ this . curChar ] ;
269
+ this . TOKENIZER_ESCAPED_CHARACTER_CONVERSIONS [ this . curChar ] ;
259
270
if ( escapedChar ) {
260
271
string += escapedChar ;
261
272
this . advance ( 1 ) ; // Skip the escaped character
@@ -305,11 +316,11 @@ export class Lexer {
305
316
this . consumeWhitespace ( ) ;
306
317
} else if ( Lexer . isIdentifierStart ( currentChar ) ) {
307
318
const identifier = this . consumeIdentifier ( ) ;
308
- if ( OPERATOR_KEYWORDS . has ( identifier ) ) {
319
+ if ( this . OPERATOR_KEYWORDS . has ( identifier ) ) {
309
320
this . tokens . push ( new Token . OperatorToken ( identifier ) ) ;
310
- } else if ( CONSTANT_KEYWORDS . has ( identifier ) ) {
321
+ } else if ( this . CONSTANT_KEYWORDS . has ( identifier ) ) {
311
322
this . tokens . push ( new Token . ConstantToken ( identifier ) ) ;
312
- } else if ( KEYWORDS . has ( identifier ) ) {
323
+ } else if ( this . KEYWORDS . has ( identifier ) ) {
313
324
this . tokens . push ( new Token . KeywordToken ( identifier ) ) ;
314
325
} else {
315
326
this . tokens . push ( new Token . IdentifierToken ( identifier ) ) ;
@@ -338,7 +349,7 @@ export class Lexer {
338
349
if ( operator ) {
339
350
this . tokens . push ( new Token . OperatorToken ( operator ) ) ;
340
351
} else {
341
- if ( ! VALID_CHARACTERS . has ( currentChar ) ) {
352
+ if ( ! this . VALID_CHARACTERS . has ( currentChar ) ) {
342
353
Lexer . throwError ( `Invalid character: ${ currentChar } ` ) ;
343
354
}
344
355
// Process it as character
0 commit comments