/** gets a token and throws an exception if it is not <tt>code</tt> */
private void consume(int code) throws IOException {
- if (getToken() != code) throw new ParserException("expected " + codeToString[code] + ", got " + (op == -1 ? "EOF" : codeToString[op]));
+ if (getToken() != code) throw pe("expected " + codeToString[code] + ", got " + (op == -1 ? "EOF" : codeToString[op]));
}
/**
CompiledFunctionImpl b = appendTo;
switch (tok) {
- case -1: throw new ParserException("expected expression");
+ case -1: throw pe("expected expression");
// all of these simply push values onto the stack
case NUMBER: b.add(parserLine, LITERAL, number); break;
case INC: case DEC: { // prefix (not postfix)
startExpr(b, precedence[tok]);
if (b.get(b.size() - 1) != GET)
- throw new ParserException("prefixed increment/decrement can only be performed on a valid assignment target");
+ throw pe("prefixed increment/decrement can only be performed on a valid assignment target");
b.set(b.size() - 1, tok, new Boolean(true));
break;
}
if (peekToken() != RC)
while(true) {
if (peekToken() != NAME && peekToken() != STRING)
- throw new ParserException("expected NAME or STRING");
+ throw pe("expected NAME or STRING");
getToken();
b.add(parserLine, LITERAL, string); // grab the key
consume(COLON);
break;
}
- default: throw new ParserException("expected expression, found " + codeToString[tok] + ", which cannot start an expression");
+ default: throw pe("expected expression, found " + codeToString[tok] + ", which cannot start an expression");
}
// attempt to continue the expression
b.add(parserLine, BREAK); // break out of the loop if we 'fall through'
break;
} else {
- throw new ParserException("expected CASE, DEFAULT, or RC; got " + codeToString[peekToken()]);
+ throw pe("expected CASE, DEFAULT, or RC; got " + codeToString[peekToken()]);
}
b.set(size0 - 1, new Integer(b.size() - size0 + 1)); // end of the loop
break;
// ParserException //////////////////////////////////////////////////////////////////////
-
- private class ParserException extends IOException { public ParserException(String s) { super(sourceName + ":" + parserLine + " " + s); } }
+ private IOException pe(String s) { return new IOException(sourceName + ":" + parserLine + " " + s); }
}