public class Parser
extends java.lang.Object
| Constructor and Description |
|---|
Parser(java.lang.String string)
Construct a parser.
|
| Modifier and Type | Method and Description |
|---|---|
void |
advance(int numChars)
Advance numChars character positions.
|
void |
appendToToken(char c)
Append the given character to the token buffer.
|
void |
appendToToken(java.lang.String str)
Append the given string to the token buffer.
|
java.lang.String |
currToken()
Get the current token, and reset the token to empty.
|
void |
expect(char expectedChar)
Expect the next character.
|
char |
getc()
Get the next character.
|
int |
getPosition()
Get the current position.
|
java.lang.String |
getPositionInfo()
Get the parsing context as a string, for debugging.
|
java.lang.Object |
getState()
Get the "state object" from the parser (can be used to parse state between parser functions).
|
java.lang.CharSequence |
getSubsequence(int startPosition,
int endPosition)
Return a subsequence of the input string.
|
java.lang.String |
getSubstring(int startPosition,
int endPosition)
Return a substring of the input string.
|
boolean |
hasMore()
Check to see if there are more characters to parse.
|
void |
next()
Advance one character without returning the value of the character.
|
char |
peek()
Peek at the next character without reading it.
|
void |
peekExpect(char expectedChar)
Get the next character, throwing a
ParseException if the next character is not the expected
character. |
boolean |
peekMatches(java.lang.String strMatch)
Peek operator that can look ahead several characters.
|
void |
setPosition(int position)
Set the position of the parser within the string.
|
java.lang.Object |
setState(java.lang.Object state)
Set the "state object" from the parser (can be used to parse state between parser functions).
|
void |
skipWhitespace()
Skip whitespace starting at the current position.
|
java.lang.String |
toString() |
public Parser(java.lang.String string)
throws ParseException
string - The string to parse.ParseException - If the string was null.public java.lang.String getPositionInfo()
public java.lang.Object setState(java.lang.Object state)
state - The state object.public java.lang.Object getState()
public char getc()
throws ParseException
ParseException - If there were no more characters in the string.public void expect(char expectedChar)
throws ParseException
expectedChar - The expected character.ParseException - If the next character was not the expected character.public char peek()
public void peekExpect(char expectedChar)
throws ParseException
ParseException if the next character is not the expected
character.expectedChar - The expected next character.ParseException - If the next character is not the expected next character.public boolean peekMatches(java.lang.String strMatch)
strMatch - The string to compare, starting at the current position, as a "peek" operation.public void next()
public void advance(int numChars)
numChars - The number of character positions to advance.java.lang.IllegalArgumentException - If there are insufficient characters remaining in the string.public boolean hasMore()
public int getPosition()
public void setPosition(int position)
position - The position to move to.java.lang.IllegalArgumentException - If the position is out of range.public java.lang.CharSequence getSubsequence(int startPosition,
int endPosition)
startPosition - The start position.endPosition - The end position.public java.lang.String getSubstring(int startPosition,
int endPosition)
startPosition - The start position.endPosition - The end position.public void appendToToken(java.lang.String str)
str - The string to append.public void appendToToken(char c)
c - The character to append.public void skipWhitespace()
public java.lang.String currToken()
public java.lang.String toString()
toString in class java.lang.Object