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