| Constructor and Description |
|---|
ParseContext(String input)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
IllegalArgumentException |
buildException()
Create a generic exception for rejecting the current input.
|
IllegalArgumentException |
buildException(String message)
Create an exception for rejecting the current input.
|
ParseContext |
clone()
Clone this instance.
|
boolean |
equals(Object obj) |
void |
expect(char ch)
Read and advance past the next character, which must match
ch. |
int |
getIndex()
Get the current index into the original input string.
|
String |
getInput()
Get the current input.
|
String |
getOriginalInput()
Get the original input string as passed to the constructor.
|
int |
hashCode() |
boolean |
isEOF()
Determine if we are at the end of the input.
|
Matcher |
matchPrefix(Pattern regex)
Match the current input against the given regular expression and advance past it.
|
Matcher |
matchPrefix(String regex)
Match the current input against the given regular expression and advance past it.
|
char |
peek()
Read, but do not advance past, the next character.
|
char |
read()
Read and advance past the next character.
|
void |
reset()
Reset this instance.
|
void |
setIndex(int index)
Set the current index into the original input string.
|
void |
skipWhitespace()
Skip leading whitespace, if any.
|
String |
toString() |
static String |
truncate(String string,
int len)
Truncate a string with ellipsis if necessary.
|
boolean |
tryLiteral(String prefix)
Determine if the current input starts with the given literal prefix.
|
Matcher |
tryPattern(Pattern regex)
Determine if the current input starts with the given regular expression.
|
Matcher |
tryPattern(String pattern)
Determine if the current input starts with the given regular expression.
|
void |
unread()
Push back the previously read character.
|
public ParseContext(String input)
input - the input string to parseIllegalArgumentException - if input is nullpublic String getOriginalInput()
public String getInput()
public int getIndex()
setIndex(int)public void setIndex(int index)
index - new parse positionIllegalArgumentException - if index is greater than the original string lengthgetIndex()public void reset()
This method just invokes:
setIndex(0)
public Matcher matchPrefix(String regex)
regex - regular expression to match against the current inputMatcher that matched regex against the inputIllegalArgumentException - if the current input does not matchpublic Matcher matchPrefix(Pattern regex)
regex - regular expression to match against the current inputMatcher that matched regex against the inputIllegalArgumentException - if the current input does not matchpublic boolean tryLiteral(String prefix)
prefix - literal string to try to match against the current inputprefixpublic Matcher tryPattern(String pattern)
Matcher; otherwise, return null.pattern - regular expression to match against inputpublic Matcher tryPattern(Pattern regex)
Matcher; otherwise, return null.regex - regular expression to match against inputpublic boolean isEOF()
public char read()
IllegalArgumentException - if there are no more characterspublic char peek()
IllegalArgumentException - if there are no more characterspublic void unread()
IllegalStateException - if the beginning of the original string has been reachedpublic void expect(char ch)
ch.ch - the expected next character of inputIllegalArgumentException - if there are no more characters or the
next character read is not chpublic void skipWhitespace()
Character.isWhitespace(char)public ParseContext clone()
public IllegalArgumentException buildException()
public IllegalArgumentException buildException(String message)
message - problem description, or null for nonepublic static String truncate(String string, int len)
string - original stringlen - maximum length beyond which to truncateCopyright © 2016. All rights reserved.