/// <summary>
		/// Splices out the sequence for the next complete value (object, array, primitive)
		/// </summary>
		/// <param name="stream"></param>
		/// <returns></returns>
		private static TokenSequence SpliceNextValue(IStream<ModelToken> stream)
		{
			if (stream.IsCompleted)
			{
				throw new TokenException<ModelTokenType>(
					ModelGrammar.TokenNone,
					ModelSubsequencer.ErrorUnexpectedEndOfInput);
			}

			stream.BeginChunk();

			int depth = 0;
			ModelToken token = stream.Pop();
			switch (token.TokenType)
			{
				case ModelTokenType.Primitive:
				{
					return stream.EndChunk();
				}
				case ModelTokenType.ArrayBegin:
				case ModelTokenType.ObjectBegin:
				{
					depth++;
					while (!stream.IsCompleted && depth > 0)
					{
						switch (stream.Pop().TokenType)
						{
							case ModelTokenType.ArrayBegin:
							case ModelTokenType.ObjectBegin:
							{
								depth++;
								break;
							}
							case ModelTokenType.ArrayEnd:
							case ModelTokenType.ObjectEnd:
							{
								depth--;
								break;
							}
						}
					}

					if (depth > 0)
					{
						throw new TokenException<ModelTokenType>(
							ModelGrammar.TokenNone,
							ModelSubsequencer.ErrorUnexpectedEndOfInput);
					}
					return stream.EndChunk();
				}
				default:
				{
					throw new TokenException<ModelTokenType>(
						token,
						String.Format(ModelSubsequencer.ErrorInvalidPropertyValue, token.TokenType));
				}
			}
		}
Example #2
0
        /// <summary>
        /// Splices out the sequence for the next complete value (object, array, primitive)
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        private static TokenSequence SpliceNextValue(IStream <ModelToken> stream)
        {
            if (stream.IsCompleted)
            {
                throw new TokenException <ModelTokenType>(
                          ModelGrammar.TokenNone,
                          ModelSubsequencer.ErrorUnexpectedEndOfInput);
            }

            stream.BeginChunk();

            int        depth = 0;
            ModelToken token = stream.Pop();

            switch (token.TokenType)
            {
            case ModelTokenType.Primitive:
            {
                return(stream.EndChunk());
            }

            case ModelTokenType.ArrayBegin:
            case ModelTokenType.ObjectBegin:
            {
                depth++;
                while (!stream.IsCompleted && depth > 0)
                {
                    switch (stream.Pop().TokenType)
                    {
                    case ModelTokenType.ArrayBegin:
                    case ModelTokenType.ObjectBegin:
                    {
                        depth++;
                        break;
                    }

                    case ModelTokenType.ArrayEnd:
                    case ModelTokenType.ObjectEnd:
                    {
                        depth--;
                        break;
                    }
                    }
                }

                if (depth > 0)
                {
                    throw new TokenException <ModelTokenType>(
                              ModelGrammar.TokenNone,
                              ModelSubsequencer.ErrorUnexpectedEndOfInput);
                }
                return(stream.EndChunk());
            }

            default:
            {
                throw new TokenException <ModelTokenType>(
                          token,
                          String.Format(ModelSubsequencer.ErrorInvalidPropertyValue, token.TokenType));
            }
            }
        }