org.codehaus.groovy.syntax
Class AbstractTokenStream

java.lang.Object
  extended byorg.codehaus.groovy.syntax.AbstractTokenStream
All Implemented Interfaces:
TokenStream
Direct Known Subclasses:
LexerTokenStream

public abstract class AbstractTokenStream
extends java.lang.Object
implements TokenStream

Provides the common code for TokenStream implementations.


Constructor Summary
AbstractTokenStream()
          Default constructor.
AbstractTokenStream(java.lang.String sourceLocator)
          Initializes the stream with information about the source.
 
Method Summary
 boolean atEnd()
          A synonym for atEnd(true).
 boolean atEnd(boolean ignoringWhitespace)
          Returns true if the stream is out of tokens.
 void checkpoint()
          Saves the look-ahead state for restore()ing later.
 Token consume(int type)
          Removes and returns the first token in the stream, provided it matches the specified type.
 java.lang.String getSourceLocator()
          Returns a description of the source (typically a file name).
 Token la()
          Returns the next token in the stream without consuming it.
 Token la(int k)
          Returns the kth token in the stream without consuming it (or any other unconsumed tokens).
protected abstract  Token nextToken()
          Implemented by concrete subtypes, provides access to the next token in the underlying stream.
 void restore()
          Restores the look-ahead state saved by checkpoint().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractTokenStream

public AbstractTokenStream()
Default constructor.


AbstractTokenStream

public AbstractTokenStream(java.lang.String sourceLocator)
Initializes the stream with information about the source.

Method Detail

getSourceLocator

public java.lang.String getSourceLocator()
Returns a description of the source (typically a file name).

Specified by:
getSourceLocator in interface TokenStream

nextToken

protected abstract Token nextToken()
                            throws ReadException,
                                   SyntaxException
Implemented by concrete subtypes, provides access to the next token in the underlying stream.

Throws:
ReadException
SyntaxException

la

public Token la()
         throws ReadException,
                SyntaxException
Returns the next token in the stream without consuming it.

Specified by:
la in interface TokenStream
Returns:
The next token or null if no more tokens available.
Throws:
ReadException - If an error occurs attempting to lookahead a token.
SyntaxException
See Also:
TokenStream.la(int)

la

public Token la(int k)
         throws ReadException,
                SyntaxException
Returns the kth token in the stream without consuming it (or any other unconsumed tokens).

Specified by:
la in interface TokenStream
Parameters:
k - Number of token to look ahead.
Returns:
the kth token or null if no more tokens available.
Throws:
ReadException - If an error occurs attempting to lookahead a token.
SyntaxException

consume

public Token consume(int type)
              throws ReadException,
                     SyntaxException
Removes and returns the first token in the stream, provided it matches the specified type.

Specified by:
consume in interface TokenStream
Parameters:
type - The token type.
Returns:
The consumed token or null if no more tokens available.
Throws:
ReadException - If an error occurs attempting to consume a token.
SyntaxException

checkpoint

public void checkpoint()
Saves the look-ahead state for restore()ing later.

Specified by:
checkpoint in interface TokenStream

restore

public void restore()
Restores the look-ahead state saved by checkpoint().

Specified by:
restore in interface TokenStream

atEnd

public boolean atEnd(boolean ignoringWhitespace)
Returns true if the stream is out of tokens.

Specified by:
atEnd in interface TokenStream

atEnd

public boolean atEnd()
A synonym for atEnd(true).

Specified by:
atEnd in interface TokenStream


Copyright © 2003-2004 The Codehaus. All Rights Reserved.