Esempio n. 1
0
        public PatternUst VisitLiteral(DslParser.LiteralContext context)
        {
            PatternUst result;
            var        textSpan = context.GetTextSpan();

            if (context.Id() != null)
            {
                result = ProcessId(context.Id());
            }
            else if (context.String() != null)
            {
                result = new PatternStringLiteral(RemoveQuotes(context.GetText()), textSpan);
            }
            else if (context.Oct() != null)
            {
                result = new PatternIntLiteral(
                    System.Convert.ToInt64(context.Oct().GetText(), 8), textSpan);
            }
            else if (context.Int() != null)
            {
                string text = context.Int().GetText();
                if (long.TryParse(text, out long longValue))
                {
                    result = new PatternIntLiteral(longValue, textSpan);
                }
                else
                {
                    result = new PatternBigIntLiteral(longValue, textSpan);
                }
            }
            else if (context.Hex() != null)
            {
                result = new PatternIntLiteral(
                    System.Convert.ToInt64(context.Hex().GetText(), 16), textSpan);
            }
            else if (context.Bool() != null)
            {
                result = new PatternBooleanLiteral(bool.Parse(context.Bool().GetText()), textSpan);
            }
            else if (context.Null() != null)
            {
                result = new PatternNullLiteral(textSpan);
            }
            else
            {
                throw new NotImplementedException();
            }
            return(result);
        }
Esempio n. 2
0
        public UstNode VisitLiteral(DslParser.LiteralContext context)
        {
            Token result;
            var   textSpan = context.GetTextSpan();

            if (context.Id() != null)
            {
                result = ProcessId(context.Id());
            }
            else if (context.String() != null)
            {
                result = new StringLiteral(RemoveQuotes(context.GetText()), textSpan, null);
            }
            else if (context.Oct() != null)
            {
                result = new IntLiteral(
                    System.Convert.ToInt64(context.Oct().GetText(), 8), textSpan, null);
            }
            else if (context.Int() != null)
            {
                result = new IntLiteral(long.Parse(context.Int().GetText()), textSpan, null);
            }
            else if (context.Hex() != null)
            {
                result = new IntLiteral(
                    System.Convert.ToInt64(context.Hex().GetText(), 16), textSpan, null);
            }
            else if (context.Bool() != null)
            {
                result = new BooleanLiteral(bool.Parse(context.Bool().GetText()), textSpan, null);
            }
            else if (context.Null() != null)
            {
                result = new NullLiteral(textSpan, null);
            }
            else
            {
                throw new NotImplementedException();
            }
            return(result);
        }