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 TokenStream
The currently-selected token stream inputprotected Hashtable
The set of inputs to the MUXprotected Stack
Used to track stack of input streams -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addInputStream
(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()
void
push
(TokenStream stream) void
void
retry()
Abort recognition of current Token and try again.void
select
(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:
nextToken
in 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:IASDebugStream
Returns the entire text input to the lexer.- Specified by:
getEntireText
in interfaceIASDebugStream
- Returns:
- The entire text or
null
, if error occured or System.in was used.
-
getOffsetInfo
Description copied from interface:IASDebugStream
Returns the offset information for the token- Specified by:
getOffsetInfo
in interfaceIASDebugStream
- Parameters:
token
- the token whose information need to be retrieved- Returns:
- offset info, or
null
-