goldengine.java
Class LookAheadStream


java.lang.Object

  |

  +--goldengine.java.LookAheadStream


public class LookAheadStream
extends java.lang.Object

-------------------------------------------------------------------------------------------
Source File: LookAheadStream.java
Author: Matthew Hawkins
Description: A stream implementation that uses a PushbackReader, to read the source file character by character, and will place characters on a char buffer. This char buffer is then used when a token needs to be read.
-------------------------------------------------------------------------------------------
Revision List

      Author          Version         Description
      ------          -------         -----------
      MPH             1.0             First Issue
      MPH             1.1             Fixed a bug with discarding a line for comments

-------------------------------------------------------------------------------------------
IMPORT: java.io
-------------------------------------------------------------------------------------------


Constructor Summary
LookAheadStream()
           
 
Method Summary
 boolean closeFile()
          closeFile This method will close the source file.
 boolean done()
          done This method checks the next character to see if it is the end of the file.
 java.lang.String nextChar()
          nextChar This method will read one character (int) from the stream.
 boolean nextCharNotWhitespace()
          nextCharNotWhitespace A quick checker method which checks to see if the next character is whitespace.
 boolean openFile(java.lang.String file)
          openFile This method will open the source file to read.
 java.lang.String read(int size)
          read This method will return a String of length size.
 java.lang.String readLine()
          readLine #ver1.1# This method will read characters from the buffer until a line feed or carriage return is found.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LookAheadStream


public LookAheadStream()
Method Detail

openFile


public boolean openFile(java.lang.String file)
                 throws ParserException
openFile This method will open the source file to read.
Parameters:
- name>
Returns:
True if the file was opened. It will not return false, as an exception should be thrown beforehand.
Throws:
ParserException - If the PushbackReader was not initialised.

closeFile


public boolean closeFile()
                  throws ParserException
closeFile This method will close the source file.
Returns:
True if the file was closed. It will not return false, as an exception should be thrown beforehand.
Throws:
ParserException - if the file could not be closed.

done


public boolean done()
             throws ParserException
done This method checks the next character to see if it is the end of the file. If it is not, it will use the functionality of the PushbackReader to push the read character back onto the stream.
Returns:
True if it is the end of file next, false if not.
Throws:
ParserException - if the stream could not be read.

nextCharNotWhitespace


public boolean nextCharNotWhitespace()
                              throws ParserException
nextCharNotWhitespace A quick checker method which checks to see if the next character is whitespace.
Returns:
True if it is not whitespace, false if it is.
Throws:
ParserException - if the stream could not be read.

nextChar


public java.lang.String nextChar()
                          throws ParserException
nextChar This method will read one character (int) from the stream.
Returns:
It will return the character as a String, unless it is the end of string, where it will return the character represented by the int "2".
Throws:
ParserException - if the stream could not be read.

read


public java.lang.String read(int size)
                      throws ParserException
read This method will return a String of length size. The String is contained in the buffer of read characters.
Parameters:
size - The number of characters to read from the buffer.
Returns:
The String created from the buffer.
Throws:
ParserException - if the stream could not be read.

readLine


public java.lang.String readLine()
                          throws ParserException
readLine #ver1.1# This method will read characters from the buffer until a line feed or carriage return is found. This means characters should be read using nextChar first to place them on the buffer. This method had a bug where the end of the line could not be found.
Returns:
The String of characters in the buffer.
Throws:
ParserException - if the stream could not be read.