gshute.ioutil
Class LineScanner

java.lang.Object
  |
  +--gshute.ioutil.LineScanner

public class LineScanner
extends java.lang.Object

An object of class LineScanner scans text, breaking it up into tokens.


Field Summary
protected  int currentPosition
          currentPosition is the beginning position in text of currentToken.
protected  java.lang.StringBuffer currentToken
          currentToken is a StringBuffer containing the current token of this LineScanner.
protected  int currentTokenEnd
          currentTokenEnd the end position in text of currentToken.
protected  int currentType
          currentType is the type of currentToken.
static int ECHO
           
protected  int echoPolicy
          echoPolicy determines if this LineScanner echoes lines before printing errors.
protected  java.util.Vector errors
          errors is a Vector of errors that have been recorded in this LineScanner.
static int NO_ECHO
           
protected static int t_end
           
protected static int t_escape_error
           
protected static int t_float
           
protected static int t_int
           
protected static int t_string
           
protected static int t_unmatched
          These are the token type constants.
protected  java.lang.String text
          text is the text that this LineScanner is reading.
protected  int textLength
          textLength is the length of text.
 
Constructor Summary
LineScanner(java.lang.String str, int echoPol)
          new LineScanner(str, echoPol) returns a new LineScanner for scanning str.
LineScanner(java.lang.String str, int echoPol, int skip)
          new LineScanner(str, echoPol, skip) returns a new LineScanner for scanning str.
 
Method Summary
 void addError(java.lang.String msg)
          ls.addError(msg) adds msg to the error list for ls.
 void advance()
          ls.advance() advances the current position in ls.
 boolean atChar()
          ls.atChar() returns true if the token at the current position of ls is a character.
 boolean atEnd()
          ls.atEnd() returns true if the current position of ls is at the end of the line.
 boolean atFloat()
          ls.atFloat() returns true if the token at the current position of ls is a float.
 boolean atInt()
          ls.atInt() returns true if the token at the current position of ls is an int.
 boolean atString()
          ls.atString() returns true if the token at the current position of ls is a string.
protected  void classifyToken()
          ls.classifyToken() sets currentType to the type of the current token of ls.
protected  void copyToken()
          copyToken() copies the current token of this LineScanner into currentToken and sets currentTokenEnd to the position just beyond the end of the current token string.
 char currentChar()
          ls.currentChar() returns the string value of the current token of ls.
 float currentFloat()
          ls.currentFloat() returns the float value of the current token of ls.
 int currentInt()
          ls.currentInt() returns the int value of the current token of ls.
 java.lang.String currentString()
          ls.currentString() returns the string value of the current token of ls.
 int errorCount()
          ls.errorCount() returns the number of error messages in ls.
 int getEchoPolicy()
          ls.getEchoPolicy(echoPol) returns the echo policy of ls.
 java.lang.String getText()
          ls.getText(echoPol) returns the text of ls.
protected  int getToMatch(int pos)
          getToMatch(pos) returns the position in text of the character just beyond the first unescaped match for the character at pos.
 void printAllErrors()
          ls.printAllErrors() prints all of the error messages in ls to System.out.
protected  void printError(int i)
          ls.printError(i) prints the i-th error message in ls to stdout.
 void printFirstError()
          ls.printFirstError() prints the first error message in ls to System.out, if there is one.
 char readChar()
          ls.readChar() returns the character value of the current token of ls, then advances the current position.
 void readEnd()
          ls.readEnd() records an error message in ls if the current position of ls is not at the end of the line.
 float readFloat()
          ls.readFloat() returns the float value of the current token of ls, then advances the current position.
 int readInt()
          ls.readInt() returns the int value of the current token of ls, then advances the current position.
 java.lang.String readString()
          ls.readString() returns the string value of the current token of ls, then advances the current position.
 void removeLastError()
          ls.removeLastError() removes the last error message from ls.
 void setEchoPolicy(int echoPol)
          ls.setEchoPolicy(echoPol) changes the echo policy of ls to echoPol.
 void setText(java.lang.String str)
          ls.setText(str) resets ls in preparation for scanning str.
 void setText(java.lang.String str, int skip)
          ls.setText(str, skip) resets ls in preparation for scanning str.
protected  int translateEscapeCharacter(int pos)
          translateEscapeCharacter(pos) appends the translation for the escape sequence at pos to currentToken and returns the position just beyond the escape sequence.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_ECHO

public static final int NO_ECHO

ECHO

public static final int ECHO

text

protected java.lang.String text
text is the text that this LineScanner is reading.

textLength

protected int textLength
textLength is the length of text.

currentToken

protected java.lang.StringBuffer currentToken
currentToken is a StringBuffer containing the current token of this LineScanner.

currentType

protected int currentType
currentType is the type of currentToken.

currentPosition

protected int currentPosition
currentPosition is the beginning position in text of currentToken.

currentTokenEnd

protected int currentTokenEnd
currentTokenEnd the end position in text of currentToken.

echoPolicy

protected int echoPolicy
echoPolicy determines if this LineScanner echoes lines before printing errors.

errors

protected java.util.Vector errors
errors is a Vector of errors that have been recorded in this LineScanner.

t_unmatched

