public static QsiLiteralExpressionNode VisitConstant(ConstantContext context) { switch (context) { case StringLiteralConstantContext literalContext: { return(VisitLiteral(literalContext.stringLiteral())); } case NegativeDecimalLiteralConstantContext literalContext: { var literal = VisitLiteral(literalContext.decimalLiteral()); literal.Value = -(decimal)literal.Value; return(literal); } case PositiveDecimalLiteralConstantContext literalContext: { return(VisitLiteral(literalContext.decimalLiteral())); } case BooleanLiteralConstantContext literalContext: { return(VisitLiteral(literalContext.booleanLiteral())); } case RealLiteralConstantContext literalContext: { var node = new QsiLiteralExpressionNode { Value = decimal.Parse(literalContext.GetText()), Type = QsiDataType.Decimal }; PrimarSqlTree.PutContextSpan(node, literalContext); return(node); } case BitStringConstantContext _: { throw TreeHelper.NotSupportedFeature("Bit string"); } case NullConstantContext _: { return(new QsiLiteralExpressionNode { Value = null, Type = QsiDataType.Null }); } default: throw TreeHelper.NotSupportedTree(context); } }
public static QsiLiteralExpressionNode VisitLiteral(ParserRuleContext context) { QsiDataType literalType; object value; switch (context) { case NullLiteralContext _: literalType = QsiDataType.Null; value = null; break; case StringLiteralContext stringLiteral: { value = string.Join("", stringLiteral.STRING_LITERAL() .Select(l => IdentifierUtility.Unescape(l.GetText()))); literalType = QsiDataType.String; break; } case DecimalLiteralContext _: literalType = QsiDataType.Decimal; value = decimal.Parse(context.GetText()); break; case BooleanLiteralContext _: literalType = QsiDataType.Boolean; value = bool.Parse(context.GetText()); break; default: throw TreeHelper.NotSupportedTree(context); } var node = new QsiLiteralExpressionNode { Value = value, Type = literalType }; PrimarSqlTree.PutContextSpan(node, context); return(node); }