FileDocCategorySizeDatePackage
TokenStreamSelector.javaAPI DocGlassfish v2 API3173Wed Aug 30 15:34:12 BST 2006persistence.antlr

TokenStreamSelector

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

Fields Summary
protected Hashtable
inputStreamNames
The set of inputs to the MUX
protected TokenStream
input
The currently-selected token stream input
protected Stack
streamStack
Used to track stack of input streams
Constructors Summary
public TokenStreamSelector()


      
        super();
        inputStreamNames = new Hashtable();
    
Methods Summary
public voidaddInputStream(persistence.antlr.TokenStream stream, java.lang.String key)

        inputStreamNames.put(key, stream);
    
public persistence.antlr.TokenStreamgetCurrentStream()
Return the stream from tokens are being pulled at the moment.

        return input;
    
public persistence.antlr.TokenStreamgetStream(java.lang.String sname)

        TokenStream stream = (TokenStream)inputStreamNames.get(sname);
        if (stream == null) {
            throw new IllegalArgumentException("TokenStream " + sname + " not found");
        }
        return stream;
    
public persistence.antlr.TokennextToken()

        // return input.nextToken();
        // keep looking for a token until you don't
        // get a retry exception.
        for (; ;) {
            try {
                return input.nextToken();
            }
            catch (TokenStreamRetryException r) {
                // just retry "forever"
            }
        }
    
public persistence.antlr.TokenStreampop()

        TokenStream stream = (TokenStream)streamStack.pop();
        select(stream);
        return stream;
    
public voidpush(persistence.antlr.TokenStream stream)

        streamStack.push(input); // save current stream
        select(stream);
    
public voidpush(java.lang.String sname)

        streamStack.push(input);
        select(sname);
    
public voidretry()
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."

        throw new TokenStreamRetryException();
    
public voidselect(persistence.antlr.TokenStream stream)
Set the stream without pushing old stream

        input = stream;
    
public voidselect(java.lang.String sname)

        input = getStream(sname);