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
     };
 }
Esempio n. 3
0
        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.");
        }
Esempio n. 4
0
        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);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        /// <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);
        }
Esempio n. 9
0
        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)
 {
 }
Esempio n. 11
0
 public bool VisitNode(FloatLiteral node)
 {
     // floatvalue
     Append("{0}", node.Value);
     return(true);
 }
Esempio n. 12
0
 // 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)
 {
 }
Esempio n. 15
0
 public override void Visit(FloatLiteral literal)
 {
     WriteFloatLiteral(literal);
 }
 public void visit(FloatLiteral n)
 {
     throw new NotImplementedException();
 }
Esempio n. 17
0
File: Typer.cs Progetto: Daouki/wire
 public IType VisitFloatLiteral(FloatLiteral floatLiteral) => new FloatType();
Esempio n. 18
0
 public virtual T Visit(FloatLiteral expr) => Visit(expr as LiteralExpression);
Esempio n. 19
0
 public bool VisitFloatLiteral(FloatLiteral floatLiteral) => true;
Esempio n. 20
0
 public ASTType visit(FloatLiteral n)
 {
     return new FloatType();
 }
 public override void VisitFloatLiteral(FloatLiteral node, AstPrinterContext context)
 {
     context.Write(node.LiteralValue);
 }
Esempio n. 22
0
 public bool VisitNode(FloatLiteral node)
 {
     throw new NotImplementedException();
 }
Esempio n. 23
0
 public virtual void Enter(FloatLiteral floatLiteral)
 {
 }
Esempio n. 24
0
 public virtual void Exit(FloatLiteral floatLiteral)
 {
 }
Esempio n. 25
0
 public void Visit(FloatLiteral literal, CommonTree tree)
 {
     Parent(tree).Children.Add(literal);
     SetLine(literal, tree);
     literal.Value = float.Parse(tree.Text);
 }
Esempio n. 26
0
 public virtual T Visit(FloatLiteral floatLiteral)
 {
     return(VisitChildren(floatLiteral));
 }