T - token classTT - token type classpublic abstract class TokenStream<T extends Token<TT>,TT extends TokenType>
extends java.lang.Object
implements java.util.Iterator<T>
| Constructor and Description |
|---|
TokenStream(java.lang.String filename,
java.io.Reader reader,
CompiledDFA<TT> dfa)
Creates a token stream using the specified reader and DFA.
|
TokenStream(java.lang.String filename,
java.lang.String data,
CompiledDFA<TT> dfa)
Creates a token stream which reads data from the specified string.
|
| Modifier and Type | Method and Description |
|---|---|
protected abstract T |
createToken(TokenPosition position,
java.lang.String value,
TT tokenType)
Called to create a token.
|
java.lang.String |
getFile() |
int |
getLine() |
int |
getLineOffset() |
TokenPosition |
getPosition() |
boolean |
hasNext() |
protected abstract T |
invalidToken(TokenPosition position,
java.lang.String token)
Called when the input contains an invalid token.
|
protected abstract void |
ioException(java.io.IOException ex)
Called when an IO exception occurs.
|
boolean |
isNext(TT type) |
T |
next() |
T |
optional(TT type) |
T |
peek() |
void |
popMark()
Pops a mark from the mark stack without reset.
|
void |
pushMark()
Pushes a mark on the mark stack.
|
void |
remove() |
T |
required(TT type,
java.lang.String error) |
protected abstract void |
requiredTokenNotFound(TokenPosition position,
java.lang.String error)
Called when a required token could not be found.
|
void |
reset()
Pops a mark from the mark stack and resets the stream's position to it
|
public TokenStream(java.lang.String filename,
java.io.Reader reader,
CompiledDFA<TT> dfa)
filename - filenamereader - reader to read characters fromdfa - DFA to tokenize the streampublic TokenStream(java.lang.String filename,
java.lang.String data,
CompiledDFA<TT> dfa)
filename - filenamedata - data to readdfa - DFA to tokenize the streampublic java.lang.String getFile()
public int getLine()
public int getLineOffset()
public T peek()
public boolean isNext(TT type)
public TokenPosition getPosition()
public void pushMark()
public void popMark()
public void reset()
public boolean hasNext()
public void remove()
protected abstract T createToken(TokenPosition position, java.lang.String value, TT tokenType)
position - token position (range)value - token valuetokenType - token typeprotected abstract void requiredTokenNotFound(TokenPosition position, java.lang.String error)
position - erroring positionerror - error to be loggedprotected abstract T invalidToken(TokenPosition position, java.lang.String token)
position - erroring positiontoken - token valueprotected abstract void ioException(java.io.IOException ex)
ex - exception to be logged