fr.umlv.tatoo.runtime.buffer
Interface LexerBuffer

All Known Implementing Classes:
AbstractBufferWrapper, ByteBufferWrapper, CharBufferWrapper, CharSequenceWrapper, InputStreamWrapper, ReadableByteChannelWrapper, ReadableWrapper, ReaderWrapper, UTF8Wrapper

public interface LexerBuffer

A LexerBuffer represents a character stream on which a Lexer can operate. Methods of this interface are internally used by the lexer

Author:
Gilles Roussel
See Also:
Lexer

Method Summary
 void discard()
          Discards all characters already recognized by the lexer.
 LocationProvider getLocationProvider()
          Returns a location provider.
 boolean hasRemaining()
          Returns true if more characters are availables in the buffer.
 int lastChar()
          Returns last read char or -1 if not available.
 int next()
          Reads the next character from the buffer.
 boolean previousWasNewLine()
          Determines if the last unwinded character was an end of line.
 boolean read()
          Reads at some bytes from the stream.
 void reset()
          Moves current position back to first non unwinded character
 void restart()
          Moves current position back to first non discarded character
 void unwind(int count)
          Unwinds count characters from the buffer.
 

Method Detail

getLocationProvider

LocationProvider getLocationProvider()
Returns a location provider.

Returns:
the location provider or null if the buffer has no location provider.

unwind

void unwind(int count)
Unwinds count characters from the buffer. count must not be 0.

Parameters:
count - the number of characters to unwind

reset

void reset()
Moves current position back to first non unwinded character


restart

void restart()
Moves current position back to first non discarded character


previousWasNewLine

boolean previousWasNewLine()
Determines if the last unwinded character was an end of line.

Returns:
true if the last unwinded character was an end of line; false otherwise

lastChar

int lastChar()
Returns last read char or -1 if not available. This method is used for logging and error reporting. This operation is optional since this method can return -1 anytime

Returns:
last read char or -1 if not available

next

int next()
Reads the next character from the buffer. Current position in the buffer is incremented.

Returns:
the next character in the buffer
Throws:
IllegalStateException - when called while hasRemaining returns false

hasRemaining

boolean hasRemaining()
Returns true if more characters are availables in the buffer. If the end of file has been reached and backtracked by lexer this method must return true.

Returns:
true if more characters are availables in the buffer

read

boolean read()
             throws IOException
Reads at some bytes from the stream. This operation is optionnal and only used by SimpleLexer.run().

Returns:
false at end of stream
Throws:
IOException - if an i/o operation failed.
UnsupportedOperationException - if this operation is not supported by the current buffer.

discard

void discard()
Discards all characters already recognized by the lexer.