Top Description Fields Constructors Methods
org.antlr.runtime.misc

public abstract Class LookaheadStream<T>

extends FastQueue<T>
Class Inheritance
Known Direct Subclasses
org.antlr.runtime.tree.CommonTreeNodeStream, org.antlr.runtime.UnbufferedTokenStream

A lookahead queue that knows how to mark/release locations in the buffer for backtracking purposes. Any markers force the FastQueue superclass to keep all elements until no more markers; then can reset to avoid growing a huge buffer.

Field Summary

Modifier and TypeField and Description
protected int
currentElementIndex

Absolute token index.

public T
eof

Track object returned by nextElement upon end of stream; Return it later when they ask for LT passed end of input.

protected int
lastMarker

Track the last mark() call result value for use in rewind().

protected int
markDepth

tracks how deep mark() calls are nested

protected T
prevElement

This is the LT(-1) element for the first element in data.

public static final int
Inherited from org.antlr.runtime.misc.FastQueue:
dataprange

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
consume()

Make sure we have at least one element to remove, even if EOF

public void
fill(int n)

add n elements to buffer

public int
public abstract boolean
isEOF(T o)

protected T
LB(int k)

public T
LT(int k)

public int
mark()

public abstract T
nextElement()

Implement nextElement to supply a stream of elements to this lookahead buffer.

public void
release(int marker)

public T
remove()

Overrides org.antlr.runtime.misc.FastQueue.remove.

Get and remove first element in queue; override FastQueue#remove(); it's the same, just checks for backtracking.
public void
public void
rewind(int marker)

public void
public void
seek(int index)

Seek to a 0-indexed absolute token index.

public int
size()

Overrides org.antlr.runtime.misc.FastQueue.size.

Size of entire stream is unknown; we only know buffer size from FastQueue.
protected void
syncAhead(int need)

Make sure we have 'need' elements from current position p.

Inherited from org.antlr.runtime.misc.FastQueue:
addclearelementAtheadrangetoString

Field Detail

currentElementIndexback to summary
protected int currentElementIndex

Absolute token index. It's the index of the symbol about to be read via LT(1). Goes from 0 to numtokens.

eofback to summary
public T eof

Track object returned by nextElement upon end of stream; Return it later when they ask for LT passed end of input.

lastMarkerback to summary
protected int lastMarker

Track the last mark() call result value for use in rewind().

markDepthback to summary
protected int markDepth

tracks how deep mark() calls are nested

prevElementback to summary
protected T prevElement

This is the LT(-1) element for the first element in data.

UNINITIALIZED_EOF_ELEMENT_INDEXback to summary
public static final int UNINITIALIZED_EOF_ELEMENT_INDEX

Constructor Detail

LookaheadStreamback to summary
public LookaheadStream()

Method Detail

consumeback to summary
public void consume()

Make sure we have at least one element to remove, even if EOF

fillback to summary
public void fill(int n)

add n elements to buffer

indexback to summary
public int index()
isEOFback to summary
public abstract boolean isEOF(T o)
LBback to summary
protected T LB(int k)
LTback to summary
public T LT(int k)
markback to summary
public int mark()
nextElementback to summary
public abstract T nextElement()

Implement nextElement to supply a stream of elements to this lookahead buffer. Return EOF upon end of the stream we're pulling from.

See Also
isEOF
releaseback to summary
public void release(int marker)
removeback to summary
public T remove()

Overrides org.antlr.runtime.misc.FastQueue.remove.

Get and remove first element in queue; override FastQueue#remove(); it's the same, just checks for backtracking.

Annotations
@Override
resetback to summary
public void reset()

Overrides org.antlr.runtime.misc.FastQueue.reset.

Annotations
@Override
rewindback to summary
public void rewind(int marker)
rewindback to summary
public void rewind()
seekback to summary
public void seek(int index)

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 consume or LT for k>0.

Exceptions
IllegalArgumentException:
if index is less than 0
UnsupportedOperationException:
if index lies before the beginning of the moving window buffer (index < currentElementIndex - p).
sizeback to summary
public int size()

Overrides org.antlr.runtime.misc.FastQueue.size.

Size of entire stream is unknown; we only know buffer size from FastQueue.

Annotations
@Override
syncAheadback to summary
protected void syncAhead(int need)

Make 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.size().