public final class ParserContext
extends java.lang.Object
| Constructor and Description |
|---|
ParserContext(java.lang.String input)
Initialize a new parser context from the given input string.
|
| Modifier and Type | Method and Description |
|---|---|
void |
advance(int amount)
Consume the given number of characters.
|
java.lang.String |
chopFront(int length)
Consume length characters from the input string, return them in a newly constructed
string.
|
void |
commit()
Drop the last snapshot, use the currently valid parser state.
|
int |
indexOf(char c)
Returns first index of a given character in the remaining part of the input string.
|
char |
peekChar(int offset)
Look-ahead at the input string.
|
char |
peekCharUnchecked(int offset)
Same as
peekChar(int), but doesn't check for the end of the string. |
int |
remainingLength() |
void |
revert()
Reverts to the last valid snapshot.
|
void |
snapshot()
Take a snapshot of the current state of the parser.
|
boolean |
startsWith(java.lang.String prefix)
Tests whether the current state starts with the given string.
|
public ParserContext(java.lang.String input)
input - The input string to parse.public void snapshot()
public void commit()
public void revert()
public char peekChar(int offset)
throws java.io.EOFException
offset - The number of characters that should be skipped. E.g. 0 means look at the
currently parsed character.java.io.EOFException - When the read attempts to read anything past the end of the input string.public char peekCharUnchecked(int offset)
peekChar(int), but doesn't check for the end of the string. Useful in loops
bounded by remainingLength() to avoid the need for a try-catch block.offset - The offset of the character to look at.public void advance(int amount)
amount - The number of characters to consider parsed.public int remainingLength()
public java.lang.String chopFront(int length)
length - The number of characters to consume from the beginning. (The method just calls
advance(int) internally with this number.)public boolean startsWith(java.lang.String prefix)
prefix - The prefix we are checking for.public int indexOf(char c)
c - The character to search for.