Example #1
0
        private JsonToken PeekAndGetToken(JsonTokenizer tokenizer, JsonTokenBuffer tokenTailBuffer, ObjectTailBuffer nodeTailBuffer)
        {
            JsonToken s = tokenizer.Peek();

            if (s == null)
            {
                throw new UnknownParserException("Failed to get the next json token. " + tokenTailBuffer.ToTraceString(), GetTailCharStream(tokenizer), PeekCharStream(tokenizer));
            }
            return(s);
        }
        private JsonToken PeekAndGetToken(JsonTokenizer tokenizer)
        {
            JsonToken s = tokenizer.Peek();

            if (s.IsInvalid)
            {
                throw new UnknownParserException("Failed to get the Next json token.", GetTailCharStream(tokenizer), PeekCharStream(tokenizer));
            }
            return(s);
        }
        private TokenType PeekAndGetType(JsonTokenizer tokenizer, JsonTokenBuffer tokenTailBuffer, ObjectTailBuffer nodeTailBuffer)
        {
            JsonToken s = tokenizer.Peek();

            if (s.IsInvalid)
            {
                throw new UnknownParserException("Failed to get the Next json token. " + tokenTailBuffer.ToTraceString(), GetTailCharStream(tokenizer), PeekCharStream(tokenizer));
            }
            var type = s.Type;

            return(type);
        }
        private TokenType PeekAndGetType(JsonTokenizer tokenizer)
        {
            JsonToken s = tokenizer.Peek();

            if (s.IsInvalid)
            {
                throw new UnknownParserException("Failed to get the Next json token.", GetTailCharStream(tokenizer), PeekCharStream(tokenizer));
            }
            var type = s.Type;

            return(type);
        }
Example #5
0
        private async Task <object> ProduceJsonArrayElementAsync(JsonTokenizer tokenizer, int depth, JsonTokenBuffer tokenTailBuffer, ObjectTailBuffer nodeTailBuffer)
        {
            object element = null;
            var    type    = PeekAndGetType(tokenizer, tokenTailBuffer, nodeTailBuffer);

            switch (type)
            {
            case TokenType.NULL:
                element = ProduceJsonNull(tokenizer, tokenTailBuffer, nodeTailBuffer);
                break;

            case TokenType.BOOLEAN:
                element = ProduceJsonBoolean(tokenizer, tokenTailBuffer, nodeTailBuffer);
                break;

            case TokenType.NUMBER:
                element = ProduceJsonNumber(tokenizer, tokenTailBuffer, nodeTailBuffer);
                break;

            case TokenType.STRING:
                element = ProduceJsonString(tokenizer, tokenTailBuffer, nodeTailBuffer);
                break;

            case TokenType.LCURLY:
                element = await ProduceJsonObjectAsync(tokenizer, depth - 1, tokenTailBuffer, nodeTailBuffer);

                break;

            case TokenType.LSQUARE:
                element = await ProduceJsonArrayAsync(tokenizer, depth - 1, tokenTailBuffer, nodeTailBuffer);

                break;

            default:
                // ???
                throw new InvalidJsonTokenException("Json array element not recognized: token = " + tokenizer.Peek() + "; " + tokenTailBuffer.ToTraceString(), GetTailCharStream(tokenizer), PeekCharStream(tokenizer));
            }

            //if (log.IsLoggable(Level.FINER)) {
            //    log.finer("element = " + element);
            //}
            return(element);
        }
