protected void AssertLiteralSuffix(string code, string suffix, object value, Type type) { LitExprNode literal = this.GenerateAST(code).As <LitExprNode>(); Assert.That(literal, Is.Not.Null); Assert.That(literal.Value?.GetType(), Is.EqualTo(type)); Assert.That(literal.Suffix, Is.EqualTo(suffix)); Assert.That(ConstantExpressionEvaluator.Evaluate(literal), Is.EqualTo(value).Within(1e-10)); }
public override ASTNode VisitExp([NotNull] ExpContext ctx) { if (!ctx.exp()?.Any() ?? true) { string firstToken = ctx.children.First().GetText(); switch (firstToken) { case "nil": return(new NullLitExprNode(ctx.Start.Line)); case "true": case "false": return(LitExprNode.FromString(ctx.Start.Line, firstToken)); case "...": throw new NotImplementedException("..."); } if (ctx.number() is { })
public virtual TResult Visit(LitExprNode node) => this.VisitChildren(node);
public override Expr Visit(LitExprNode node) // TODO string literals need to be substituted as well... => node.Value is null ? Expr.Undefined : Expr.Parse(node.Value.ToString());