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); }
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); }
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); }
public virtual T Visit(PatternIntLiteral patternIntLiteral) { return(VisitChildren(patternIntLiteral)); }
public virtual void Exit(PatternIntLiteral patternIntLiteral) { }
public virtual void Enter(PatternIntLiteral patternIntLiteral) { }