MCPcopy Create free account
hub / github.com/aiscript-dev/aiscript / tryReadWord

Method tryReadWord

src/parser/scanner.ts:338–432  ·  view source on GitHub ↗
(hasLeftSpacing: boolean)

Source from the content-addressed store, hash-verified

336 }
337
338 private tryReadWord(hasLeftSpacing: boolean): Token | undefined {
339 // read a word
340 if (this.stream.eof) {
341 return;
342 }
343
344 const pos = this.stream.getPos();
345
346 let rawValue = this.tryReadIdentifierStart();
347 if (rawValue === undefined) {
348 return;
349 }
350 while (!(this.stream.eof as boolean)) {
351 const matchedIdentifierPart = this.tryReadIdentifierPart();
352 if (matchedIdentifierPart === undefined) {
353 break;
354 }
355 rawValue += matchedIdentifierPart;
356 }
357
358 const value = decodeUnicodeEscapeSequence(rawValue);
359 if (value !== rawValue) {
360 throw new AiScriptSyntaxError(`Invalid identifier: "${rawValue}"`, pos);
361 }
362
363 // check word kind
364 switch (value) {
365 case 'null': {
366 return TOKEN(TokenKind.NullKeyword, pos, { hasLeftSpacing });
367 }
368 case 'true': {
369 return TOKEN(TokenKind.TrueKeyword, pos, { hasLeftSpacing });
370 }
371 case 'false': {
372 return TOKEN(TokenKind.FalseKeyword, pos, { hasLeftSpacing });
373 }
374 case 'each': {
375 return TOKEN(TokenKind.EachKeyword, pos, { hasLeftSpacing });
376 }
377 case 'for': {
378 return TOKEN(TokenKind.ForKeyword, pos, { hasLeftSpacing });
379 }
380 case 'loop': {
381 return TOKEN(TokenKind.LoopKeyword, pos, { hasLeftSpacing });
382 }
383 case 'do': {
384 return TOKEN(TokenKind.DoKeyword, pos, { hasLeftSpacing });
385 }
386 case 'while': {
387 return TOKEN(TokenKind.WhileKeyword, pos, { hasLeftSpacing });
388 }
389 case 'break': {
390 return TOKEN(TokenKind.BreakKeyword, pos, { hasLeftSpacing });
391 }
392 case 'continue': {
393 return TOKEN(TokenKind.ContinueKeyword, pos, { hasLeftSpacing });
394 }
395 case 'match': {

Callers 1

readTokenMethod · 0.95

Calls 5

tryReadIdentifierPartMethod · 0.95
TOKENFunction · 0.85
getPosMethod · 0.65

Tested by

no test coverage detected