protected static final int t_unmatched
These are the token type constants.

t_escape_error

protected static final int t_escape_error

t_string

protected static final int t_string

t_float

protected static final int t_float

t_int

protected static final int t_int

t_end

protected static final int t_end
Constructor Detail

LineScanner

public LineScanner(java.lang.String str,
                   int echoPol,
                   int skip)
new LineScanner(str, echoPol, skip) returns a new LineScanner for scanning str. The new LineScanner uses echoPol to determine echo policy for error messages. This parameter should have one of the values LineScanner.ECHO or LineScanner.NO_ECHO. The parameter skip specifies the number of characters to skip in str before scanning.

LineScanner

public LineScanner(java.lang.String str,
                   int echoPol)
new LineScanner(str, echoPol) returns a new LineScanner for scanning str. The new LineScanner uses echoPol to determine echo policy for error messages. This parameter should have one of the values LineScanner.ECHO or LineScanner.NO_ECHO.
Method Detail

setText

public void setText(java.lang.String str,
                    int skip)
ls.setText(str, skip) resets ls in preparation for scanning str. The echo policy of ls is not changed. The parameter skip specifies the number of characters to skip in str befor scanning.

setText

public void setText(java.lang.String str)
ls.setText(str) resets ls in preparation for scanning str. The echo policy of ls is not changed.

setEchoPolicy

public void setEchoPolicy(int echoPol)
ls.setEchoPolicy(echoPol) changes the echo policy of ls to echoPol. This parameter should have one of the values LineScanner.ECHO or LineScanner.NO_ECHO.

getText

public java.lang.String getText()
ls.getText(echoPol) returns the text of ls.

getEchoPolicy

public int getEchoPolicy()
ls.getEchoPolicy(echoPol) returns the echo policy of ls.

readString

public java.lang.String readString()
ls.readString() returns the string value of the current token of ls, then advances the current position. If an error occurs, a message is recorded in ls. Error messages: Unterminated quote. String expected.

readChar

public char readChar()
ls.readChar() returns the character value of the current token of ls, then advances the current position. If an error occurs, a message is recorded in ls. Error messages: Unterminated quote. Character expected.

readFloat

public float readFloat()
ls.readFloat() returns the float value of the current token of ls, then advances the current position. If an error occurs, a message is recorded in ls. Error messages: Real number expected.

readInt

public int readInt()
ls.readInt() returns the int value of the current token of ls, then advances the current position. If an error occurs, a message is recorded in ls. Error messages: Integer expected.

readEnd

public void readEnd()
ls.readEnd() records an error message in ls if the current position of ls is not at the end of the line. Error messages: No more arguments expected.

atString

public boolean atString()
ls.atString() returns true if the token at the current position of ls is a string.

atChar

public boolean atChar()
ls.atChar() returns true if the token at the current position of ls is a character.

atFloat

public boolean atFloat()
ls.atFloat() returns true if the token at the current position of ls is a float.

atInt

public boolean atInt()
ls.atInt() returns true if the token at the current position of ls is an int.

atEnd

public boolean atEnd()
ls.atEnd() returns true if the current position of ls is at the end of the line.

currentString

public java.lang.String currentString()
ls.currentString() returns the string value of the current token of ls. If an error occurs, a message is recorded in ls. Preconditions: ls.atString() is true.

currentChar

public char currentChar()
ls.currentChar() returns the string value of the current token of ls. If an error occurs, a message is recorded in ls. Preconditions: ls.atChar() is true.

currentFloat

public float currentFloat()
ls.currentFloat() returns the float value of the current token of ls. If an error occurs, a message is recorded in ls. Preconditions: ls.atFloat() is true.

currentInt

public int currentInt()
ls.currentInt() returns the int value of the current token of ls. If an error occurs, a message is recorded in ls. Preconditions: ls.atInt() is true.

advance

public void advance()
ls.advance() advances the current position in ls. Preconditions: ls.atEnd() is false.

errorCount

public int errorCount()
ls.errorCount() returns the number of error messages in ls.

addError

public void addError(java.lang.String msg)
ls.addError(msg) adds msg to the error list for ls. The position for this error is the current position of ls.

removeLastError

public void removeLastError()
ls.removeLastError() removes the last error message from ls. Preconditions: ls.errorCount() > 0.

printFirstError

public void printFirstError()
ls.printFirstError() prints the first error message in ls to System.out, if there is one.

printAllErrors

public void printAllErrors()
ls.printAllErrors() prints all of the error messages in ls to System.out.

copyToken

protected void copyToken()
copyToken() copies the current token of this LineScanner into currentToken and sets currentTokenEnd to the position just beyond the end of the current token string.

getToMatch

protected int getToMatch(int pos)
getToMatch(pos) returns the position in text of the character just beyond the first unescaped match for the character at pos.

translateEscapeCharacter

protected int translateEscapeCharacter(int pos)
translateEscapeCharacter(pos) appends the translation for the escape sequence at pos to currentToken and returns the position just beyond the escape sequence.

classifyToken

protected void classifyToken()
ls.classifyToken() sets currentType to the type of the current token of ls.

printError

protected void printError(int i)
ls.printError(i) prints the i-th error message in ls to stdout.