TokenStream loads tokens from a
TokenSource on-demand, and places the tokens in a buffer to provide
access to any previous token by index.
This token stream ignores the value of Token#getChannel. If your
parser requires the token stream filter tokens to only those on a particular
channel, such as Token#DEFAULT_CHANNEL or
Token#HIDDEN_CHANNEL, use a filtering token stream such a
CommonTokenStream.
| Modifier and Type | Field and Description |
|---|---|
| protected boolean | fetchedEOF
Indicates whether the |
| protected int | |
| protected List | tokens
A collection of all tokens fetched from the token source. |
| protected TokenSource | tokenSource
The |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected int | Returns: The adjusted target token index.The target token index. i)Allowed derived classes to modify the behavior of operations which change the current stream position by adjusting the target token index of a seek operation. |
| public void | consume()
Implements org. |
| protected int | |
| public void | |
| protected List | |
| public Token | get(int i)
Implements org. Token at the specified index in the stream.
|
| public List | |
| public List | getHiddenTokensToLeft(int tokenIndex, int channel)
Collect all tokens on specified channel to the left of
the current token up until we see a token on |
| public List | getHiddenTokensToLeft(int tokenIndex)
Collect all hidden tokens (any off-default channel) to the left of
the current token up until we see a token on |
| public List | getHiddenTokensToRight(int tokenIndex, int channel)
Collect all tokens on specified channel to the right of
the current token up until we see a token on |
| public List | getHiddenTokensToRight(int tokenIndex)
Collect all hidden tokens (any off-default channel) to the right of
the current token up until we see a token on |
| public String | getSourceName()
Implements org. |
| public String | getText()
Implements org. |
| public String | getText(Interval
The interval of tokens within this stream to get text
for. interval)Implements org. interval.
|
| public String | getText(RuleContext
The context providing the source interval of tokens to get
text for. ctx)Implements org. |
| public String | getText(Object
The first token in the interval to get text for. start, Object The last token in the interval to get text for (inclusive). stop)Implements org. start and
stop (inclusive).
|
| public List | |
| public List | |
| public List | |
| public List | |
| public TokenSource | getTokenSource()
Implements org. TokenSource which provides tokens for this
stream.
|
| public int | index()
Implements org. LA(1).
|
| public int | LA(int i)
Implements org. i from the current
position.
|
| protected final void | |
| protected Token | |
| public Token | LT(int k)
Implements org. Token instance associated with the value returned by
LA(k).
|
| public int | mark()
Implements org. seek() operations will be
valid over a "marked range" extending from the index where mark()
was called to the current index().
|
| protected int | nextTokenOnChannel(int i, int channel)
Given a starting index, return the index of the next token on channel. |
| protected int | previousTokenOnChannel(int i, int channel)
Given a starting index, return the index of the previous token on channel. |
| public void | release(int
A marker returned by a call to marker)mark().Implements org. mark().
|
| public void | reset()
Deprecated
Use
This method resets the token stream back to the first token in the
buffer.
seek(0) instead.
|
| public void | seek(int
The absolute index to seek to. index)Implements org. index.
|
| public void | |
| protected void | |
| public int | size()
Implements org. |
| protected boolean | Returns: true if a token is located at index i, otherwise
false.Make sure index |
| fetchedEOF | back to summary |
|---|---|
| protected boolean fetchedEOF Indicates whether the | |
| p | back to summary |
|---|---|
| protected int p The index into This field is set to -1 when the stream is first constructed or when
| |
| tokens | back to summary |
|---|---|
| protected List<Token> tokens A collection of all tokens fetched from the token source. The list is
considered a complete view of the input once | |
| tokenSource | back to summary |
|---|---|
| protected TokenSource tokenSource The | |
| BufferedTokenStream | back to summary |
|---|---|
| public BufferedTokenStream(TokenSource tokenSource) | |
| adjustSeekIndex | back to summary |
|---|---|
| protected int adjustSeekIndex(int i) Allowed derived classes to modify the behavior of operations which change
the current stream position by adjusting the target token index of a seek
operation. The default implementation simply returns For example,
| |
| consume | back to summary |
|---|---|
| public void consume() Implements org. Doc from org. Consumes the current symbol in the stream. This method has the following effects:
index() is
incremented by exactly 1, as that would preclude the ability to implement
filtering streams (e.g. CommonTokenStream which distinguishes
between "on-channel" and "off-channel" tokens).
| |
| fetch | back to summary |
|---|---|
| protected int fetch(int n) Add
| |
| fill | back to summary |
|---|---|
| public void fill() Get all tokens from lexer until EOF. | |
| filterForChannel | back to summary |
|---|---|
| protected List | |
| get | back to summary |
|---|---|
| public Token get(int i) Implements org. Doc from org. Gets the The preconditions for this method are the same as the preconditions of
The symbol referred to by
| |
| get | back to summary |
|---|---|
| public List Get all tokens from start..stop inclusively. | |
| getHiddenTokensToLeft | back to summary |
|---|---|
| public List Collect all tokens on specified channel to the left of
the current token up until we see a token on | |
| getHiddenTokensToLeft | back to summary |
|---|---|
| public List Collect all hidden tokens (any off-default channel) to the left of
the current token up until we see a token on | |
| getHiddenTokensToRight | back to summary |
|---|---|
| public List Collect all tokens on specified channel to the right of
the current token up until we see a token on | |
| getHiddenTokensToRight | back to summary |
|---|---|
| public List Collect all hidden tokens (any off-default channel) to the right of
the current token up until we see a token on | |
| getSourceName | back to summary |
|---|---|
| public String getSourceName() Implements org. Doc from org. Gets the name of the underlying symbol source. This method returns a
non-null, non-empty string. If such a name is not known, this method
returns
| |
| getText | back to summary |
|---|---|
| public String getText() Implements org. Get the text of all tokens in this buffer.
| |
| getText | back to summary |
|---|---|
| public String getText(Interval interval) Implements org. Doc from org. Return the text of all tokens within the specified
TokenStream stream = ...;
String text = "";
for (int i = interval.a; i <= interval.b; i++) {
text += stream.get(i).getText();
}
| |
| getText | back to summary |
|---|---|
| public String getText(RuleContext ctx) Implements org. Doc from org. Return the text of all tokens in the source interval of the specified
context. This method behaves like the following code, including potential
exceptions from the call to If TokenStream stream = ...; String text = stream.getText(ctx.getSourceInterval());
| |
| getText | back to summary |
|---|---|
| public String getText(Object start, Object stop) Implements org. Doc from org. Return the text of all tokens in this stream between If the specified For streams which ensure that the
TokenStream stream = ...;
String text = "";
for (int i = start.getTokenIndex(); i <= stop.getTokenIndex(); i++) {
text += stream.get(i).getText();
}
| |
| getTokens | back to summary |
|---|---|
| public List | |
| getTokens | back to summary |
|---|---|
| public List | |
| getTokens | back to summary |
|---|---|
| public List Given a start and stop index, return a | |
| getTokens | back to summary |
|---|---|
| public List | |
| getTokenSource | back to summary |
|---|---|
| public TokenSource getTokenSource() Implements org. Doc from org. Gets the underlying
| |
| index | back to summary |
|---|---|
| public int index() Implements org. Doc from org. Return the index into the stream of the input symbol referred to by
The behavior of this method is unspecified if no call to an
| |
| LA | back to summary |
|---|---|
| public int LA(int i) Implements org. Doc from org. Gets the value of the symbol at offset This method is guaranteed to succeed if any of the following are true:
If The return value is unspecified if
| |
| lazyInit | back to summary |
|---|---|
| protected final void lazyInit() | |
| LB | back to summary |
|---|---|
| protected Token LB(int k) | |
| LT | back to summary |
|---|---|
| public Token LT(int k) Implements org. Doc from org. Get the | |
| mark | back to summary |
|---|---|
| public int mark() Implements org. Doc from org. A mark provides a guarantee that The returned mark is an opaque handle (type The behavior of this method is unspecified if no call to an
This method does not change the current position in the input stream. The following example shows the use of
IntStream stream = ...;
int index = -1;
int mark = stream.mark();
try {
index = stream.index();
// perform work here...
} finally {
if (index != -1) {
stream.seek(index);
}
stream.release(mark);
}
| |
| nextTokenOnChannel | back to summary |
|---|---|
| protected int nextTokenOnChannel(int i, int channel) Given a starting index, return the index of the next token on channel.
Return | |
| previousTokenOnChannel | back to summary |
|---|---|
| protected int previousTokenOnChannel(int i, int channel) Given a starting index, return the index of the previous token on
channel. Return
If | |
| release | back to summary |
|---|---|
| public void release(int marker) Implements org. Doc from org. This method releases a marked range created by a call to
For more information and an example, see
| |
| reset | back to summary |
|---|---|
| public void reset()
Deprecated Use This method resets the token stream back to the first token in the
buffer. It is equivalent to calling
| |
| seek | back to summary |
|---|---|
| public void seek(int index) Implements org. Doc from org. Set the input cursor to the position indicated by
index
lies within a marked region. For more information on marked regions, see
mark. The behavior of this method is unspecified if no call to
an initializing method has occurred after this stream
was constructed.
| |
| setTokenSource | back to summary |
|---|---|
| public void setTokenSource(TokenSource tokenSource) Reset this token stream by setting its token source. | |
| setup | back to summary |
|---|---|
| protected void setup() | |
| size | back to summary |
|---|---|
| public int size() Implements org. Doc from org. Returns the total number of symbols in the stream, including a single EOF symbol.
| |
| sync | back to summary |
|---|---|
| protected boolean sync(int i) Make sure index
| |