Exemplo n.º 1
0
        public NumberLiteral ReadNumberLiteral()
        {
            var location0 = Tokenizer.GetCurrentLocation();

            if (CurToken.Type != TokenType.Number)
            {
                ThrowExpect("number", CurToken);
            }

            if (CurToken.Value.StartsWith("0x", StringComparison.InvariantCulture))
            {
                var literal = new NumberLiteral(location0)
                {
                    HexFormat = true
                };

                if (CurToken.Value.Contains(".") ||
                    CurToken.Value.Contains("p") ||
                    CurToken.Value.Contains("P")
                    )
                {
                    literal.Value = LexerUtils.ParseHexFloat(CurToken);
                }
                else
                {
                    literal.Value = LexerUtils.ParseHexInteger(CurToken);
                }

                //if (!int.TryParse(CurToken.Value.Substring(2),
                //    System.Globalization.NumberStyles.AllowHexSpecifier,
                //    null,
                //    out int hexvalue))
                //{
                //}

                Move();

                return(literal);
            }

            if (!double.TryParse(CurToken.Value, out double value))
            {
                ThrowExpect("number", CurToken);
            }

            Move();
            return(new NumberLiteral(location0)
            {
                Value = value
            });
        }