diff --git a/config/simple.toml b/config/simple.toml index 29b75ed..3690559 100644 --- a/config/simple.toml +++ b/config/simple.toml @@ -1,4 +1,5 @@ [[server]] + a = "b" name = "jopa" port = 6969 ip = "127.0.0.1" diff --git a/src/config/TOMLNode.hpp b/src/config/TOMLNode.hpp index 662e9a9..a590ca5 100644 --- a/src/config/TOMLNode.hpp +++ b/src/config/TOMLNode.hpp @@ -147,14 +147,14 @@ class toml_node TOMLMapArray::iterator it; TOMLMapArray *map_array = value.map_array; - ss << std::endl; + ss << "[\n"; for (it = map_array->begin(); it != map_array->end(); ++it) { ss << (*TOMLMap_to_string(*it)); - ss << std::endl; + ss << ", " << std::endl; } + ss << "]\n"; - ss << "-------" << std::endl; /* ss >> *result; */ *result = ss.str(); diff --git a/src/config/TOMLParser.hpp b/src/config/TOMLParser.hpp index 1a58249..e46033a 100644 --- a/src/config/TOMLParser.hpp +++ b/src/config/TOMLParser.hpp @@ -19,12 +19,6 @@ namespace config TOMLParser(const std::string filename) : tokenizer(filename) {} TOMLMap *parse(void); - /* get a name possibly with dots and add new map to corresponding map_array*/ - /* void add_to_map_array(std::string name, TOMLMap *new) */ - /* { */ - - /* } */ - toml_node *parseMap(void) { std::cerr << "Parsing object" << std::endl; @@ -99,10 +93,6 @@ namespace config { throw std::logic_error("EXPECTED newline"); } - /* if (tokenizer.getToken().type == NEWLINE) */ - /* completed = true; */ - /* else */ - /* throw std::logic_error("EXPECTED newline"); */ } else { @@ -113,10 +103,6 @@ namespace config return (node); } - /* toml_node *parseMapArray(void) */ - /* { */ - /* } */ - toml_node *parseString(void) { /* toml_node *node; */ @@ -240,11 +226,8 @@ namespace config /* parse tha root ! */ TOMLMap *TOMLParser::parse(void) { - /* root = parseMap()->getMap(); */ std::cerr << "Parsing ROOT" << std::endl; - /* TOMLMap *mapObject = new TOMLMap; */ root = new TOMLMap; - /* toml_node *node = new toml_node; */ bool completed = false; while (!completed) { @@ -280,10 +263,6 @@ namespace config } else throw std::logic_error("unexpected token in parseMapArray"); - /* if (current.type != NEWLINE) */ - /* { */ - /* throw std::logic_error("EXPECTED newline"); */ - /* } */ TOMLMap::iterator it; std::string name = current.value; @@ -302,20 +281,9 @@ namespace config (it->second)->getMapArray()->push_back(map_node->getMap()); } - /* if (tokenizer.hasMoreTokens()) */ - /* nextToken = tokenizer.getToken(); */ - /* else */ - /* break; */ - /* if (nextToken.type != NEWLINE) */ - /* { */ - /* throw std::logic_error("EXPECTED newline"); */ - /* } */ - - /* continue; */ } else { - /* take key make decision */ std::string key = current.value; std::cerr << key << std::endl; if (tokenizer.getToken().type != ASSIGN) @@ -362,86 +330,14 @@ namespace config { throw std::logic_error("EXPECTED newline"); } - /* if (tokenizer.getToken().type == NEWLINE) */ - /* completed = true; */ - /* else */ - /* throw std::logic_error("EXPECTED newline"); */ } } else { - /* throw std::logic_error("parseMap: no more tokens"); */ completed = true; break; } - /* node->setObject(root); */ } - /* root = parseMapArray(); */ - return (root); - - /* while (tokenizer.hasMoreTokens()) */ - /* { */ - /* s_token token; */ - /* try */ - /* { */ - /* token = tokenizer.getToken(); */ - /* /1* std::cout << token.to_string() << std::endl; *1/ */ - /* switch (token.type) */ - /* { */ - /* case KEY: */ - /* { */ - /* toml_node *parsedObject = parseString(); */ - /* if (!root) */ - /* root = parsedObject; */ - /* } */ - - /* case ARR_OPEN: */ - /* { */ - /* toml_node *parsedObject = parseMap(); */ - /* /1* parsedObject->printNode(0); *1/ */ - /* if (!root) */ - /* root = parsedObject; */ - /* } */ - /* break; */ - /* case NUMBER: */ - /* { */ - /* tokenizer.rollBackToken(); */ - /* toml_node *parsedNumber = parseNumber(); */ - /* if (!root) */ - /* root = parsedNumber; */ - /* } */ - /* break; */ - /* case STRING: */ - /* { */ - /* tokenizer.rollBackToken(); */ - /* toml_node *parsedString = parseString(); */ - /* if (!root) */ - /* root = parsedString; */ - /* } */ - /* break; */ - /* case BOOL: */ - /* { */ - /* tokenizer.rollBackToken(); */ - /* toml_node *parsedBool = parseBool(); */ - /* if (!root) */ - /* root = parsedBool; */ - /* } */ - /* break; */ - /* case MAPARRAY_DECL: */ - /* { */ - - /* } */ - /* default: */ - /* { */ - /* throw std::logic_error("JOPA :("); */ - /* } */ - /* } */ - /* } */ - /* catch (std::logic_error err) */ - /* { */ - /* break; */ - /* } */ - /* } */ return (root); } } diff --git a/src/config/parse.cpp b/src/config/parse.cpp index a49b5ba..90e806d 100644 --- a/src/config/parse.cpp +++ b/src/config/parse.cpp @@ -34,10 +34,10 @@ namespace config { std::cout << it->first << ": " - << *(it->second->toString()) - << std::endl; + << *(it->second->toString()); + std::cout << ", " << std::endl; + /* << std::endl << "-------" << std::endl; */ } - std::cout << "-------" << std::endl; } }