@@ -205,52 +205,52 @@ export class Scanner {
205
205
206
206
const ch = this . _advance ( ) ;
207
207
switch ( ch ) {
208
- case '(' : this . _addToken ( TokenType . LParen ) ; break ;
209
- case ')' : this . _addToken ( TokenType . RParen ) ; break ;
208
+ case CharCode . OpenParen : this . _addToken ( TokenType . LParen ) ; break ;
209
+ case CharCode . CloseParen : this . _addToken ( TokenType . RParen ) ; break ;
210
210
211
- case '!' :
212
- this . _addToken ( this . _match ( '=' ) ? TokenType . NotEq : TokenType . Neg ) ;
211
+ case CharCode . ExclamationMark :
212
+ this . _addToken ( this . _match ( CharCode . Equals ) ? TokenType . NotEq : TokenType . Neg ) ;
213
213
break ;
214
214
215
- case '\'' : this . _quotedString ( ) ; break ;
216
- case '/' : this . _regex ( ) ; break ;
215
+ case CharCode . SingleQuote : this . _quotedString ( ) ; break ;
216
+ case CharCode . Slash : this . _regex ( ) ; break ;
217
217
218
- case '=' :
219
- if ( this . _match ( '=' ) ) { // support `==`
218
+ case CharCode . Equals :
219
+ if ( this . _match ( CharCode . Equals ) ) { // support `==`
220
220
this . _addToken ( TokenType . Eq ) ;
221
- } else if ( this . _match ( '~' ) ) {
221
+ } else if ( this . _match ( CharCode . Tilde ) ) {
222
222
this . _addToken ( TokenType . RegexOp ) ;
223
223
} else {
224
224
this . _error ( ) ;
225
225
}
226
226
break ;
227
227
228
- case '<' : this . _addToken ( this . _match ( '=' ) ? TokenType . LtEq : TokenType . Lt ) ; break ;
228
+ case CharCode . LessThan : this . _addToken ( this . _match ( CharCode . Equals ) ? TokenType . LtEq : TokenType . Lt ) ; break ;
229
229
230
- case '>' : this . _addToken ( this . _match ( '=' ) ? TokenType . GtEq : TokenType . Gt ) ; break ;
230
+ case CharCode . GreaterThan : this . _addToken ( this . _match ( CharCode . Equals ) ? TokenType . GtEq : TokenType . Gt ) ; break ;
231
231
232
- case '&' :
233
- if ( this . _match ( '&' ) ) {
232
+ case CharCode . Ampersand :
233
+ if ( this . _match ( CharCode . Ampersand ) ) {
234
234
this . _addToken ( TokenType . And ) ;
235
235
} else {
236
236
this . _error ( ) ;
237
237
}
238
238
break ;
239
239
240
- case '|' :
241
- if ( this . _match ( '|' ) ) {
240
+ case CharCode . Pipe :
241
+ if ( this . _match ( CharCode . Pipe ) ) {
242
242
this . _addToken ( TokenType . Or ) ;
243
243
} else {
244
244
this . _error ( ) ;
245
245
}
246
246
break ;
247
247
248
248
// TODO@ulugbekna : 1) I don't think we need to handle whitespace here, 2) if we do, we should reconsider what characters we consider whitespace, including unicode, nbsp, etc.
249
- case ' ' :
250
- case '\r' :
251
- case '\t' :
252
- case '\n' :
253
- case '\u00A0' : //  
249
+ case CharCode . Space :
250
+ case CharCode . CarriageReturn :
251
+ case CharCode . Tab :
252
+ case CharCode . LineFeed :
253
+ case CharCode . NoBreakSpace : //  
254
254
break ;
255
255
256
256
default :
@@ -264,23 +264,23 @@ export class Scanner {
264
264
return Array . from ( this . _tokens ) ;
265
265
}
266
266
267
- private _match ( expected : string ) : boolean {
267
+ private _match ( expected : number ) : boolean {
268
268
if ( this . _isAtEnd ( ) ) {
269
269
return false ;
270
270
}
271
- if ( this . _input [ this . _current ] !== expected ) {
271
+ if ( this . _input . charCodeAt ( this . _current ) !== expected ) {
272
272
return false ;
273
273
}
274
274
this . _current ++ ;
275
275
return true ;
276
276
}
277
277
278
- private _advance ( ) : string {
279
- return this . _input [ this . _current ++ ] ;
278
+ private _advance ( ) : number {
279
+ return this . _input . charCodeAt ( this . _current ++ ) ;
280
280
}
281
281
282
- private _peek ( ) : string {
283
- return this . _isAtEnd ( ) ? '\0' : this . _input [ this . _current ] ;
282
+ private _peek ( ) : number {
283
+ return this . _isAtEnd ( ) ? CharCode . Null : this . _input . charCodeAt ( this . _current ) ;
284
284
}
285
285
286
286
private _addToken ( type : TokenTypeWithoutLexeme ) {
@@ -312,7 +312,7 @@ export class Scanner {
312
312
313
313
// captures the lexeme without the leading and trailing '
314
314
private _quotedString ( ) {
315
- while ( this . _peek ( ) !== `'` && ! this . _isAtEnd ( ) ) { // TODO@ulugbekna : add support for escaping ' ?
315
+ while ( this . _peek ( ) !== CharCode . SingleQuote && ! this . _isAtEnd ( ) ) { // TODO@ulugbekna : add support for escaping ' ?
316
316
this . _advance ( ) ;
317
317
}
318
318
0 commit comments