Exemplo n.º 1
0
        private static object ParseDictionary(Lexer lexer)
        {
            PropertyDictionary dictionary = new PropertyDictionary();

            while (true)
            {
                Token token = lexer.Next();

                if (token.Kind == TokenKind.DictionaryClose) break;

                object key = ParseObject(lexer, token);

                Token equals = lexer.Next();
                if (equals.Kind != TokenKind.Equals) ThrowBecauseOfAnUnexpectedToken(lexer, equals);

                object value = ParseObject(lexer, Token.None);

                dictionary.SetValueFor(key, value);

                Token terminator = lexer.Next();

                if (terminator.Kind == TokenKind.DictionaryClose) break;
                if (terminator.Kind == TokenKind.Separator) continue;

                ThrowBecauseOfAnUnexpectedToken(lexer, terminator);
            }

            return dictionary;
        }
Exemplo n.º 2
0
        private static object ParseArray(Lexer lexer)
        {
            PropertyArray array = new PropertyArray();

            while (true)
            {
                Token token = lexer.Next();

                if (token.Kind == TokenKind.ArrayClose) break;

                object value = ParseObject(lexer, token);

                array.AppendValue(value);

                Token terminator = lexer.Next();

                if (terminator.Kind == TokenKind.ArrayClose) break;
                if (terminator.Kind == TokenKind.Separator) continue;

                ThrowBecauseOfAnUnexpectedToken(lexer, terminator);
            }

            return array;
        }
Exemplo n.º 3
0
        static object ParseObject(Lexer lexer, Token savedToken)
        {
            Token token = savedToken.Kind == TokenKind.None ? lexer.Next() : savedToken;

            // TODO: This should be done properly instead of just assuming it's a date time.
            // Date Time handling.
            //DateTime possibleDateValue;

            //if (token.Value is string && token.Kind == TokenKind.Literal &&
            //    DateTime.TryParse(token.Value as string, out possibleDateValue))
            //{
            //    return possibleDateValue;
            //}

            switch (token.Kind)
            {
                case TokenKind.Literal:
                    return token.Value;

                case TokenKind.ArrayOpen:
                    return ParseArray(lexer);

                case TokenKind.DictionaryOpen:
                    return ParseDictionary(lexer);

                case TokenKind.DictionaryClose:
                case TokenKind.ArrayClose:
                case TokenKind.Equals:
                case TokenKind.Separator:
                case TokenKind.End:
                default:
                    ThrowBecauseOfAnUnexpectedToken(lexer, token);
                    return null;
            }
        }