private object VisitCast([NotNull] KoraliumParser.Scalar_expressionContext context) { var innerScalar = Visit(context.casted) as ScalarExpression; var toType = context.castedidentifier.Text.ToLower(); return(new CastExpression() { ScalarExpression = innerScalar, ToType = toType }); }
/// <summary> /// Exit a parse tree produced by <see cref="KoraliumParser.scalar_expression"/>. /// <para>The default implementation does nothing.</para> /// </summary> /// <param name="context">The parse tree.</param> public virtual void ExitScalar_expression([NotNull] KoraliumParser.Scalar_expressionContext context) { }
/// <summary> /// Visit a parse tree produced by <see cref="KoraliumParser.scalar_expression"/>. /// <para> /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/> /// on <paramref name="context"/>. /// </para> /// </summary> /// <param name="context">The parse tree.</param> /// <return>The visitor result.</return> public virtual Result VisitScalar_expression([NotNull] KoraliumParser.Scalar_expressionContext context) { return(VisitChildren(context)); }
public override object VisitScalar_expression([NotNull] KoraliumParser.Scalar_expressionContext context) { if (context.inner != null) { return(Visit(context.inner) as ScalarExpression); } if (context.casted != null) { return(VisitCast(context)); } var columnReferenceNode = context.column_reference(); if (columnReferenceNode != null) { return(Visit(columnReferenceNode) as ScalarExpression); } var literalNode = context.literal_value(); if (literalNode != null) { return(Visit(literalNode) as ScalarExpression); } var functionCallNode = context.function_call(); if (functionCallNode != null) { return(Visit(functionCallNode) as ScalarExpression); } var operationTypeNode = context.binary_operation_type(); if (operationTypeNode != null) { var binaryOperationType = operationTypeNode.GetText(); BinaryType binaryType = BinaryType.Add; switch (binaryOperationType) { case "+": binaryType = BinaryType.Add; break; case "-": binaryType = BinaryType.Subtract; break; case "*": binaryType = BinaryType.Multiply; break; case "/": binaryType = BinaryType.Divide; break; case "%": binaryType = BinaryType.Modulo; break; case "&": binaryType = BinaryType.BitwiseAnd; break; case "|": binaryType = BinaryType.BitwiseOr; break; case "^": binaryType = BinaryType.BitwiseXor; break; } return(new BinaryExpression() { Left = Visit(context.left) as ScalarExpression, Right = Visit(context.right) as ScalarExpression, Type = binaryType }); } var variableReferenceNode = context.variable_reference(); if (variableReferenceNode != null) { return(Visit(variableReferenceNode) as VariableReference); } throw new NotImplementedException(); }