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

java.lang.Object
  extended by fr.umlv.tatoo.runtime.buffer.impl.AbstractBufferWrapper
      extended by fr.umlv.tatoo.runtime.buffer.impl.CharSequenceWrapper
All Implemented Interfaces:
LexerBuffer, TokenBuffer<CharSequence>, CharSequence

public class CharSequenceWrapper
extends AbstractBufferWrapper
implements TokenBuffer<CharSequence>, CharSequence

A CharSequenceWrapper wraps a CharSequence in order to allow a lexer to process its content in order to have its tokens extracted.

Author:
Julien
See Also:
Lexer

Constructor Summary
CharSequenceWrapper(CharSequence seq, LocationTracker tracker)
          Constructs a CharSequenceWrapper which wraps specified CharSequence.
 
Method Summary
 char charAt(int position)
           
protected  void discardImpl()
           
 int getPosition()
           
 CharSequence getSequence()
           
 int getTokenEnd()
           
 int getTokenStart()
           
 boolean hasRemaining()
          Returns true if more characters are availables in the buffer.
 int lastChar()
          Returns last read char or -1 if not available.
 int length()
           
protected  int nextImpl()
          Returns next character in buffer without taking care of locations
 boolean previousWasNewLine()
          Determines if the last unwinded character was an end of line.
 boolean read()
          Reads at some bytes from the stream.
protected  void resetImpl()
          Moves current position back to first non unwinded character without taking care of locations
protected  void restartImpl()
           
 CharSequence subSequence(int start, int end)
           
protected  void unwindImpl(int l)
          Performs unwind operation on buffer without taking care of locations
 CharSequence view()
          Provides a view of all available tokens.
 
Methods inherited from class fr.umlv.tatoo.runtime.buffer.impl.AbstractBufferWrapper
discard, getLocationProvider, locationClear, next, reset, restart, unwind
 
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.TokenBuffer
discard
 
Methods inherited from interface java.lang.CharSequence
toString
 

Constructor Detail

CharSequenceWrapper

public CharSequenceWrapper(CharSequence seq,
                           LocationTracker tracker)
Constructs a CharSequenceWrapper which wraps specified CharSequence.

Parameters:
seq - the CharSequence to wrap
tracker - the location tracker
Method Detail

getPosition

public int getPosition()

getSequence

public CharSequence getSequence()

getTokenStart

public int getTokenStart()

getTokenEnd

public int getTokenEnd()

unwindImpl

protected void unwindImpl(int l)
Description copied from class: AbstractBufferWrapper
Performs unwind operation on buffer without taking care of locations

Specified by:
unwindImpl in class AbstractBufferWrapper
Parameters:
l - the number of characters to unwind
See Also:
LexerBuffer.unwind(int)

resetImpl

protected void resetImpl()
Description copied from class: AbstractBufferWrapper
Moves current position back to first non unwinded character without taking care of locations

Specified by:
resetImpl in class AbstractBufferWrapper
See Also:
LexerBuffer.reset()

previousWasNewLine

public boolean previousWasNewLine()
Description copied from interface: LexerBuffer
Determines if the last unwinded character was an end of line.

Specified by:
previousWasNewLine in interface LexerBuffer
Returns:
true if the last unwinded character was an end of line; false otherwise

hasRemaining

public boolean hasRemaining()
Description copied from interface: LexerBuffer
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.

Specified by:
hasRemaining in interface LexerBuffer
Returns:
true if more characters are availables in the buffer

read

public boolean read()
Description copied from interface: LexerBuffer
Reads at some bytes from the stream. This operation is optionnal and only used by SimpleLexer.run().

Specified by:
read in interface LexerBuffer
Returns:
false at end of stream

nextImpl

protected int nextImpl()
Description copied from class: AbstractBufferWrapper
Returns next character in buffer without taking care of locations

Specified by:
nextImpl in class AbstractBufferWrapper
Returns:
the next character in the buffer
See Also:
LexerBuffer.next()

discardImpl

protected void discardImpl()
Specified by:
discardImpl in class AbstractBufferWrapper

view

public CharSequence view()
Description copied from interface: TokenBuffer
Provides a view of all available tokens. Tokens are not copied from the buffer and thus may change during lexer process.

Specified by:
view in interface TokenBuffer<CharSequence>
Returns:
a view of all available tokens

charAt

public char charAt(int position)
Specified by:
charAt in interface CharSequence

length

public int length()
Specified by:
length in interface CharSequence

subSequence

public CharSequence subSequence(int start,
                                int end)
Specified by:
subSequence in interface CharSequence

lastChar

public int lastChar()
Description copied from interface: LexerBuffer
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

Specified by:
lastChar in interface LexerBuffer
Returns:
last read char or -1 if not available

restartImpl

protected void restartImpl()
Specified by:
restartImpl in class AbstractBufferWrapper