Example #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);
        }
Example #2
0
        public UstNode VisitPatternIntLiteral(DslParser.PatternIntLiteralContext context)
        {
            IntLiteral result;

            if (context.i != null)
            {
                result = (IntLiteral)VisitPatternIntExpression(context.i);
            }
            else
            {
                result = new PatternIntLiteral(
                    context.i1 != null ? ((IntLiteral)VisitPatternIntExpression(context.i1)).Value : long.MinValue,
                    context.i2 != null ? ((IntLiteral)VisitPatternIntExpression(context.i2)).Value : long.MaxValue);
            }
            result.TextSpan = context.GetTextSpan();
            return(result);
        }
Example #3
0
        public PatternUst VisitPatternIntExpression([NotNull] DslParser.PatternIntExpressionContext context)
        {
            PatternIntLiteral result;

            if (context.op != null)
            {
                long leftValue   = ((PatternIntLiteral)VisitPatternIntExpression(context.left)).Value;
                long rightValue  = ((PatternIntLiteral)VisitPatternIntExpression(context.right)).Value;
                long resultValue = 0;
                switch (context.op.Text)
                {
                case "*":
                    resultValue = leftValue * rightValue;
                    break;

                case "/":
                    resultValue = leftValue / rightValue;
                    break;

                case "+":
                    resultValue = leftValue + rightValue;
                    break;

                case "-":
                    resultValue = leftValue - rightValue;
                    break;

                default:
                    throw new NotImplementedException($"Operation {context.op.Text} is not implemented");
                }
                result = new PatternIntLiteral(resultValue, context.GetTextSpan());
            }
            else
            {
                result = (PatternIntLiteral)VisitPatternInt(context.patternInt());
            }
            return(result);
        }
Example #4
0
 public virtual T Visit(PatternIntLiteral patternIntLiteral)
 {
     return(VisitChildren(patternIntLiteral));
 }
Example #5
0
 public virtual void Exit(PatternIntLiteral patternIntLiteral)
 {
 }
Example #6
0
 public virtual void Enter(PatternIntLiteral patternIntLiteral)
 {
 }