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

Class TokenStream

src/parser/streams/token-stream.ts:54–145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52 * トークン列からトークンを読み取るクラス
53*/
54export class TokenStream implements ITokenStream {
55 private source: Token[];
56 private index: number;
57 private _token: Token;
58
59 constructor(source: TokenStream['source']) {
60 this.source = source;
61 this.index = 0;
62 this.load();
63 }
64
65 private get eof(): boolean {
66 return (this.index >= this.source.length);
67 }
68
69 /**
70 * カーソル位置にあるトークンを取得します。
71 */
72 public getToken(): Token {
73 if (this.eof) {
74 return TOKEN(TokenKind.EOF, { line: -1, column: -1 });
75 }
76 return this._token;
77 }
78
79 /**
80 * カーソル位置にあるトークンの種類が指定したトークンの種類と一致するかどうかを示す値を取得します。
81 */
82 public is(kind: TokenKind): boolean {
83 return this.getTokenKind() === kind;
84 }
85
86 /**
87 * カーソル位置にあるトークンに含まれる値を取得します。
88 */
89 public getTokenValue(): string {
90 return this.getToken().value!;
91 }
92
93 /**
94 * カーソル位置にあるトークンの種類を取得します。
95 */
96 public getTokenKind(): TokenKind {
97 return this.getToken().kind;
98 }
99
100 /**
101 * カーソル位置にあるトークンの位置情報を取得します。
102 */
103 public getPos(): TokenPosition {
104 return this.getToken().pos;
105 }
106
107 /**
108 * カーソル位置を次のトークンへ進めます。
109 */
110 public next(): void {
111 if (!this.eof) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected