Skip to content

Commit dea3eb9

Browse files
committed
context keys: scanner: rewrite using char codes
1 parent 97d16e4 commit dea3eb9

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

src/vs/platform/contextkey/common/scanner.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -205,52 +205,52 @@ export class Scanner {
205205

206206
const ch = this._advance();
207207
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;
210210

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);
213213
break;
214214

215-
case '\'': this._quotedString(); break;
216-
case '/': this._regex(); break;
215+
case CharCode.SingleQuote: this._quotedString(); break;
216+
case CharCode.Slash: this._regex(); break;
217217

218-
case '=':
219-
if (this._match('=')) { // support `==`
218+
case CharCode.Equals:
219+
if (this._match(CharCode.Equals)) { // support `==`
220220
this._addToken(TokenType.Eq);
221-
} else if (this._match('~')) {
221+
} else if (this._match(CharCode.Tilde)) {
222222
this._addToken(TokenType.RegexOp);
223223
} else {
224224
this._error();
225225
}
226226
break;
227227

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;
229229

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;
231231

232-
case '&':
233-
if (this._match('&')) {
232+
case CharCode.Ampersand:
233+
if (this._match(CharCode.Ampersand)) {
234234
this._addToken(TokenType.And);
235235
} else {
236236
this._error();
237237
}
238238
break;
239239

240-
case '|':
241-
if (this._match('|')) {
240+
case CharCode.Pipe:
241+
if (this._match(CharCode.Pipe)) {
242242
this._addToken(TokenType.Or);
243243
} else {
244244
this._error();
245245
}
246246
break;
247247

248248
// 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': // &nbsp
249+
case CharCode.Space:
250+
case CharCode.CarriageReturn:
251+
case CharCode.Tab:
252+
case CharCode.LineFeed:
253+
case CharCode.NoBreakSpace: // &nbsp
254254
break;
255255

256256
default:
@@ -264,23 +264,23 @@ export class Scanner {
264264
return Array.from(this._tokens);
265265
}
266266

267-
private _match(expected: string): boolean {
267+
private _match(expected: number): boolean {
268268
if (this._isAtEnd()) {
269269
return false;
270270
}
271-
if (this._input[this._current] !== expected) {
271+
if (this._input.charCodeAt(this._current) !== expected) {
272272
return false;
273273
}
274274
this._current++;
275275
return true;
276276
}
277277

278-
private _advance(): string {
279-
return this._input[this._current++];
278+
private _advance(): number {
279+
return this._input.charCodeAt(this._current++);
280280
}
281281

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);
284284
}
285285

286286
private _addToken(type: TokenTypeWithoutLexeme) {
@@ -312,7 +312,7 @@ export class Scanner {
312312

313313
// captures the lexeme without the leading and trailing '
314314
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 ' ?
316316
this._advance();
317317
}
318318

0 commit comments

Comments
 (0)