use of org.finos.legend.engine.language.pure.grammar.from.domain.DateParseTreeWalker in project legend-engine by finos.
the class PureCollectionDataParseTreeWalker method visitInstanceLiteral.
private ValueSpecification visitInstanceLiteral(PureCollectionDataParserGrammar.InstanceLiteralContext ctx) {
ValueSpecification result;
if (ctx.instanceLiteralToken() != null) {
PureCollectionDataParserGrammar.InstanceLiteralTokenContext literalToken = ctx.instanceLiteralToken();
if (literalToken.STRING() != null) {
result = cString(PureGrammarParserUtility.fromGrammarString(literalToken.STRING().getText(), true));
} else if (literalToken.INTEGER() != null) {
result = cInteger(Long.parseLong(literalToken.INTEGER().getText()));
} else if (literalToken.FLOAT() != null) {
result = cFloat(Double.parseDouble(literalToken.FLOAT().getText()));
} else if (literalToken.DECIMAL() != null) {
String text = literalToken.DECIMAL().getText();
result = cDecimal(new BigDecimal(text.substring(0, text.length() - 1)));
} else if (literalToken.DATE() != null) {
result = new DateParseTreeWalker(literalToken.DATE(), this.walkerSourceInformation).visitDefinition();
} else if (literalToken.BOOLEAN() != null) {
result = cBoolean(Boolean.parseBoolean(literalToken.BOOLEAN().getText()));
} else if (literalToken.STRICTTIME() != null) {
result = new StrictTimeParseTreeWalker(literalToken.STRICTTIME(), this.walkerSourceInformation).visitStrictTimeDefinition();
} else {
throw new IllegalStateException("Unhandled instanceLiteralToken");
}
} else if (ctx.INTEGER() != null && ctx.MINUS() != null) {
result = cInteger(Long.parseLong(ctx.MINUS().getText() + ctx.INTEGER().getText()));
} else if (ctx.FLOAT() != null && ctx.MINUS() != null) {
result = cFloat(Double.parseDouble(ctx.MINUS().getText() + ctx.FLOAT().getText()));
} else if (ctx.DECIMAL() != null && ctx.MINUS() != null) {
String text = ctx.MINUS().getText() + ctx.DECIMAL().getText();
result = cDecimal(new BigDecimal(text.substring(0, text.length() - 1)));
} else if (ctx.INTEGER() != null && ctx.PLUS() != null) {
result = cInteger(Long.parseLong(ctx.PLUS().getText() + ctx.INTEGER().getText()));
} else if (ctx.FLOAT() != null && ctx.PLUS() != null) {
result = cFloat(Double.parseDouble(ctx.PLUS().getText() + ctx.FLOAT().getText()));
} else if (ctx.DECIMAL() != null && ctx.PLUS() != null) {
String text = ctx.PLUS().getText() + ctx.DECIMAL().getText();
result = cDecimal(new BigDecimal(text.substring(0, text.length() - 1)));
} else {
throw new IllegalStateException("Unhandled instanceLiteral");
}
result.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
return result;
}
Aggregations