net.sf.japaki.text
Class ReaderWithPosition

java.lang.Object
  extended by net.sf.japaki.text.ParseReader
      extended by net.sf.japaki.text.ReaderWithPosition
All Implemented Interfaces:
Closeable, RestorableIO<ParseReader>, PathTracker

public class ReaderWithPosition
extends ParseReader

Default implementation of a ParseReader.


Constructor Summary
ReaderWithPosition(Reader reader)
          Creates a new instance of this class from a reader.
ReaderWithPosition(String fileName)
          Creates a new instance of this class from a file.
 
Method Summary
 void checkForException(String errorMessage)
          Creates a parsing exception with the specified error message.
 void close()
           
 void copyFrom(ParseReader source)
          Sets the status to the same as in the specified ReaderWithPosition.
 ParseReader deepCopy()
          Saves the current settings of this ReaderWithPosition.
 boolean eof()
          Checks if the input stream is at its end.
 boolean eol()
          Checks if the current line is at its end.
 TreeSet<ParsingException> getExceptionLog()
          Returns a list of all exceptions that have occured while parsing.
 Deque<Parser> getPath()
          Returns the path of parsers in the parser network.
 ParsePosition getPosition()
          Returns the current parse position.
 String getSource()
          Returns the current line of the input stream.
 void newLine()
          Forwards to the next line in the input stream.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ReaderWithPosition

public ReaderWithPosition(Reader reader)
                   throws IOException
Creates a new instance of this class from a reader.

Parameters:
reader - base reader for the I/O operations
Throws:
NullPointerException - if reader is null
IOException - if the first line of the reader could not be read

ReaderWithPosition

public ReaderWithPosition(String fileName)
                   throws IOException
Creates a new instance of this class from a file.

Parameters:
fileName - name of the input file
Throws:
IOException - see FileReader.FileReader(String)
Method Detail

getExceptionLog

public TreeSet<ParsingException> getExceptionLog()
Returns a list of all exceptions that have occured while parsing.

Returns:
the exception log
See Also:
checkForException(java.lang.String)

eol

public boolean eol()
Checks if the current line is at its end.

Returns:
true if end of line is reached

getSource

public String getSource()
Description copied from class: ParseReader
Returns the current line of the input stream.

Specified by:
getSource in class ParseReader
Returns:
A string containing the contents of the last line read, not including any line-termination characters, or null if the end of the stream has been reached.
See Also:
BufferedReader.readLine()

getPosition

public ParsePosition getPosition()
Description copied from class: ParseReader
Returns the current parse position.

Specified by:
getPosition in class ParseReader
Returns:
the current parse position

newLine

public void newLine()
             throws IOException,
                    ParseException
Description copied from class: ParseReader
Forwards to the next line in the input stream.

Specified by:
newLine in class ParseReader
Throws:
IOException - if an I/O error occurs
ParseException - if end of current line was not reached

eof

public boolean eof()
Description copied from class: ParseReader
Checks if the input stream is at its end.

Specified by:
eof in class ParseReader
Returns:
true if end of file is reached

checkForException

public void checkForException(String errorMessage)
                       throws ParsingException
Description copied from class: ParseReader
Creates a parsing exception with the specified error message.

Specified by:
checkForException in class ParseReader
Parameters:
errorMessage - message set in the exception
Throws:
ParsingException - if the error index of the parse position is set.

getPath

public Deque<Parser> getPath()
Description copied from interface: PathTracker
Returns the path of parsers in the parser network.

Returns:
the path of parsers in the parser network.

copyFrom

public void copyFrom(ParseReader source)
Sets the status to the same as in the specified ReaderWithPosition.

Parameters:
source - source of the copy operation, normally created from a deepCopy() operation.
Throws:
ClassCastException - if source is not a ReaderWithPosition.

deepCopy

public ParseReader deepCopy()
Saves the current settings of this ReaderWithPosition. copyFrom can be used to restore the settings from the clone.

Returns:
a clone of this object.

close

public void close()
           throws IOException
Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object