antlr-ng
Version:
Next generation ANTLR Tool
72 lines (71 loc) • 2.78 kB
TypeScript
import { type TokenStream } from "antlr4ng";
import type { CommonTree } from "./CommonTree.js";
export declare class CommonTreeNodeStream {
/** If this tree (root) was created from a {@link TokenStream}, track it. */
tokens: TokenStream;
/** Pull nodes from which tree? */
private root;
/** The {@link TreeIterator} we using. */
private iterator;
/** Tree {@code (nil A B C)} trees like flat {@code A B C} streams */
private hasNilRoot;
/** Tracks tree depth. Level=0 means we're at root node level. */
private level;
/** Absolute token index. It's the index of the symbol about to be read via `LT(1)`. */
private currentElementIndex;
/** Index of next element to fill. */
private p;
private data;
/** This is the `LT(-1)` element for the first element in {@link data}. */
private prevElement;
/** Track object returned by nextElement upon end of stream. */
private eof;
/** Tracks how deep mark() calls are nested. */
private markDepth;
constructor(tree: CommonTree);
isEOF(o: CommonTree): boolean;
lookaheadType(k: number): CommonTree | null;
lookahead(i: number): number;
get index(): number;
mark(): number;
release(marker: number): void;
/** Make sure we have at least one element to remove, even if EOF. */
consume(): void;
/**
* Seek to a 0-indexed absolute token index. Normally used to seek backwards in the buffer. Does not force
* loading of nodes.
*
* To preserve backward compatibility, this method allows seeking past the end of the currently buffered data.
* In this case, the input pointer will be moved but the data will only actually be loaded upon the next call to
* {@link consume} or {@link lookaheadType} for `k > 0`.
*
* @param index The absolute token index to seek to.
*/
seek(index: number): void;
private lookBack;
/**
* @returns element `i` elements ahead of current element. `i == 0` gets current element. This is not an absolute
* index into `data` since `p` defines the start of the real list.
*
* @param i The index for the element.
*/
private elementAt;
/**
* Makes sure we have 'need' elements from current position p. Last valid p index is data.size()-1. `p + need - 1`
* is the data index 'need' elements ahead. If we need 1 element, `(p + 1 - 1) == p` must be < data.length.
*
* @param need The number of elements to ensure are in the buffer.
*/
private syncAhead;
/**
* Adds n elements to buffer
*
* @param n The number of elements to add.
*/
private fill;
private nextElement;
/**
* @returns the first element in the queue.
*/
private remove;
}