static void ThrowBecauseOfAnUnexpectedToken(Lexer lexer, Token token) { string description = ""; switch (token.Kind) { case TokenKind.Literal: description = "literal"; break; case TokenKind.ArrayOpen: description = "array opening character"; break; case TokenKind.ArrayClose: description = "array closing character"; break; case TokenKind.DictionaryOpen: description = "dictionary opening character"; break; case TokenKind.DictionaryClose: description = "dictionary closing character"; break; case TokenKind.Equals: description = "equals character"; break; case TokenKind.Separator: description = "separator character"; break; case TokenKind.End: description = "end of file"; break; default: description = "unknown token"; break; } throw new PropertyListException(string.Format( "An unexpected {0} was found on line {1} of the configuration " + "file \"{2}\".", description, token.LineNumber, lexer.NameForExceptions)); }
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; } }