All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class org.webmacro.engine.ParseTool

java.lang.Object
   |
   +----org.webmacro.engine.ParseTool

public final class ParseTool
extends Object
Tokenizes WebMacro template files. It is an wrapper around a StreamTokenizer that's configured to tokenize the kinds of symbols that appear in WebMacro template files.

It also provides several utility functions that make it convenient to parse stuch files.

All characters are word characters except: {}();.=#&@$ space and newline which are "ordinary"--meaning they can be returned as token types.

The parseTool also has the property that it returns unique strings only: If two strings returned by the parseTool are .equals equivalent, then they are also == equivalent.

Furthermore, unlike StreamTokenizer, the pushback method for this ParseTool works for strings as well as regular tokens.


Variable Index

 o lineSeparator
We need to know this to help us out with stupid platforms that decided to use non-standard line separators.
 o sval
If the current token is a word it will appear in this variable
 o TT_EOF
The current token on the stack is the end of file token
 o TT_EOL
The current token on the stack is the end of line character
 o TT_UNKNOWN
The current token on the stack is unknown, usually meaning no valid token has been read yet.
 o TT_WORD
The current token on the stack is a word.
 o ttype
This is the current token

Constructor Index

 o ParseTool(File)
Create a parseTool that reads from the supplied file
 o ParseTool(String, Reader)
Create a parseTool that reads from the supplied stream.

Method Index

 o getName()
Return the name of the stream we read from
 o getParamContext()
Get the parameter hashtable.
 o lineno()
Determine which line we are on, possibly for reporting errors.
 o main(String[])
Test harness
 o nextToken()
Get the next token on the stream.
 o parseChar(char)
If the current token is the specified character, advance to the next token.
 o parseEOL()
Parse end of line character(s).
 o parseLine()
Parse the rest of the line as a string and return it.
 o parseSpaces()
skip to the first non-space character
 o parseString()
Eat a string and return it.
 o parseToEOL()
Skip all characters up to but not including the next newline
 o parseWhitespace()
Skip to the next non-whitespace character.
 o parseWord(String)
Look for the named word, case insensitive.
 o pushBack()
Push the parseTool back to the previous token.
 o toString()
A string suitable for use in error messages

Variables

 o TT_UNKNOWN
 public static final int TT_UNKNOWN
The current token on the stack is unknown, usually meaning no valid token has been read yet. The ParseTool begins in this state.

 o TT_WORD
 public static final int TT_WORD
The current token on the stack is a word.

 o TT_EOF
 public static final int TT_EOF
The current token on the stack is the end of file token

 o TT_EOL
 public static final int TT_EOL
The current token on the stack is the end of line character

 o sval
 public String sval
If the current token is a word it will appear in this variable

 o ttype
 public int ttype
This is the current token

 o lineSeparator
 public static final String lineSeparator
We need to know this to help us out with stupid platforms that decided to use non-standard line separators. I'm not in general hostile towards mac/nt, except in cases like this where they cause me to do unnecessary work.

Constructors

 o ParseTool
 public ParseTool(File in) throws IOException
Create a parseTool that reads from the supplied file

 o ParseTool
 public ParseTool(String name,
                  Reader inputStream)
Create a parseTool that reads from the supplied stream. The supplied name is used in error messages, to identify the source of the input.

Methods

 o getName
 public final String getName()
Return the name of the stream we read from

 o toString
 public final String toString()
A string suitable for use in error messages

Overrides:
toString in class Object
 o parseToEOL
 public boolean parseToEOL() throws IOException
Skip all characters up to but not including the next newline

Returns:
whether anything was skipped or not
 o parseEOL
 public boolean parseEOL() throws IOException
Parse end of line character(s). Same as parseChar('\n'); OS dependent line separators are always converted to the single character \n.

Returns:
true if \n found, false otherwise
 o parseSpaces
 public boolean parseSpaces() throws IOException
skip to the first non-space character

Returns:
whether anything was skipped
 o parseWhitespace
 public boolean parseWhitespace() throws IOException
Skip to the next non-whitespace character. Whitespace is either a space or a newline.

Returns:
whether anything was skipped
 o parseChar
 public boolean parseChar(char c) throws IOException
If the current token is the specified character, advance to the next token.

Returns:
whether the character was eaten.
 o parseString
 public String parseString() throws IOException
Eat a string and return it. If the current token is not a string token, do not eat it, and return null.

Returns:
the word eaten, or null if the next token is not a word.
 o parseWord
 public boolean parseWord(String word) throws IOException
Look for the named word, case insensitive. If the current token matches that word advance the token and return the word; otherwise do not advance the token and return null

Parameters:
word - the word we are looking for
Returns:
s whether or not we found it
 o pushBack
 public void pushBack() throws ParseException
Push the parseTool back to the previous token. This only works once per token, and if you attempt to call it twice you will get a ParseException.

This pushback, unlike StreamTokenizer's, will correctly reset the sval variable if it pushes back to a word token.

Throws: ParseException
on attempt to push back twice
 o nextToken
 public final int nextToken() throws IOException
Get the next token on the stream. If it is a word, set sval. Either way the value of ttype will be set to the current token, which is also returned.

Returns:
the new value of ttype
 o lineno
 public final int lineno()
Determine which line we are on, possibly for reporting errors.

Returns:
the line of input that the current token is on
 o parseLine
 public final String parseLine() throws IOException
Parse the rest of the line as a string and return it. Every character up until the newline will be eaten and added to the string.

It WILL eat the newline, and append it to the string it returns.

 o getParamContext
 public final Hashtable getParamContext()
Get the parameter hashtable. This can be used to store static data values during parse. In the template parse, this is used to store the template parameters.

 o main
 public static void main(String arg[])
Test harness


All Packages  Class Hierarchy  This Package  Previous  Next  Index