fr.umlv.tatoo.runtime.buffer.impl
Class AbstractBufferWrapper

java.lang.Object
  extended by fr.umlv.tatoo.runtime.buffer.impl.AbstractBufferWrapper
All Implemented Interfaces:
LexerBuffer
Direct Known Subclasses:
ByteBufferWrapper, CharBufferWrapper, CharSequenceWrapper, InputStreamWrapper, ReadableByteChannelWrapper, ReadableWrapper, ReaderWrapper

public abstract class AbstractBufferWrapper
extends Object
implements LexerBuffer

Abstract base class for buffer that can tracks line and column position in a text.

Author:
Remi Forax
See Also:
LocationProvider

Constructor Summary
AbstractBufferWrapper(LocationTracker locationTracker)
          Create a buffer with a location tracker.
 
Method Summary
 void discard()
          Discards all characters already recognized by the lexer.
protected abstract  void discardImpl()
           
 LocationTracker getLocationProvider()
          Returns the location tracker.
protected  void locationClear()
          Service method that can be called by the current buffer to update the underlying location tracker.
 int next()
          Reads the next character from the buffer.
protected abstract  int nextImpl()
          Returns next character in buffer without taking care of locations
 void reset()
          Moves current position back to first non unwinded character
protected abstract  void resetImpl()
          Moves current position back to first non unwinded character without taking care of locations
 void restart()
          Moves current position back to first non discarded character
protected abstract  void restartImpl()
           
 void unwind(int count)
          Performs unwind operation on buffer without taking care of locations
protected abstract  void unwindImpl(int count)
          Performs unwind operation on buffer without taking care of locations
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface fr.umlv.tatoo.runtime.buffer.LexerBuffer
hasRemaining, lastChar, previousWasNewLine, read
 

Constructor Detail

AbstractBufferWrapper

public AbstractBufferWrapper(LocationTracker locationTracker)
Create a buffer with a location tracker.

Parameters:
locationTracker - the location tracker may be null
Method Detail

unwindImpl

protected abstract void unwindImpl(int count)
Performs unwind operation on buffer without taking care of locations

Parameters:
count - the number of characters to unwind
See Also:
LexerBuffer.unwind(int)

unwind

public final void unwind(int count)
Performs unwind operation on buffer without taking care of locations

Specified by:
unwind in interface LexerBuffer
Parameters:
count - the number of characters to unwind
See Also:
LexerBuffer.unwind(int)

discardImpl

protected abstract void discardImpl()

discard

public final void discard()
Description copied from interface: LexerBuffer
Discards all characters already recognized by the lexer.

Specified by:
discard in interface LexerBuffer

restartImpl

protected abstract void restartImpl()

restart

public final void restart()
Description copied from interface: LexerBuffer
Moves current position back to first non discarded character

Specified by:
restart in interface LexerBuffer

nextImpl

protected abstract int nextImpl()
Returns next character in buffer without taking care of locations

Returns:
the next character in the buffer
Throws:
IllegalStateException - when called while hasRemaining returns false
See Also:
LexerBuffer.next()

next

public final int next()
Description copied from interface: LexerBuffer
Reads the next character from the buffer. Current position in the buffer is incremented.

Specified by:
next in interface LexerBuffer
Returns:
the next character in the buffer

resetImpl

protected abstract void resetImpl()
Moves current position back to first non unwinded character without taking care of locations

See Also:
LexerBuffer.reset()

reset

public final void reset()
Description copied from interface: LexerBuffer
Moves current position back to first non unwinded character

Specified by:
reset in interface LexerBuffer

locationClear

protected final void locationClear()
Service method that can be called by the current buffer to update the underlying location tracker. This method sets columns and lines numbers to zero.

See Also:
LocationProvider

getLocationProvider

public LocationTracker getLocationProvider()
Returns the location tracker.

Specified by:
getLocationProvider in interface LexerBuffer
Returns:
the location tracker or null if the buffer was initialized with no location tracker.