public override Expression VisitNumericAtom([NotNull] ExpressionAntlrParser.NumericAtomContext context) { if (int.TryParse(context.GetText(), out var intValue)) { return(Expression.ConstantExpression(intValue)); } if (double.TryParse(context.GetText(), NumberStyles.Any, CultureInfo.InvariantCulture, out var doubleValue)) { return(Expression.ConstantExpression(doubleValue)); } throw new Exception($"{context.GetText()} is not a number in expression '{context.GetText()}'"); }
public override Expression VisitNumericAtom([NotNull] ExpressionAntlrParser.NumericAtomContext context) { var contextText = context.GetText(); if (int.TryParse(contextText, out var intValue)) { return(Expression.ConstantExpression(intValue)); } if (long.TryParse(contextText, out var longValue)) { return(Expression.ConstantExpression(longValue)); } if (double.TryParse(contextText, NumberStyles.Any, CultureInfo.InvariantCulture, out var doubleValue)) { return(Expression.ConstantExpression(doubleValue)); } throw new ArgumentException($"{contextText} is not a number in expression \"{contextText}\""); }
/// <summary> /// Exit a parse tree produced by the <c>numericAtom</c> /// labeled alternative in <see cref="ExpressionAntlrParser.primaryExpression"/>. /// <para>The default implementation does nothing.</para> /// </summary> /// <param name="context">The parse tree.</param> public virtual void ExitNumericAtom([NotNull] ExpressionAntlrParser.NumericAtomContext context) { }
/// <summary> /// Visit a parse tree produced by the <c>numericAtom</c> /// labeled alternative in <see cref="ExpressionAntlrParser.primaryExpression"/>. /// <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 VisitNumericAtom([NotNull] ExpressionAntlrParser.NumericAtomContext context) { return(VisitChildren(context)); }