예제 #1
0
파일: Json.cs 프로젝트: modai888/xunit
 public JsonBoolean(JsonToken token)
     : base(token.Line, token.Column)
 {
     if (token.Type == JsonTokenType.True)
     {
         Value = true;
     }
     else if (token.Type == JsonTokenType.False)
     {
         Value = false;
     }
     else
     {
         throw new ArgumentException("Token value should be either True or False.", nameof(token));
     }
 }
예제 #2
0
 protected override void WriteEnd(JsonToken token)
 {
     if (token == JsonToken.EndObject)
         _writer.Write("}}}");
     else
         base.WriteEnd(token);
 }
예제 #3
0
파일: Json.cs 프로젝트: modai888/xunit
 public JsonNumber(JsonToken token)
     : base(token.Line, token.Column)
 {
     try
     {
         _raw = token.Value;
         _double = double.Parse(_raw, NumberStyles.Float);
     }
     catch (FormatException ex)
     {
         throw new JsonDeserializerException(
             JsonDeserializerResource.Format_InvalidFloatNumberFormat(_raw),
             ex,
             token.Line,
             token.Column);
     }
     catch (OverflowException ex)
     {
         throw new JsonDeserializerException(
             JsonDeserializerResource.Format_FloatNumberOverflow(_raw),
             ex,
             token.Line,
             token.Column);
     }
 }
예제 #4
0
파일: Json.cs 프로젝트: modai888/xunit
 public JsonDeserializerException(string message, JsonToken nextToken)
     : base(message)
 {
     Line = nextToken.Line;
     Column = nextToken.Column;
 }
예제 #5
0
파일: Json.cs 프로젝트: modai888/xunit
        static JsonObject DeserializeObject(JsonToken head, JsonBuffer buffer)
        {
            var dictionary = new Dictionary<string, JsonValue>();

            // Loop through each JSON entry in the input object
            while (true)
            {
                var next = buffer.Read();
                if (next.Type == JsonTokenType.EOF)
                {
                    throw new JsonDeserializerException(
                        JsonDeserializerResource.Format_InvalidSyntaxExpectation("JSON object", '}'),
                        next);
                }

                if (next.Type == JsonTokenType.Colon)
                {
                    throw new JsonDeserializerException(
                        JsonDeserializerResource.Format_InvalidSyntaxNotExpected("JSON object", ':'),
                        next);
                }
                else if (next.Type == JsonTokenType.RightCurlyBracket)
                {
                    break;
                }
                else
                {
                    if (next.Type != JsonTokenType.String)
                    {
                        throw new JsonDeserializerException(
                            JsonDeserializerResource.Format_InvalidSyntaxExpectation("JSON object member name", "JSON string"),
                            next);
                    }

                    var memberName = next.Value;
                    if (dictionary.ContainsKey(memberName))
                    {
                        throw new JsonDeserializerException(
                            JsonDeserializerResource.Format_DuplicateObjectMemberName(memberName),
                            next);
                    }

                    next = buffer.Read();
                    if (next.Type != JsonTokenType.Colon)
                    {
                        throw new JsonDeserializerException(
                            JsonDeserializerResource.Format_InvalidSyntaxExpectation("JSON object", ':'),
                            next);
                    }

                    dictionary[memberName] = DeserializeInternal(buffer.Read(), buffer);

                    next = buffer.Read();
                    if (next.Type == JsonTokenType.RightCurlyBracket)
                    {
                        break;
                    }
                    else if (next.Type != JsonTokenType.Comma)
                    {
                        throw new JsonDeserializerException(
                            JsonDeserializerResource.Format_InvalidSyntaxExpectation("JSON object", ',', '}'),
                            next);
                    }
                }
            }

            return new JsonObject(dictionary, head.Line, head.Column);
        }
