use of org.beetl.core.parser.BeetlParser.BooleanLiteralContext in project beetl2.0 by javamonkey.
the class AntlrProgramBuilder method parseLiteralExpress.
protected Expression parseLiteralExpress(LiteralContext ctx) {
ParseTree tree = ctx.getChild(0);
Object value = null;
if (tree instanceof TerminalNode) {
Token node = ((TerminalNode) tree).getSymbol();
String strValue = node.getText();
int type = node.getType();
switch(type) {
case BeetlParser.StringLiteral:
value = getStringValue(strValue);
break;
case BeetlParser.FloatingPointLiteral:
char c = strValue.charAt(strValue.length() - 1);
if (isHighScaleNumber(strValue)) {
String newValue = strValue.substring(0, strValue.length() - 1);
value = new BigDecimal(newValue);
} else {
value = Double.parseDouble(strValue);
}
break;
case BeetlParser.DecimalLiteral:
if (isHighScaleNumber(strValue)) {
String newValue = strValue.substring(0, strValue.length() - 1);
value = new BigDecimal(newValue);
} else {
if (strValue.length() < 10) {
value = Integer.parseInt(strValue);
} else if (strValue.length() > 10) {
value = Long.parseLong(strValue);
} else if (strValue.compareTo("2147483647") > 0) {
value = Long.parseLong(strValue);
} else {
value = Integer.parseInt(strValue);
}
}
break;
case BeetlParser.NULL:
value = null;
break;
}
} else {
BooleanLiteralContext blc = (BooleanLiteralContext) tree;
String strValue = blc.getChild(0).getText();
value = Boolean.parseBoolean(strValue);
}
if (value == null) {
return Literal.NULLLiteral;
} else {
Literal literal = new Literal(value, this.getBTToken(ctx.getStart()));
return literal;
}
}
Aggregations