Example #6
0
        private async Task <MapEntry <string, object> > ProduceJsonObjectMemberAsync(JsonTokenizer tokenizer, int depth, JsonTokenBuffer tokenTailBuffer, ObjectTailBuffer nodeTailBuffer)
        {
            JsonToken keyToken = NextAndGetToken(tokenizer, tokenTailBuffer, nodeTailBuffer);

            if (TracingEnabled)
            {
                tokenTailBuffer.Push(keyToken);
            }
            var keyType = keyToken.Type;

            if (keyType != TokenType.STRING)
            {
                throw new InvalidJsonTokenException("JSON Object member should start with a string key. keyType = " + keyType + "; " + tokenTailBuffer.ToTraceString(), GetTailCharStream(tokenizer), PeekCharStream(tokenizer));
            }
            string key = (string)keyToken.Value;

            JsonToken colonToken = NextAndGetToken(tokenizer, tokenTailBuffer, nodeTailBuffer); // "consume" :.

            if (TracingEnabled)
            {
                tokenTailBuffer.Push(colonToken);
            }
            var colonType = colonToken.Type;

            if (colonType != TokenType.COLON)
            {
                throw new InvalidJsonTokenException("JSON Object member should include a colon (:). " + tokenTailBuffer.ToTraceString(), GetTailCharStream(tokenizer), PeekCharStream(tokenizer));
            }

            object value = null;
            var    type  = PeekAndGetType(tokenizer, tokenTailBuffer, nodeTailBuffer);

            switch (type)
            {
            case TokenType.NULL:
                value = ProduceJsonNull(tokenizer, tokenTailBuffer, nodeTailBuffer);
                break;

            case TokenType.BOOLEAN:
                value = ProduceJsonBoolean(tokenizer, tokenTailBuffer, nodeTailBuffer);
                break;

            case TokenType.NUMBER:
                value = ProduceJsonNumber(tokenizer, tokenTailBuffer, nodeTailBuffer);
                break;

            case TokenType.STRING:
                value = ProduceJsonString(tokenizer, tokenTailBuffer, nodeTailBuffer);
                break;

            case TokenType.LCURLY:
                value = await ProduceJsonObjectAsync(tokenizer, depth - 1, tokenTailBuffer, nodeTailBuffer);

                break;

            case TokenType.LSQUARE:
                value = await ProduceJsonArrayAsync(tokenizer, depth - 1, tokenTailBuffer, nodeTailBuffer);

                break;

            default:
                // ???
                throw new InvalidJsonTokenException("Json array element not recognized: token = " + tokenizer.Peek() + "; " + tokenTailBuffer.ToTraceString(), GetTailCharStream(tokenizer), PeekCharStream(tokenizer));
            }

            // TBD: Use type factory ???
            MapEntry <string, object> member = new MapEntry <string, object>(key, value);

            //if (log.IsLoggable(Level.FINER)) {
            //    log.finer("member = " + member);
            //}
            return(member);
        }
        private JsonNode ProduceJsonArrayElement(JsonTokenizer tokenizer)
        {
            JsonNode element = null;
            var      type    = PeekAndGetType(tokenizer);

            switch (type)
            {
            case TokenType.NULL:
                element = ProduceJsonNull(tokenizer);
                break;

            case TokenType.BOOLEAN:
                element = ProduceJsonBoolean(tokenizer);
                break;

            case TokenType.NUMBER:
                element = ProduceJsonNumber(tokenizer);
                break;

            case TokenType.STRING:
                element = ProduceJsonString(tokenizer);
                break;

            case TokenType.LCURLY:
                element = ProduceJsonObject(tokenizer);
                break;

            case TokenType.LSQUARE:
                element = ProduceJsonArray(tokenizer);
                break;

            default:
                // ???
                throw new InvalidJsonTokenException("Json array element not recognized: token = " + tokenizer.Peek(), GetTailCharStream(tokenizer), PeekCharStream(tokenizer));
            }

            //if (log.isLoggable(Level.FINER)) {
            //    log.finer("element = " + element);
            //}
            return(element);
        }
        private JsonObjectMember ProduceJsonObjectMember(JsonTokenizer tokenizer)
        {
            JsonToken keyToken = NextAndGetToken(tokenizer);
            var       keyType  = keyToken.Type;

            if (keyType != TokenType.STRING)
            {
                throw new InvalidJsonTokenException("JSON Object member should start with a string key.", GetTailCharStream(tokenizer), PeekCharStream(tokenizer));
            }
            string key = (string)keyToken.Value;

            JsonToken colonToken = NextAndGetToken(tokenizer); // "consume" :.
            var       colonType  = colonToken.Type;

            if (colonType != TokenType.COLON)
            {
                throw new InvalidJsonTokenException("JSON Object member should include a colon (:).", GetTailCharStream(tokenizer), PeekCharStream(tokenizer));
            }

            JsonNode value = null;
            var      type  = PeekAndGetType(tokenizer);

            switch (type)
            {
            case TokenType.NULL:
                value = ProduceJsonNull(tokenizer);
                break;

            case TokenType.BOOLEAN:
                value = ProduceJsonBoolean(tokenizer);
                break;

            case TokenType.NUMBER:
                value = ProduceJsonNumber(tokenizer);
                break;

            case TokenType.STRING:
                value = ProduceJsonString(tokenizer);
                break;

            case TokenType.LCURLY:
                value = ProduceJsonObject(tokenizer);
                break;

            case TokenType.LSQUARE:
                value = ProduceJsonArray(tokenizer);
                break;

            default:
                // ???
                throw new InvalidJsonTokenException("Json array element not recognized: token = " + tokenizer.Peek(), GetTailCharStream(tokenizer), PeekCharStream(tokenizer));
            }

            // TBD: Use type factory ???
            JsonObjectMember member = new AbstractJsonObjectMember(key, value);

            //if (log.isLoggable(Level.FINER)) {
            //    log.finer("member = " + member);
            //}
            return(member);
        }