File size: 3,089 Bytes
6abff73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { type Token, TokenKind } from './Token';
import { TokenSequence } from './TokenSequence';
import type { ParserContext } from './ParserContext';
/**
 * Manages a stream of tokens that are read by the parser.
 *
 * @remarks
 * Use TokenReader.readToken() to read a token and advance the stream pointer.
 * Use TokenReader.peekToken() to preview the next token.
 * Use TokenReader.createMarker() and backtrackToMarker() to rewind to an earlier point.
 * Whenever readToken() is called, the token is added to an accumulated TokenSequence
 * that can be extracted by calling extractAccumulatedSequence().
 */
export declare class TokenReader {
    readonly tokens: ReadonlyArray<Token>;
    private readonly _parserContext;
    private _readerStartIndex;
    private _readerEndIndex;
    private _currentIndex;
    private _accumulatedStartIndex;
    constructor(parserContext: ParserContext, embeddedTokenSequence?: TokenSequence);
    /**
     * Extracts and returns the TokenSequence that was accumulated so far by calls to readToken().
     * The next call to readToken() will start a new accumulated sequence.
     */
    extractAccumulatedSequence(): TokenSequence;
    /**
     * Returns true if the accumulated sequence has any tokens yet.  This will be false
     * when the TokenReader starts, and it will be false immediately after a call
     * to extractAccumulatedSequence().  Otherwise, it will become true whenever readToken()
     * is called.
     */
    isAccumulatedSequenceEmpty(): boolean;
    /**
     * Like extractAccumulatedSequence(), but returns undefined if nothing has been
     * accumulated yet.
     */
    tryExtractAccumulatedSequence(): TokenSequence | undefined;
    /**
     * Asserts that isAccumulatedSequenceEmpty() should return false.  If not, an exception
     * is throw indicating a parser bug.
     */
    assertAccumulatedSequenceIsEmpty(): void;
    /**
     * Returns the next token that would be returned by _readToken(), without
     * consuming anything.
     */
    peekToken(): Token;
    /**
     * Returns the TokenKind for the next token that would be returned by _readToken(), without
     * consuming anything.
     */
    peekTokenKind(): TokenKind;
    /**
     * Like peekTokenKind(), but looks ahead two tokens.
     */
    peekTokenAfterKind(): TokenKind;
    /**
     * Like peekTokenKind(), but looks ahead three tokens.
     */
    peekTokenAfterAfterKind(): TokenKind;
    /**
     * Extract the next token from the input stream and return it.
     * The token will also be appended to the accumulated sequence, which can
     * later be accessed via extractAccumulatedSequence().
     */
    readToken(): Token;
    /**
     * Returns the kind of the token immediately before the current token.
     */
    peekPreviousTokenKind(): TokenKind;
    /**
     * Remembers the current position in the stream.
     */
    createMarker(): number;
    /**
     * Rewinds the stream pointer to a previous position in the stream.
     */
    backtrackToMarker(marker: number): void;
}
//# sourceMappingURL=TokenReader.d.ts.map