|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgoldengine.java.LookAheadStream
public class LookAheadStream
Copy of original goldengine.java.LookAheadStream,
with modified readLine()
method.
Field Summary | |
---|---|
private int |
bufferPos
|
private java.io.PushbackReader |
buffR
|
private int |
kMaxBufferSize
|
private int |
multiplier
|
private char[] |
unreadme
|
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. |
private void |
doubleArray()
|
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()
As of today, 08/12/2005, Java engine featured on the GOLD site (http://www.devincook.com/goldparser/doc/index.htm#Engine) does NOT handle languages that use EOL as a statement separator (such as VBS). |
private void |
unreadChars(int size)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private java.io.PushbackReader buffR
private char[] unreadme
private final int kMaxBufferSize
private int multiplier
private int bufferPos
Constructor Detail |
---|
public LookAheadStream()
Method Detail |
---|
public boolean openFile(java.lang.String file) throws goldengine.java.ParserException
- 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 goldengine.java.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.
doubleArray
private void doubleArray()
unreadChars
private void unreadChars(int size)
done
public boolean done()
throws goldengine.java.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 goldengine.java.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 goldengine.java.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 goldengine.java.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 goldengine.java.ParserException
- As of today, 08/12/2005, Java engine featured on the GOLD site
(http://www.devincook.com/goldparser/doc/index.htm#Engine) does NOT
handle languages that use EOL as a statement separator (such as VBS). In
particular, lines of code that end with a line comment, such as:
IF x>0 THEN ' X is positive
The workaround is to this method with the following:
public String readLine() throws ParserException {
int charSpace = 0;
boolean endReached = false;
String text = "", ch;
while (!endReached & !done()) {
ch = nextChar();
if (ch.charAt(0) == '\r' || ch.charAt(0) == '\n') {
break;
}
charSpace++;
text += ch;
}
unreadChars(charSpace);
return text;
}
Notice that this does not really readLine, it reads UP TO EOL.
However, the languages for which EOL is whitespace won't care, and the
languages which care about EOL will just get it and handle it
appropriately otherwise. This second behavior is exactly what I needed.
Furthermore, this method is only called in one place -- precisely to
handle line comments. This bug fix may already have made it into that
package by the time you read this. But if not, here you go.
- Throws:
goldengine.java.ParserException
- See Also:
http://www.devincook.com/GOLDParser/engine/java-hawkins/doc/LookAheadStream.html#readLine()
Overview
Package
Class
Use
Tree
Deprecated
Index
Help
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD