コード例 #1
0
        private byte ReadDigits(byte firstCode)
        {
            if (!GraphQLConstants.IsDigit(firstCode))
            {
                throw new SyntaxException(this,
                                          "Invalid number, expected digit but got: " +
                                          $"`{(char)firstCode}` ({firstCode}).");
            }

            byte code = firstCode;

            while (true)
            {
                if (++_position >= _length)
                {
                    code = GraphQLConstants.Space;
                    break;
                }

                code = _graphQLData[_position];
                if (!GraphQLConstants.IsDigit(code))
                {
                    break;
                }
            }

            return(code);
        }
コード例 #2
0
        private void ReadNumberToken(byte firstCode)
        {
            int  start   = _position;
            byte code    = firstCode;
            var  isFloat = false;

            if (code == GraphQLConstants.Minus)
            {
                code = _graphQLData[++_position];
            }

            if (code == GraphQLConstants.Zero && !IsEndOfStream(_position + 1))
            {
                code = _graphQLData[++_position];
                if (GraphQLConstants.IsDigit(code))
                {
                    throw new SyntaxException(this,
                                              "Invalid number, unexpected digit after 0: " +
                                              $"`{(char)code}` ({code}).");
                }
            }
            else
            {
                code = ReadDigits(code);
            }

            if (code == GraphQLConstants.Dot)
            {
                isFloat      = true;
                _floatFormat = Language.FloatFormat.FixedPoint;
                code         = _graphQLData[++_position];
                code         = ReadDigits(code);
            }

            if ((code | 0x20) == GraphQLConstants.E)
            {
                isFloat      = true;
                _floatFormat = Language.FloatFormat.Exponential;
                code         = _graphQLData[++_position];
                if (code == GraphQLConstants.Plus ||
                    code == GraphQLConstants.Minus)
                {
                    code = _graphQLData[++_position];
                }
                ReadDigits(code);
            }

            _kind  = isFloat ? TokenKind.Float : TokenKind.Integer;
            _start = start;
            _end   = _position;
            _value = _graphQLData.Slice(start, _position - start);
        }