/*! * Copyright 2016 The ANTLR Project. All rights reserved. * Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information. */ import { Interval } from './misc/Interval'; import { RuleContext } from './RuleContext'; import { Token } from './Token'; import { TokenSource } from './TokenSource'; import { TokenStream } from './TokenStream'; /** * This implementation of {@link TokenStream} loads tokens from a * {@link TokenSource} on-demand, and places the tokens in a buffer to provide * access to any previous token by index. * *
* This token stream ignores the value of {@link Token#getChannel}. If your * parser requires the token stream filter tokens to only those on a particular * channel, such as {@link Token#DEFAULT_CHANNEL} or * {@link Token#HIDDEN_CHANNEL}, use a filtering token stream such a * {@link CommonTokenStream}.
*/ export declare class BufferedTokenStream implements TokenStream { /** * The {@link TokenSource} from which tokens for this stream are fetched. */ private _tokenSource; /** * A collection of all tokens fetched from the token source. The list is * considered a complete view of the input once {@link #fetchedEOF} is set * to {@code true}. */ protected tokens: Token[]; /** * The index into {@link #tokens} of the current token (next token to * {@link #consume}). {@link #tokens}{@code [}{@link #p}{@code ]} should be * {@link #LT LT(1)}. * *This field is set to -1 when the stream is first constructed or when * {@link #setTokenSource} is called, indicating that the first token has * not yet been fetched from the token source. For additional information, * see the documentation of {@link IntStream} for a description of * Initializing Methods.
*/ protected p: number; /** * Indicates whether the {@link Token#EOF} token has been fetched from * {@link #tokenSource} and added to {@link #tokens}. This field improves * performance for the following cases: * *For example, {@link CommonTokenStream} overrides this method to ensure that * the seek target is always an on-channel token.
* * @param i The target token index. * @return The adjusted target token index. */ protected adjustSeekIndex(i: number): number; protected lazyInit(): void; protected setup(): void; /** Given a start and stop index, return a {@code List} of all tokens in * the token type {@code BitSet}. Return {@code null} if no tokens were found. This * method looks at both on and off channel tokens. */ getTokens(start?: number, stop?: number, types?: Set* If {@code i} specifies an index at or after the EOF token, the EOF token * index is returned. This is due to the fact that the EOF token is treated * as though it were on every channel.
*/ protected previousTokenOnChannel(i: number, channel: number): number; /** Collect all tokens on specified channel to the right of * the current token up until we see a token on {@link Lexer#DEFAULT_TOKEN_CHANNEL} or * EOF. If {@code channel} is {@code -1}, find any non default channel token. */ getHiddenTokensToRight(tokenIndex: number, channel?: number): Token[]; /** Collect all tokens on specified channel to the left of * the current token up until we see a token on {@link Lexer#DEFAULT_TOKEN_CHANNEL}. * If {@code channel} is {@code -1}, find any non default channel token. */ getHiddenTokensToLeft(tokenIndex: number, channel?: number): Token[]; protected filterForChannel(from: number, to: number, channel: number): Token[]; readonly sourceName: string; /** Get the text of all tokens in this buffer. */ getText(): string; getText(interval: Interval): string; getText(context: RuleContext): string; getTextFromRange(start: any, stop: any): string; /** Get all tokens from lexer until EOF. */ fill(): void; private isWritableToken(t); private isToken(t); }