public class CommonTokenStream extends Object implements TokenStream
Modifier and Type | Field and Description |
---|---|
protected int |
channel
Skip tokens on any channel but this one; this is how we skip whitespace...
|
protected Map |
channelOverrideMap
Map
|
protected boolean |
discardOffChannelTokens
By default, track all incoming tokens
|
protected Set |
discardSet
Set
|
protected int |
lastMarker
Track the last mark() call result value for use in rewind().
|
protected int |
p
The index into the tokens list of the current token (next token
to consume).
|
protected List |
tokens
Record every single token pulled from the source so we can reproduce
chunks of it later.
|
protected TokenSource |
tokenSource |
Constructor and Description |
---|
CommonTokenStream() |
CommonTokenStream(TokenSource tokenSource) |
CommonTokenStream(TokenSource tokenSource,
int channel) |
Modifier and Type | Method and Description |
---|---|
void |
consume()
Move the input pointer to the next incoming token.
|
void |
discardOffChannelTokens(boolean discardOffChannelTokens) |
void |
discardTokenType(int ttype) |
protected void |
fillBuffer()
Load all tokens from the token source and put in tokens.
|
Token |
get(int i)
Return absolute token i; ignore which channel the tokens are on;
that is, count all tokens not just on-channel tokens.
|
String |
getSourceName()
Where are you getting symbols from? Normally, implementations will
pass the buck all the way to the lexer who can ask its input stream
for the file name or whatever.
|
List |
getTokens() |
List |
getTokens(int start,
int stop) |
List |
getTokens(int start,
int stop,
BitSet types)
Given a start and stop index, return a List of all tokens in
the token type BitSet.
|
List |
getTokens(int start,
int stop,
int ttype) |
List |
getTokens(int start,
int stop,
List types) |
TokenSource |
getTokenSource()
Where is this stream pulling tokens from? This is not the name, but
the object that provides Token objects.
|
int |
index()
Return the current input symbol index 0..n where n indicates the
last symbol has been read.
|
int |
LA(int i)
Get int at current input pointer + i ahead where i=1 is next int.
|
protected Token |
LB(int k)
Look backwards k tokens on-channel tokens
|
Token |
LT(int k)
Get the ith token from the current position 1..n where k=1 is the
first symbol of lookahead.
|
int |
mark()
Tell the stream to start buffering if it hasn't already.
|
void |
release(int marker)
You may want to commit to a backtrack but don't want to force the
stream to keep bookkeeping objects around for a marker that is
no longer necessary.
|
void |
reset() |
void |
rewind()
Rewind to the input position of the last marker.
|
void |
rewind(int marker)
Reset the stream so that next call to index would return marker.
|
void |
seek(int index)
Set the input cursor to the position indicated by index.
|
void |
setTokenSource(TokenSource tokenSource)
Reset this token stream by setting its token source.
|
void |
setTokenTypeChannel(int ttype,
int channel)
A simple filter mechanism whereby you can tell this token stream
to force all tokens of type ttype to be on channel.
|
int |
size()
Only makes sense for streams that buffer everything up probably, but
might be useful to display the entire stream or for testing.
|
protected int |
skipOffTokenChannels(int i)
Given a starting index, return the index of the first on-channel
token.
|
protected int |
skipOffTokenChannelsReverse(int i) |
String |
toString() |
String |
toString(int start,
int stop)
Return the text of all tokens from start to stop, inclusive.
|
String |
toString(Token start,
Token stop)
Because the user is not required to use a token with an index stored
in it, we must provide a means for two token objects themselves to
indicate the start/end location.
|
protected TokenSource tokenSource
protected List tokens
protected Map channelOverrideMap
protected Set discardSet
protected int channel
protected boolean discardOffChannelTokens
protected int lastMarker
protected int p
public CommonTokenStream()
public CommonTokenStream(TokenSource tokenSource)
public CommonTokenStream(TokenSource tokenSource, int channel)
public void setTokenSource(TokenSource tokenSource)
protected void fillBuffer()
public void consume()
protected int skipOffTokenChannels(int i)
protected int skipOffTokenChannelsReverse(int i)
public void setTokenTypeChannel(int ttype, int channel)
public void discardTokenType(int ttype)
public void discardOffChannelTokens(boolean discardOffChannelTokens)
public List getTokens()
public List getTokens(int start, int stop)
public List getTokens(int start, int stop, BitSet types)
public List getTokens(int start, int stop, int ttype)
public Token LT(int k)
LT
in interface TokenStream
protected Token LB(int k)
public Token get(int i)
get
in interface TokenStream
public int LA(int i)
IntStream
public int mark()
IntStream
public void release(int marker)
IntStream
public int size()
IntStream
public int index()
IntStream
public void rewind(int marker)
IntStream
public void rewind()
IntStream
public void reset()
public void seek(int index)
IntStream
public TokenSource getTokenSource()
TokenStream
getTokenSource
in interface TokenStream
public String getSourceName()
IntStream
getSourceName
in interface IntStream
public String toString(int start, int stop)
TokenStream
toString
in interface TokenStream
public String toString(Token start, Token stop)
TokenStream
toString
in interface TokenStream
Copyright © 2020. All rights reserved.