コード例 #1
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="KoraliumParser.literal_value"/>.
 /// <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 VisitLiteral_value([NotNull] KoraliumParser.Literal_valueContext context)
 {
     return(VisitChildren(context));
 }
コード例 #2
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="KoraliumParser.literal_value"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitLiteral_value([NotNull] KoraliumParser.Literal_valueContext context)
 {
 }
コード例 #3
0
        public override object VisitLiteral_value([NotNull] KoraliumParser.Literal_valueContext context)
        {
            if (context.NULL() != null)
            {
                return(new NullLiteral());
            }

            var value = context.GetText();

            //Its a string literal
            if (context.STRING_LITERAL() != null)
            {
                value = value.Trim('\'');
                return(new StringLiteral()
                {
                    Value = value
                });
            }
            if (context.NUMERIC_LITERAL() != null)
            {
                if (decimal.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var val))
                {
                    if ((val % 1) == 0)
                    {
                        return(new IntegerLiteral()
                        {
                            Value = (long)val
                        });
                    }
                    else
                    {
                        return(new NumericLiteral()
                        {
                            Value = val
                        });
                    }
                }
                else
                {
                    throw new SqlParserException($"Unmatched literal: {value}");
                }
            }

            if (context.TRUE() != null)
            {
                return(new BooleanLiteral()
                {
                    Value = true
                });
            }

            if (context.FALSE() != null)
            {
                return(new BooleanLiteral()
                {
                    Value = false
                });
            }

            throw new NotImplementedException();
        }