UNPKG

2.56 kBTypeScriptView Raw
1import { Token } from "./parser/tokenizer";
2import { ContextualKeyword } from "./parser/tokenizer/keywords";
3import { TokenType } from "./parser/tokenizer/types";
4export interface TokenProcessorSnapshot {
5 resultCode: string;
6 tokenIndex: number;
7}
8export default class TokenProcessor {
9 readonly code: string;
10 readonly tokens: Array<Token>;
11 readonly isFlowEnabled: boolean;
12 private resultCode;
13 private tokenIndex;
14 constructor(code: string, tokens: Array<Token>, isFlowEnabled: boolean);
15 /**
16 * Make a new TokenProcessor for things like lookahead.
17 */
18 snapshot(): TokenProcessorSnapshot;
19 restoreToSnapshot(snapshot: TokenProcessorSnapshot): void;
20 getResultCodeIndex(): number;
21 reset(): void;
22 matchesContextualAtIndex(index: number, contextualKeyword: ContextualKeyword): boolean;
23 identifierNameAtIndex(index: number): string;
24 identifierName(): string;
25 identifierNameForToken(token: Token): string;
26 stringValueAtIndex(index: number): string;
27 stringValue(): string;
28 stringValueForToken(token: Token): string;
29 matches1AtIndex(index: number, t1: TokenType): boolean;
30 matches2AtIndex(index: number, t1: TokenType, t2: TokenType): boolean;
31 matches3AtIndex(index: number, t1: TokenType, t2: TokenType, t3: TokenType): boolean;
32 matches1(t1: TokenType): boolean;
33 matches2(t1: TokenType, t2: TokenType): boolean;
34 matches3(t1: TokenType, t2: TokenType, t3: TokenType): boolean;
35 matches4(t1: TokenType, t2: TokenType, t3: TokenType, t4: TokenType): boolean;
36 matches5(t1: TokenType, t2: TokenType, t3: TokenType, t4: TokenType, t5: TokenType): boolean;
37 matchesContextual(contextualKeyword: ContextualKeyword): boolean;
38 matchesContextIdAndLabel(type: TokenType, contextId: number): boolean;
39 previousWhitespaceAndComments(): string;
40 replaceToken(newCode: string): void;
41 replaceTokenTrimmingLeftWhitespace(newCode: string): void;
42 removeInitialToken(): void;
43 removeToken(): void;
44 copyExpectedToken(tokenType: TokenType): void;
45 copyToken(): void;
46 copyTokenWithPrefix(prefix: string): void;
47 appendCode(code: string): void;
48 currentToken(): Token;
49 currentTokenCode(): string;
50 tokenAtRelativeIndex(relativeIndex: number): Token;
51 currentIndex(): number;
52 /**
53 * Move to the next token. Only suitable in preprocessing steps. When
54 * generating new code, you should use copyToken or removeToken.
55 */
56 nextToken(): void;
57 previousToken(): void;
58 finish(): string;
59 isAtEnd(): boolean;
60}