Interface TokenStream
-
- All Superinterfaces:
IntStream
- All Known Implementing Classes:
BufferedTokenStream
,CommonTokenStream
,UnbufferedTokenStream
public interface TokenStream extends IntStream
-
-
Field Summary
-
Fields inherited from interface org.antlr.v4.runtime.IntStream
EOF, UNKNOWN_SOURCE_NAME
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Token
get(int index)
Gets theToken
at the specifiedindex
in the stream.String
getText()
Return the text of all tokens in the stream.String
getText(Interval interval)
Return the text of all tokens within the specifiedinterval
.String
getText(RuleContext ctx)
Return the text of all tokens in the source interval of the specified context.String
getText(Token start, Token stop)
Return the text of all tokens in this stream betweenstart
andstop
(inclusive).TokenSource
getTokenSource()
Gets the underlyingTokenSource
which provides tokens for this stream.Token
LT(int k)
-
-
-
Method Detail
-
LT
Token LT(int k)
Get theToken
instance associated with the value returned byLA(k)
. This method has the same pre- and post-conditions asIntStream.LA(int)
. In addition, when the preconditions of this method are met, the return value is non-null and the value ofLT(k).getType()==LA(k)
.- See Also:
IntStream.LA(int)
-
get
Token get(int index)
Gets theToken
at the specifiedindex
in the stream. When the preconditions of this method are met, the return value is non-null.The preconditions for this method are the same as the preconditions of
IntStream.seek(int)
. If the behavior ofseek(index)
is unspecified for the current state and givenindex
, then the behavior of this method is also unspecified.The symbol referred to by
index
differs fromseek()
only in the case of filtering streams whereindex
lies before the end of the stream. Unlikeseek()
, this method does not adjustindex
to point to a non-ignored symbol.- Throws:
IllegalArgumentException
- if {code index} is less than 0UnsupportedOperationException
- if the stream does not support retrieving the token at the specified index
-
getTokenSource
TokenSource getTokenSource()
Gets the underlyingTokenSource
which provides tokens for this stream.
-
getText
String getText(Interval interval)
Return the text of all tokens within the specifiedinterval
. This method behaves like the following code (including potential exceptions for violating preconditions ofget(int)
, but may be optimized by the specific implementation.TokenStream stream = ...; String text = ""; for (int i = interval.a; i <= interval.b; i++) { text += stream.get(i).getText(); }
- Parameters:
interval
- The interval of tokens within this stream to get text for.- Returns:
- The text of all tokens within the specified interval in this stream.
- Throws:
NullPointerException
- ifinterval
isnull
-
getText
String getText()
Return the text of all tokens in the stream. This method behaves like the following code, including potential exceptions from the calls toIntStream.size()
andgetText(Interval)
, but may be optimized by the specific implementation.TokenStream stream = ...; String text = stream.getText(new Interval(0, stream.size()));
- Returns:
- The text of all tokens in the stream.
-
getText
String getText(RuleContext ctx)
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 togetText(Interval)
, but may be optimized by the specific implementation.If
ctx.getSourceInterval()
does not return a valid interval of tokens provided by this stream, the behavior is unspecified.TokenStream stream = ...; String text = stream.getText(ctx.getSourceInterval());
- Parameters:
ctx
- The context providing the source interval of tokens to get text for.- Returns:
- The text of all tokens within the source interval of
ctx
.
-
getText
String getText(Token start, Token stop)
Return the text of all tokens in this stream betweenstart
andstop
(inclusive).If the specified
start
orstop
token was not provided by this stream, or if thestop
occurred before thestart
token, the behavior is unspecified.For streams which ensure that the
Token.getTokenIndex()
method is accurate for all of its provided tokens, this method behaves like the following code. Other streams may implement this method in other ways provided the behavior is consistent with this at a high level.TokenStream stream = ...; String text = ""; for (int i = start.getTokenIndex(); i <= stop.getTokenIndex(); i++) { text += stream.get(i).getText(); }
- Parameters:
start
- The first token in the interval to get text for.stop
- The last token in the interval to get text for (inclusive).- Returns:
- The text of all tokens lying between the specified
start
andstop
tokens. - Throws:
UnsupportedOperationException
- if this stream does not support this method for the specified tokens
-
-