diff --git a/src/config/TOMLParser.cpp b/src/config/TOMLParser.cpp index 467b477..2bae3fd 100644 --- a/src/config/TOMLParser.cpp +++ b/src/config/TOMLParser.cpp @@ -43,11 +43,13 @@ namespace config if (current.type == MAP_DECL) { if (tokenizer.getToken().type != NEWLINE) - throw std::logic_error("no newline after MAP_DECL"); + throw ExpectedToken("newline", current.value); + // throw std::logic_error("no newline after MAP_DECL"); map_node = parseMap(); } else - throw std::logic_error("unexpected token in processMap"); + // throw std::logic_error("unexpected token in processMap"); + throw UnexpectedToken("", current.value); /* std::cout << current.value << std::endl; */ @@ -90,8 +92,11 @@ namespace config } std::string key = nextToken.value; /* std::cerr << key << std::endl; */ + DBOUT << RED << "key is " << key << ENDL; if (tokenizer.getToken().type != ASSIGN) - throw std::logic_error("EXPECTED assign!"); + throw ExpectedToken("assign", "after " + key); + // throw std::logic_error("EXPECTED assign! 1"); + nextToken = tokenizer.getToken(); switch (nextToken.type) { @@ -126,8 +131,9 @@ namespace config } default: { + throw UnexpectedToken(nextToken.value, key); /* throw std::logic_error("jopa in parseMap"); */ - std::cerr << "Unknown token, marking as complete" << std::endl; + // std::cerr << "Unknown token, marking as complete" << std::endl; completed = true; break; } @@ -138,13 +144,14 @@ namespace config break; if (nextToken.type != NEWLINE) { - throw std::logic_error("EXPECTED newline"); + // throw std::logic_error("EXPECTED newline"); + throw ExpectedToken("newline", "parsing Hash Table"); } } - else - { - throw std::logic_error("parseMap: no more tokens"); - } + // else + // { + // throw std::logic_error("parseMap: no more tokens"); + // } } node->setObject(mapObject); return (node); @@ -257,7 +264,9 @@ namespace config } default: { - throw std::logic_error("unkown token in parseArray"); + // throw std::logic_error("unkown token in parseArray"); + throw UnexpectedToken("entry " + current.value, + "in Array"); } } @@ -268,7 +277,8 @@ namespace config else if (current.type == CLOSE_BRACKET) completed = true; else - throw std::invalid_argument("Unexpected token in array!"); + throw UnexpectedToken(current.value, ", when expected COMMA, or CLOSE_BRACKET"); + // throw std::invalid_argument("Unexpected token in array!"); } } result->setArr(array); diff --git a/src/config/TOMLParser.hpp b/src/config/TOMLParser.hpp index 98833fb..26fc9a9 100644 --- a/src/config/TOMLParser.hpp +++ b/src/config/TOMLParser.hpp @@ -41,8 +41,52 @@ namespace config toml_node *parseNil(void); - }; + class ExpectedToken: public std::exception + { + protected: + std::string *msg; + public: + ExpectedToken(const std::string &missing, const std::string context) + { + msg = new std::string("Config file: "); + *msg += ("Expected " + missing + " at " + context); + } + + virtual const char *what() const throw() + { + return (msg->c_str()); + } + + virtual ~ExpectedToken() throw() + { + delete msg; + } + }; + class UnexpectedToken: public std::exception + { + protected: + std::string *msg; + + public: + UnexpectedToken(const std::string &unexpected, const std::string context) + { + msg = new std::string("Config file: "); + *msg += ("Unexpected " + unexpected + " " + context); + } + + virtual const char *what() const throw() + { + return (msg->c_str()); + } + + virtual ~UnexpectedToken() throw() + { + delete msg; + } + + }; + }; /* parse tha root ! */ /* TOMLMap *TOMLParser::parse(void); */ }