antlr

Class TokenStreamSelector

Implemented Interfaces:
IASDebugStream, TokenStream

public class TokenStreamSelector
extends 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

protected TokenStream
input
The currently-selected token stream input
protected Hashtable
inputStreamNames
The set of inputs to the MUX
protected Stack
streamStack
Used to track stack of input streams

Constructor Summary

TokenStreamSelector()

Method Summary

void
addInputStream(TokenStream stream, String key)
TokenStream
getCurrentStream()
Return the stream from tokens are being pulled at the moment.
String
getEntireText()
Returns the entire text input to the lexer.
TokenOffsetInfo
getOffsetInfo(Token token)
Returns the offset information for the token
TokenStream
getStream(String sname)
Token
nextToken()
TokenStream
pop()
void
push(String sname)
void
push(TokenStream stream)
void
retry()
Abort recognition of current Token and try again.
void
select(String sname)
void
select(TokenStream stream)
Set the stream without pushing old stream

Field Details

input

protected TokenStream input
The currently-selected token stream input

inputStreamNames

protected Hashtable inputStreamNames
The set of inputs to the MUX

streamStack

protected Stack streamStack
Used to track stack of input streams

Constructor Details

TokenStreamSelector

public TokenStreamSelector()

Method Details

addInputStream

public void addInputStream(TokenStream stream,
                           String key)

getCurrentStream

public TokenStream getCurrentStream()
Return the stream from tokens are being pulled at the moment.

getEntireText

public String getEntireText()
Returns the entire text input to the lexer.
Specified by:
getEntireText in interface IASDebugStream
Returns:
The entire text or null, if error occured or System.in was used.

getOffsetInfo

public TokenOffsetInfo getOffsetInfo(Token token)
Returns the offset information for the token
Specified by:
getOffsetInfo in interface IASDebugStream
Parameters:
token - the token whose information need to be retrieved
Returns:
offset info, or null

getStream

public TokenStream getStream(String sname)

nextToken

public Token nextToken()
            throws TokenStreamException
Specified by:
nextToken in interface TokenStream

pop

public TokenStream pop()

push

public void push(String sname)

push

public void push(TokenStream stream)

retry

public void retry()
            throws TokenStreamRetryException
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."

select

public void select(String sname)
            throws IllegalArgumentException

select

public void select(TokenStream stream)
Set the stream without pushing old stream