예제 #6
0
파일: Json.cs 프로젝트: modai888/xunit
        static JsonArray DeserializeArray(JsonToken head, JsonBuffer buffer)
        {
            var list = new List<JsonValue>();
            while (true)
            {
                var next = buffer.Read();
                if (next.Type == JsonTokenType.RightSquareBracket)
                {
                    break;
                }

                list.Add(DeserializeInternal(next, buffer));

                next = buffer.Read();
                if (next.Type == JsonTokenType.EOF)
                {
                    throw new JsonDeserializerException(
                        JsonDeserializerResource.Format_InvalidSyntaxExpectation("JSON array", ']', ','),
                        next);
                }
                else if (next.Type == JsonTokenType.RightSquareBracket)
                {
                    break;
                }
                else if (next.Type != JsonTokenType.Comma)
                {
                    throw new JsonDeserializerException(
                        JsonDeserializerResource.Format_InvalidSyntaxExpectation("JSON array", ','),
                        next);
                }
            }

            return new JsonArray(list.ToArray(), head.Line, head.Column);
        }
예제 #7
0
파일: Json.cs 프로젝트: modai888/xunit
        static JsonValue DeserializeInternal(JsonToken next, JsonBuffer buffer)
        {
            if (next.Type == JsonTokenType.EOF)
            {
                return null;
            }

            if (next.Type == JsonTokenType.LeftSquareBracket)
            {
                return DeserializeArray(next, buffer);
            }

            if (next.Type == JsonTokenType.LeftCurlyBracket)
            {
                return DeserializeObject(next, buffer);
            }

            if (next.Type == JsonTokenType.String)
            {
                return new JsonString(next.Value, next.Line, next.Column);
            }

            if (next.Type == JsonTokenType.True || next.Type == JsonTokenType.False)
            {
                return new JsonBoolean(next);
            }

            if (next.Type == JsonTokenType.Null)
            {
                return new JsonNull(next.Line, next.Column);
            }

            if (next.Type == JsonTokenType.Number)
            {
                return new JsonNumber(next);
            }

            throw new JsonDeserializerException(JsonDeserializerResource.Format_InvalidTokenExpectation(
                next.Value, "'{', '[', true, false, null, JSON string, JSON number, or the end of the file"),
                next);
        }
예제 #8
0
파일: Json.cs 프로젝트: zabulus/xunit
 public JsonDeserializerException(string message, JsonToken nextToken)
     : base(message)
 {
     Line   = nextToken.Line;
     Column = nextToken.Column;
 }
예제 #9
0
파일: Json.cs 프로젝트: zabulus/xunit
        static JsonObject DeserializeObject(JsonToken head, JsonBuffer buffer)
        {
            var dictionary = new Dictionary <string, JsonValue>();

            // Loop through each JSON entry in the input object
            while (true)
            {
                var next = buffer.Read();
                if (next.Type == JsonTokenType.EOF)
                {
                    throw new JsonDeserializerException(
                              JsonDeserializerResource.Format_InvalidSyntaxExpectation("JSON object", '}'),
                              next);
                }

                if (next.Type == JsonTokenType.Colon)
                {
                    throw new JsonDeserializerException(
                              JsonDeserializerResource.Format_InvalidSyntaxNotExpected("JSON object", ':'),
                              next);
                }
                else if (next.Type == JsonTokenType.RightCurlyBracket)
                {
                    break;
                }
                else
                {
                    if (next.Type != JsonTokenType.String)
                    {
                        throw new JsonDeserializerException(
                                  JsonDeserializerResource.Format_InvalidSyntaxExpectation("JSON object member name", "JSON string"),
                                  next);
                    }

                    var memberName = next.Value;
                    if (dictionary.ContainsKey(memberName))
                    {
                        throw new JsonDeserializerException(
                                  JsonDeserializerResource.Format_DuplicateObjectMemberName(memberName),
                                  next);
                    }

                    next = buffer.Read();
                    if (next.Type != JsonTokenType.Colon)
                    {
                        throw new JsonDeserializerException(
                                  JsonDeserializerResource.Format_InvalidSyntaxExpectation("JSON object", ':'),
                                  next);
                    }

                    dictionary[memberName] = DeserializeInternal(buffer.Read(), buffer);

                    next = buffer.Read();
                    if (next.Type == JsonTokenType.RightCurlyBracket)
                    {
                        break;
                    }
                    else if (next.Type != JsonTokenType.Comma)
                    {
                        throw new JsonDeserializerException(
                                  JsonDeserializerResource.Format_InvalidSyntaxExpectation("JSON object", ',', '}'),
                                  next);
                    }
                }
            }

            return(new JsonObject(dictionary, head.Line, head.Column));
        }