1 | import { Token } from "./parser/tokenizer";
|
2 | import { ContextualKeyword } from "./parser/tokenizer/keywords";
|
3 | import { TokenType } from "./parser/tokenizer/types";
|
4 | export interface TokenProcessorSnapshot {
|
5 | resultCode: string;
|
6 | tokenIndex: number;
|
7 | }
|
8 | export 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 | rawCodeForToken(token: Token): string;
|
27 | stringValueAtIndex(index: number): string;
|
28 | stringValue(): string;
|
29 | stringValueForToken(token: Token): string;
|
30 | matches1AtIndex(index: number, t1: TokenType): boolean;
|
31 | matches2AtIndex(index: number, t1: TokenType, t2: TokenType): boolean;
|
32 | matches3AtIndex(index: number, t1: TokenType, t2: TokenType, t3: TokenType): boolean;
|
33 | matches1(t1: TokenType): boolean;
|
34 | matches2(t1: TokenType, t2: TokenType): boolean;
|
35 | matches3(t1: TokenType, t2: TokenType, t3: TokenType): boolean;
|
36 | matches4(t1: TokenType, t2: TokenType, t3: TokenType, t4: TokenType): boolean;
|
37 | matches5(t1: TokenType, t2: TokenType, t3: TokenType, t4: TokenType, t5: TokenType): boolean;
|
38 | matchesContextual(contextualKeyword: ContextualKeyword): boolean;
|
39 | matchesContextIdAndLabel(type: TokenType, contextId: number): boolean;
|
40 | previousWhitespaceAndComments(): string;
|
41 | replaceToken(newCode: string): void;
|
42 | replaceTokenTrimmingLeftWhitespace(newCode: string): void;
|
43 | removeInitialToken(): void;
|
44 | removeToken(): void;
|
45 | copyExpectedToken(tokenType: TokenType): void;
|
46 | copyToken(): void;
|
47 | copyTokenWithPrefix(prefix: string): void;
|
48 | appendCode(code: string): void;
|
49 | currentToken(): Token;
|
50 | currentTokenCode(): string;
|
51 | tokenAtRelativeIndex(relativeIndex: number): Token;
|
52 | currentIndex(): number;
|
53 | /**
|
54 | * Move to the next token. Only suitable in preprocessing steps. When
|
55 | * generating new code, you should use copyToken or removeToken.
|
56 | */
|
57 | nextToken(): void;
|
58 | previousToken(): void;
|
59 | finish(): string;
|
60 | isAtEnd(): boolean;
|
61 | }
|