public class BufferedTokenStream extends Object implements TokenStream
<names:{hi, <it>}>
has to parse names
as part of an expression but "hi, <it>"
as a nested template.
You can't use this stream if you pass whitespace or other off-channel
tokens to the parser. The stream can't ignore off-channel tokens.
(UnbufferedTokenStream is the same way.)
This is not a subclass of UnbufferedTokenStream because I don't want
to confuse small moving window of tokens it uses for the full buffer.Modifier and Type | Field and Description |
---|---|
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 int |
range |
protected List<Token> |
tokens
Record every single token pulled from the source so we can reproduce
chunks of it later.
|
protected TokenSource |
tokenSource |
Constructor and Description |
---|
BufferedTokenStream() |
BufferedTokenStream(TokenSource tokenSource) |
Modifier and Type | Method and Description |
---|---|
void |
consume()
Move the input pointer to the next incoming token.
|
protected void |
fetch(int n)
add n elements to buffer
|
void |
fill()
Get all tokens from lexer until EOF
|
Token |
get(int i)
Get a token at an absolute index i; 0..n-1.
|
List<? extends Token> |
get(int start,
int stop)
Get all tokens from start..stop inclusively
|
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<? extends Token> |
getTokens() |
List<? extends Token> |
getTokens(int start,
int stop) |
List<? extends Token> |
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<? extends Token> |
getTokens(int start,
int stop,
int ttype) |
List<? extends Token> |
getTokens(int start,
int stop,
List<Integer> 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) |
Token |
LT(int k)
Get Token at current input pointer + i ahead where i=1 is next Token.
|
int |
mark()
Tell the stream to start buffering if it hasn't already.
|
int |
range()
How far ahead has the stream been asked to look? The return
value is a valid index from 0..n-1.
|
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.
|
protected void |
setup() |
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 void |
sync(int i)
Make sure index i in tokens has a token.
|
String |
toString()
Grab *all* tokens from stream and return string
|
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<Token> tokens
protected int lastMarker
protected int p
protected int range
public BufferedTokenStream()
public BufferedTokenStream(TokenSource tokenSource)
public TokenSource getTokenSource()
TokenStream
getTokenSource
in interface TokenStream
public int index()
IntStream
public int range()
TokenStream
range
in interface TokenStream
public int mark()
IntStream
public void release(int marker)
IntStream
public void rewind(int marker)
IntStream
public void rewind()
IntStream
public void reset()
public void seek(int index)
IntStream
public int size()
IntStream
public void consume()
protected void sync(int i)
protected void fetch(int n)
public Token get(int i)
TokenStream
get
in interface TokenStream
public List<? extends Token> get(int start, int stop)
public int LA(int i)
IntStream
protected Token LB(int k)
public Token LT(int k)
TokenStream
LT
in interface TokenStream
protected void setup()
public void setTokenSource(TokenSource tokenSource)
public List<? extends Token> getTokens(int start, int stop, BitSet types)
public String getSourceName()
IntStream
getSourceName
in interface IntStream
public String toString()
public String toString(int start, int stop)
TokenStream
toString
in interface TokenStream
public String toString(Token start, Token stop)
TokenStream
toString
in interface TokenStream
public void fill()
Copyright © 1992–2015 ANTLR. All rights reserved.