Methods Summary |
---|
public boolean | atEnd()
return mOffset >= mInput.length();
|
public java.lang.String | eat(java.util.regex.Pattern pattern, java.lang.String tokenName)
String result = tryEat(pattern);
if (result == null) {
throw new RuntimeException(unexpectedTokenMessage(tokenName));
}
return result;
|
public int | lineNo()
return mLineNo;
|
public boolean | peek(java.util.regex.Pattern pattern)
// Skip ignore pattern
if (mIgnorePattern != null) {
skip(mIgnorePattern);
}
// Create the matcher
Matcher matcher = pattern.matcher(mInput);
matcher.region(mOffset, mInput.length());
// Attempt to match
return matcher.lookingAt();
|
public void | skip(java.util.regex.Pattern pattern)
Matcher matcher = pattern.matcher(mInput);
matcher.region(mOffset, mInput.length());
if (matcher.lookingAt()) {
updateLineCount(mOffset, matcher.end());
mOffset = matcher.end();
}
|
public java.lang.String | tryEat(java.util.regex.Pattern pattern)
// Skip ignore pattern
if (mIgnorePattern != null) {
skip(mIgnorePattern);
}
// Create the matcher
Matcher matcher = pattern.matcher(mInput);
matcher.region(mOffset, mInput.length());
// Attempt to match
String result = null;
if (matcher.lookingAt()) {
updateLineCount(mOffset, matcher.end());
mOffset = matcher.end();
result = mInput.substring(matcher.start(), matcher.end());
}
// Skip ignore pattern
if (result != null && mIgnorePattern != null) {
skip(mIgnorePattern);
}
return result;
|
public java.lang.String | unexpectedTokenMessage(java.lang.String tokenName)
String line = mInput.substring(mStartOfLine, mOffset);
return "Unexpected token on line " + (mLineNo + 1) + " after '" + line + "' <- Expected " +
tokenName + "!";
|
public void | updateLineCount(int start, int end)
for (int i = start; i < end; ++i) {
if (mInput.charAt(i) == '\n") {
++mLineNo;
mStartOfLine = i + 1;
}
}
|