T
- the type of the elements kept in the streampublic abstract class Lookahead<T> extends Object
Modifier and Type | Field and Description |
---|---|
protected T |
endOfInputIndicator
Once the end of the underlying input was reached, an end of input indicator is created and constantly returned
for all calls of current and next.
|
protected boolean |
endReached
Determines if the end of the underlying data source has been reached.
|
protected List<T> |
itemBuffer
Internal buffer containing items which where already created due to lookaheads.
|
protected List<ParseError> |
problemCollector
Used to collect problems which occurred when processing the input.
|
Constructor and Description |
---|
Lookahead() |
Modifier and Type | Method and Description |
---|---|
T |
consume()
Removes and returns the current item from the stream.
|
void |
consume(int numberOfItems)
Consumes (removes) numberOfItems at once.
|
T |
current()
Returns the item the stream is currently pointing at.
|
protected abstract T |
endOfInput()
Creates the end of input indicator item.
|
protected abstract T |
fetch()
Fetches the next item from the stream.
|
List<ParseError> |
getProblemCollector()
Provides access to the problem collector used by this instance.
|
T |
next()
Returns the next item after the current one in the stream.
|
T |
next(int offset)
Returns the next n-th item in the stream.
|
void |
setProblemCollector(List<ParseError> problemCollector)
Installs the given problem collector.
|
protected List<T> itemBuffer
protected boolean endReached
protected List<ParseError> problemCollector
protected T endOfInputIndicator
public T current()
This method does not change the internal state. Therefore it can be called several times and will always return the same result.
public T next()
This method does not change the internal state. Therefore it can be called several times and will always return the same result.
consume()
public T next(int offset)
Calling this method with 0 as parameter, will return the current item. Calling it with 1 will return the same item as a call to next().
This method does not change the internal state. Therefore it can be called several times and will always return the same result.
offset
- the number of items to skipprotected abstract T endOfInput()
This method will be only called once, as the indicator is cached.
protected abstract T fetch()
public T consume()
After this method was called, all calls to current()
will then return the item, which
was previously returned by next()
public void consume(int numberOfItems)
Removes the given number of items from the stream.
numberOfItems
- the number of items to removepublic List<ParseError> getProblemCollector()
public void setProblemCollector(List<ParseError> problemCollector)
problemCollector
- the problem collector to be from now onCopyright © 2020. All rights reserved.