public void Visit(FloatLiteral literal) { _codeStack.Peek().CodeExpression = new CodePrimitiveExpression(literal.Value); _codeStack.Peek().Scope = new ScopeData <Type> { Type = typeof(float?), CodeDomReference = new CodeTypeReference(typeof(float?)) }; }
public override void VisitFloatLiteral(FloatLiteral node, CloningAstVisitorContext context) { context.Result = new FloatLiteral() { LiteralValue = node.LiteralValue }; }
public override IQueryElement VisitLiteral([NotNull] QueryGrammarParser.LiteralContext context) { if (context.number() != null) { if (context.number().FLOAT_PRESICION() != null) { FloatLiteral floatLiteral = new FloatLiteral(); floatLiteral.Value = context.number().GetText(); return(floatLiteral); } IntegerLiteral literal = new IntegerLiteral(); literal.Value = context.number().GetText(); return(literal); } else if (context.STRING_VALUE() != null) { StringLiteral literal = new StringLiteral(); literal.Value = context.STRING_VALUE().GetText().Replace("'", "\""); return(literal); } else if (context.BOOL_VALUE() != null) { BoolLiteral literal = new BoolLiteral(); literal.Value = context.BOOL_VALUE().GetText(); return(literal); } else if (context.K_NULL() != null) { NullLiteral literal = new NullLiteral(); return(literal); } throw new SyntaxException("Unsupported literal."); }
protected Token ExtractLiteral(IToken token) { string text = token.Text; TextSpan textSpan = token.GetTextSpan(); Token result = null; try { if (text == "*") { result = new IdToken(text, textSpan); } else if (text.StartsWith("@")) { result = new IdToken(text.Substring(1), textSpan); } else if (text.StartsWith("\"") || text.StartsWith("[")) { result = new IdToken(text.Substring(1, text.Length - 2), textSpan); } else if (text.EndsWith("'")) { if (text.StartsWith("N")) { text = text.Substring(1); } text = text.Substring(1, text.Length - 2); result = new StringLiteral(text, textSpan); } else if (text.All(char.IsDigit)) { result = TextUtils.TryCreateNumericLiteral(text, textSpan); } else if (text.StartsWith("0X", StringComparison.OrdinalIgnoreCase)) { result = TextUtils.TryCreateNumericLiteral(text, textSpan, 16); } else if (double.TryParse(text, NumberStyles.Any, CultureInfo.InvariantCulture, out double floatValue)) { result = new FloatLiteral(floatValue, textSpan); } } catch { Logger.LogDebug($"Literal cannot be extracted from {nameof(token)} with symbol {text}"); } if (result == null && (text.Any(c => char.IsLetterOrDigit(c) || c == '_'))) { result = new IdToken(text, textSpan); } return(result); }
private Token ExtractLiteral(IToken token) { string text = token.Text; TextSpan textSpan = token.GetTextSpan(); Token result; double floatValue; if (text.StartsWith("@")) { result = new IdToken(text.Substring(1), textSpan, FileNode); } else if (text.StartsWith("\"") || text.StartsWith("[")) { result = new IdToken(text.Substring(1, text.Length - 2), textSpan, FileNode); } else if (text.EndsWith("'")) { if (text.StartsWith("N")) { text = text.Substring(1); } text = text.Substring(1, text.Length - 2); result = new StringLiteral(text, textSpan, FileNode); } else if (text.All(c => char.IsDigit(c))) { result = new IntLiteral(long.Parse(text), textSpan, FileNode); } else if (text.StartsWith("0X") || text.StartsWith("0x")) { result = new IntLiteral(Convert.ToInt64(text.Substring(2), 16), textSpan, FileNode); } else if (double.TryParse(text, out floatValue)) { result = new FloatLiteral(floatValue, textSpan, FileNode); } else { if (text.Any(c => char.IsLetterOrDigit(c) || c == '_')) { result = new IdToken(text, textSpan, FileNode); } else { result = null; } } return(result); }
private Token ExtractLiteral(IToken token) { string text = token.Text; TextSpan textSpan = token.GetTextSpan(); Token result = null; try { if (text.StartsWith("@")) { result = new IdToken(text.Substring(1), textSpan); } else if (text.StartsWith("\"") || text.StartsWith("[")) { result = new IdToken(text.Substring(1, text.Length - 2), textSpan); } else if (text.EndsWith("'")) { if (text.StartsWith("N")) { text = text.Substring(1); } text = text.Substring(1, text.Length - 2); result = new StringLiteral(text, textSpan); } else if (text.All(c => char.IsDigit(c))) { result = new IntLiteral(long.Parse(text), textSpan); } else if (text.StartsWith("0X", StringComparison.OrdinalIgnoreCase)) { result = new IntLiteral(System.Convert.ToInt64(text.Substring(2), 16), textSpan); } else if (double.TryParse(text, out double floatValue)) { result = new FloatLiteral(floatValue, textSpan); } } catch { } if (result == null && (text.Any(c => char.IsLetterOrDigit(c) || c == '_'))) { result = new IdToken(text, textSpan); } return(result); }
private IExpression ParseFloatLiteral() { var lit = new FloatLiteral { Token = CurrentToken }; var success = double.TryParse(CurrentToken.Literal, out var value); if (!success) { Errors.Add($"could not parse {CurrentToken.Literal} into float64"); return(null); } lit.Value = value; return(lit); }
/// <returns><see cref="Token"/></returns> public override UstNode VisitTerminal(ITerminalNode node) { string text = node.GetText(); TextSpan textSpan = node.GetTextSpan(); Token result; double doubleResult; if (text.StartsWith("'")) { result = new StringLiteral(text.Substring(1, text.Length - 2), textSpan, FileNode); } else if (text.ToLowerInvariant().StartsWith("n'")) { result = new StringLiteral(text.Substring(2, text.Length - 3), textSpan, FileNode); } else if (text.All(c => char.IsDigit(c))) { result = new IntLiteral(long.Parse(text), textSpan, FileNode); } else if (double.TryParse(text, out doubleResult)) { result = new FloatLiteral(doubleResult, textSpan, FileNode); } else if (text.All(c => char.IsLetterOrDigit(c) || c == '_')) { result = new IdToken(text, textSpan, FileNode); } else { if (text.Any(c => char.IsLetterOrDigit(c) || c == '_')) { Logger.LogDebug($"{text} converter to IdToken"); result = new IdToken(text, textSpan, FileNode); } else { result = null; } } return(result); }
internal List <Statement> GetStatements() { return(_variables.Select(variable => { Expression literal; if (variable.Value is int i) { literal = new IntegerLiteral("IntegerLiteral", Convert.ToString(i)); } else if (variable.Value is bool b) { literal = new BooleanLiteral("BooleanLiteral", b); } else if (variable.Value is float f) { literal = new FloatLiteral("FloatLiteral", Convert.ToDecimal(f)); } else if (variable.Value is DateTime d) { literal = new DateTimeLiteral("DateTimeLiteral", d); } else if (variable.Value is DateTimeOffset o) { literal = new DateTimeLiteral("DateTimeLiteral", o.UtcDateTime); } else { literal = new StringLiteral("StringLiteral", Convert.ToString(variable.Value)); } var assignment = new VariableAssignment("VariableAssignment", new Identifier("Identifier", variable.Name), literal); return new OptionStatement("OptionStatement", assignment) as Statement; }).ToList()); }
public virtual void Visit(FloatLiteral literal) { }
public bool VisitNode(FloatLiteral node) { // floatvalue Append("{0}", node.Value); return(true); }
// Float literal private void WriteFloatLiteral(FloatLiteral floatLiteral) { Write($"{floatLiteral}f"); }
public override void visit(FloatLiteral n) { n.Scope = Scope; }
public virtual void VisitFloatLiteral(FloatLiteral node, TContext context) { }
public override void Visit(FloatLiteral literal) { WriteFloatLiteral(literal); }
public void visit(FloatLiteral n) { throw new NotImplementedException(); }
public IType VisitFloatLiteral(FloatLiteral floatLiteral) => new FloatType();
public virtual T Visit(FloatLiteral expr) => Visit(expr as LiteralExpression);
public bool VisitFloatLiteral(FloatLiteral floatLiteral) => true;
public ASTType visit(FloatLiteral n) { return new FloatType(); }
public override void VisitFloatLiteral(FloatLiteral node, AstPrinterContext context) { context.Write(node.LiteralValue); }
public bool VisitNode(FloatLiteral node) { throw new NotImplementedException(); }
public virtual void Enter(FloatLiteral floatLiteral) { }
public virtual void Exit(FloatLiteral floatLiteral) { }
public void Visit(FloatLiteral literal, CommonTree tree) { Parent(tree).Children.Add(literal); SetLine(literal, tree); literal.Value = float.Parse(tree.Text); }
public virtual T Visit(FloatLiteral floatLiteral) { return(VisitChildren(floatLiteral)); }