Package antlr
Class TokenStreamSelector
java.lang.Object
antlr.TokenStreamSelector
- All Implemented Interfaces:
IASDebugStream,TokenStream
A token stream MUX (multiplexor) knows about n token streams
and can multiplex them onto the same channel for use by token
stream consumer like a parser. This is a way to have multiple
lexers break up the same input stream for a single parser.
Or, you can have multiple instances of the same lexer handle
multiple input streams; this works great for includes.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected TokenStreamThe currently-selected token stream inputprotected HashtableThe set of inputs to the MUXprotected StackUsed to track stack of input streams -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddInputStream(TokenStream stream, String key) Return the stream from tokens are being pulled at the moment.Returns the entire text input to the lexer.getOffsetInfo(Token token) Returns the offset information for the tokenpop()voidpush(TokenStream stream) voidvoidretry()Abort recognition of current Token and try again.voidselect(TokenStream stream) Set the stream without pushing old streamvoid
-
Field Details
-
inputStreamNames
The set of inputs to the MUX -
input
The currently-selected token stream input -
streamStack
Used to track stack of input streams
-
-
Constructor Details
-
TokenStreamSelector
public TokenStreamSelector()
-
-
Method Details
-
addInputStream
-
getCurrentStream
Return the stream from tokens are being pulled at the moment. -
getStream
-
nextToken
- Specified by:
nextTokenin interfaceTokenStream- Throws:
TokenStreamException
-
pop
-
push
-
push
-
retry
Abort recognition of current Token and try again. A stream can push a new stream (for include files for example, and then retry(), which will cause the current stream to abort back to this.nextToken(). this.nextToken() then asks for a token from the current stream, which is the new "substream."- Throws:
TokenStreamRetryException
-
select
Set the stream without pushing old stream -
select
- Throws:
IllegalArgumentException
-
getEntireText
Description copied from interface:IASDebugStreamReturns the entire text input to the lexer.- Specified by:
getEntireTextin interfaceIASDebugStream- Returns:
- The entire text or
null, if error occured or System.in was used.
-
getOffsetInfo
Description copied from interface:IASDebugStreamReturns the offset information for the token- Specified by:
getOffsetInfoin interfaceIASDebugStream- Parameters:
token- the token whose information need to be retrieved- Returns:
- offset info, or
null
-