tokens.consume(')');
return new ParenthesizedExpression(expr);
}
protected Literal parseNumericLiteral( TokenStream tokens ) {
Position pos = tokens.nextPosition();
String sign = "";
if (tokens.canConsume('-')) sign = "-";
else if (tokens.canConsume('+')) sign = "";
// Try to parse this value as a number ...
String number = tokens.consume();
if (number.indexOf(".") != -1) {
String value = sign + number;
if (value.endsWith("e") && (tokens.matches('+') || tokens.matches('-'))) {
// There's more to the number ...
value = value + tokens.consume() + tokens.consume(); // +/-EXP
}
try {
// Convert to a double and then back to a string to get canonical form ...
String canonical = typeSystem.getDoubleFactory().asString(value);
return new Literal(canonical);
} catch (ValueFormatException e) {
String msg = GraphI18n.expectingLiteralAndUnableToParseAsDouble.text(value, pos.getLine(), pos.getColumn());
throw new ParsingException(pos, msg);
}
}
// try to parse an a long ...
String value = sign + number;
try {
// Convert to a long and then back to a string to get canonical form ...
String canonical = typeSystem.getLongFactory().asString(value);
return new Literal(canonical);
} catch (ValueFormatException e) {
String msg = GraphI18n.expectingLiteralAndUnableToParseAsLong.text(value, pos.getLine(), pos.getColumn());
throw new ParsingException(pos, msg);
}
}