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

Class Scanner

src/parser/scanner.ts:21–742  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19 * 入力文字列からトークンを読み取るクラス
20*/
21export class Scanner implements ITokenStream {
22 private stream: CharStream;
23 private _tokens: Token[] = [];
24
25 constructor(source: string)
26 constructor(stream: CharStream)
27 constructor(x: string | CharStream) {
28 if (typeof x === 'string') {
29 this.stream = new CharStream(x);
30 } else {
31 this.stream = x;
32 }
33 this._tokens.push(this.readToken());
34 }
35
36 /**
37 * カーソル位置にあるトークンを取得します。
38 */
39 public getToken(): Token {
40 return this._tokens[0]!;
41 }
42
43 /**
44 * カーソル位置にあるトークンの種類が指定したトークンの種類と一致するかどうかを示す値を取得します。
45 */
46 public is(kind: TokenKind): boolean {
47 return this.getTokenKind() === kind;
48 }
49
50 /**
51 * カーソル位置にあるトークンの種類を取得します。
52 */
53 public getTokenKind(): TokenKind {
54 return this.getToken().kind;
55 }
56
57 /**
58 * カーソル位置にあるトークンに含まれる値を取得します。
59 */
60 public getTokenValue(): string {
61 return this.getToken().value!;
62 }
63
64 /**
65 * カーソル位置にあるトークンの位置情報を取得します。
66 */
67 public getPos(): TokenPosition {
68 return this.getToken().pos;
69 }
70
71 /**
72 * カーソル位置を次のトークンへ進めます。
73 */
74 public next(): void {
75 // 現在のトークンがEOFだったら次のトークンに進まない
76 if (this._tokens[0]!.kind === TokenKind.EOF) {
77 return;
78 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected