Package antlr
Class TokenStreamSelector
- java.lang.Object
-
- antlr.TokenStreamSelector
-
- All Implemented Interfaces:
IASDebugStream,TokenStream
public class TokenStreamSelector extends java.lang.Object implements TokenStream, IASDebugStream
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
Fields Modifier and Type Field Description protected TokenStreaminputThe currently-selected token stream inputprotected java.util.HashtableinputStreamNamesThe set of inputs to the MUXprotected StackstreamStackUsed to track stack of input streams
-
Constructor Summary
Constructors Constructor Description TokenStreamSelector()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddInputStream(TokenStream stream, java.lang.String key)TokenStreamgetCurrentStream()Return the stream from tokens are being pulled at the moment.java.lang.StringgetEntireText()Returns the entire text input to the lexer.TokenOffsetInfogetOffsetInfo(Token token)Returns the offset information for the tokenTokenStreamgetStream(java.lang.String sname)TokennextToken()TokenStreampop()voidpush(TokenStream stream)voidpush(java.lang.String sname)voidretry()Abort recognition of current Token and try again.voidselect(TokenStream stream)Set the stream without pushing old streamvoidselect(java.lang.String sname)
-
-
-
Field Detail
-
inputStreamNames
protected java.util.Hashtable inputStreamNames
The set of inputs to the MUX
-
input
protected TokenStream input
The currently-selected token stream input
-
streamStack
protected Stack streamStack
Used to track stack of input streams
-
-
Method Detail
-
addInputStream
public void addInputStream(TokenStream stream, java.lang.String key)
-
getCurrentStream
public TokenStream getCurrentStream()
Return the stream from tokens are being pulled at the moment.
-
getStream
public TokenStream getStream(java.lang.String sname)
-
nextToken
public Token nextToken() throws TokenStreamException
- Specified by:
nextTokenin interfaceTokenStream- Throws:
TokenStreamException
-
pop
public TokenStream pop()
-
push
public void push(TokenStream stream)
-
push
public void push(java.lang.String sname)
-
retry
public void retry() throws TokenStreamRetryExceptionAbort 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
public void select(TokenStream stream)
Set the stream without pushing old stream
-
select
public void select(java.lang.String sname) throws java.lang.IllegalArgumentException- Throws:
java.lang.IllegalArgumentException
-
getEntireText
public java.lang.String 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
public TokenOffsetInfo getOffsetInfo(Token token)
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
-
-