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

java.lang.Object
  extended by fr.umlv.tatoo.runtime.buffer.impl.ReaderWrapper
All Implemented Interfaces:
CharacterBuffer, ErrorContextBuffer<LocationErrorContext>, TokenBuffer, CharSequence

public class ReaderWrapper
extends Object
implements TokenBuffer, CharacterBuffer, ErrorContextBuffer<LocationErrorContext>, CharSequence

A ReadWrapper wraps a Reader in order to allow a lexer to process it and a developper to extract tokens recognized.

Version:
$Revision$
Author:
Julien Cervelle
See Also:
Lexer

Constructor Summary
protected ReaderWrapper(int capacity, int increment, Reader reader)
           
  ReaderWrapper(Reader reader)
          Constructs a reader wrapper used by the lexer to process the reader.
 
Method Summary
 char charAt(int index)
           
 void discard()
          Discards all characters already recognized by the lexer.
 int getErrorChar()
           
 LocationErrorContext getErrorContext()
          Returns the context of an error that occurred in the lexer.
 boolean hasRemaining()
           
 int length()
           
 char next()
          Reads the next character from the buffer.
 boolean notEof()
           
 boolean previousWasNewLine()
          Determines if the last unwinded character was an end of line.
 CharSequence subSequence(int start, int end)
           
 String toString()
           
 void unwind(int l)
          Unwinds l characters from the buffer.
 CharSequence view()
          Provides a view of all available tokens.
 CharSequence viewCharacters(int nb)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ReaderWrapper

public ReaderWrapper(Reader reader)
Constructs a reader wrapper used by the lexer to process the reader.

Parameters:
reader - the reader to wrap

ReaderWrapper

protected ReaderWrapper(int capacity,
                        int increment,
                        Reader reader)
Method Detail

unwind

public void unwind(int l)
Description copied from interface: CharacterBuffer
Unwinds l characters from the buffer.

Specified by:
unwind in interface CharacterBuffer
Parameters:
l - the number of characters to unwind

previousWasNewLine

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

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

notEof

public boolean notEof()

hasRemaining

public boolean hasRemaining()

next

public char next()
Description copied from interface: CharacterBuffer
Reads the next character from the buffer. Current position in the buffer is incremented.

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

discard

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

Specified by:
discard in interface TokenBuffer

viewCharacters

public CharSequence viewCharacters(int nb)

view

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

Specified by:
view in interface TokenBuffer
Returns:
a view of all availale tokens

getErrorContext

public LocationErrorContext getErrorContext()
Description copied from interface: ErrorContextBuffer
Returns the context of an error that occurred in the lexer.

Specified by:
getErrorContext in interface ErrorContextBuffer<LocationErrorContext>
Returns:
the error context

getErrorChar

public int getErrorChar()
Specified by:
getErrorChar in interface ErrorContextBuffer<LocationErrorContext>

length

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

charAt

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

subSequence

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

toString

public String toString()
Specified by:
toString in interface CharSequence
Overrides:
toString in class Object