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.
-
lineSeparator
- We need to know this to help us out with stupid platforms
that decided to use non-standard line separators.
-
sval
- If the current token is a word it will appear in this variable
-
TT_EOF
- The current token on the stack is the end of file token
-
TT_EOL
- The current token on the stack is the end of line character
-
TT_UNKNOWN
- The current token on the stack is unknown, usually meaning no
valid token has been read yet.
-
TT_WORD
- The current token on the stack is a word.
-
ttype
- This is the current token
-
ParseTool(File)
- Create a parseTool that reads from the supplied file
-
ParseTool(String, Reader)
- Create a parseTool that reads from the supplied stream.
-
getName()
- Return the name of the stream we read from
-
getParamContext()
- Get the parameter hashtable.
-
lineno()
- Determine which line we are on, possibly for reporting errors.
-
main(String[])
- Test harness
-
nextToken()
- Get the next token on the stream.
-
parseChar(char)
- If the current token is the specified character, advance to the
next token.
-
parseEOL()
- Parse end of line character(s).
-
parseLine()
- Parse the rest of the line as a string and return it.
-
parseSpaces()
- skip to the first non-space character
-
parseString()
- Eat a string and return it.
-
parseToEOL()
- Skip all characters up to but not including the next newline
-
parseWhitespace()
- Skip to the next non-whitespace character.
-
parseWord(String)
- Look for the named word, case insensitive.
-
pushBack()
- Push the parseTool back to the previous token.
-
toString()
- A string suitable for use in error messages
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.
TT_WORD
public static final int TT_WORD
- The current token on the stack is a word.
TT_EOF
public static final int TT_EOF
- The current token on the stack is the end of file token
TT_EOL
public static final int TT_EOL
- The current token on the stack is the end of line character
sval
public String sval
- If the current token is a word it will appear in this variable
ttype
public int ttype
- This is the current token
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.
ParseTool
public ParseTool(File in) throws IOException
- Create a parseTool that reads from the supplied file
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.
getName
public final String getName()
- Return the name of the stream we read from
toString
public final String toString()
- A string suitable for use in error messages
- Overrides:
- toString in class Object
parseToEOL
public boolean parseToEOL() throws IOException
- Skip all characters up to but not including the next newline
- Returns:
- whether anything was skipped or not
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
parseSpaces
public boolean parseSpaces() throws IOException
- skip to the first non-space character
- Returns:
- whether anything was skipped
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
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.
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.
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
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
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
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
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.
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.
main
public static void main(String arg[])
- Test harness
All Packages Class Hierarchy This Package Previous Next Index