clean ups

This commit is contained in:
3lswear
2022-01-18 17:58:45 +03:00
parent e7470e9124
commit 77c32c96e8
4 changed files with 7 additions and 110 deletions

View File

@@ -1,4 +1,5 @@
[[server]] [[server]]
a = "b"
name = "jopa" name = "jopa"
port = 6969 port = 6969
ip = "127.0.0.1" ip = "127.0.0.1"

View File

@@ -147,14 +147,14 @@ class toml_node
TOMLMapArray::iterator it; TOMLMapArray::iterator it;
TOMLMapArray *map_array = value.map_array; TOMLMapArray *map_array = value.map_array;
ss << std::endl; ss << "[\n";
for (it = map_array->begin(); it != map_array->end(); ++it) for (it = map_array->begin(); it != map_array->end(); ++it)
{ {
ss << (*TOMLMap_to_string(*it)); ss << (*TOMLMap_to_string(*it));
ss << std::endl; ss << ", " << std::endl;
} }
ss << "]\n";
ss << "-------" << std::endl;
/* ss >> *result; */ /* ss >> *result; */
*result = ss.str(); *result = ss.str();

View File

@@ -19,12 +19,6 @@ namespace config
TOMLParser(const std::string filename) : tokenizer(filename) {} TOMLParser(const std::string filename) : tokenizer(filename) {}
TOMLMap *parse(void); 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) toml_node *parseMap(void)
{ {
std::cerr << "Parsing object" << std::endl; std::cerr << "Parsing object" << std::endl;
@@ -99,10 +93,6 @@ namespace config
{ {
throw std::logic_error("EXPECTED newline"); throw std::logic_error("EXPECTED newline");
} }
/* if (tokenizer.getToken().type == NEWLINE) */
/* completed = true; */
/* else */
/* throw std::logic_error("EXPECTED newline"); */
} }
else else
{ {
@@ -113,10 +103,6 @@ namespace config
return (node); return (node);
} }
/* toml_node *parseMapArray(void) */
/* { */
/* } */
toml_node *parseString(void) toml_node *parseString(void)
{ {
/* toml_node *node; */ /* toml_node *node; */
@@ -240,11 +226,8 @@ namespace config
/* parse tha root ! */ /* parse tha root ! */
TOMLMap *TOMLParser::parse(void) TOMLMap *TOMLParser::parse(void)
{ {
/* root = parseMap()->getMap(); */
std::cerr << "Parsing ROOT" << std::endl; std::cerr << "Parsing ROOT" << std::endl;
/* TOMLMap *mapObject = new TOMLMap; */
root = new TOMLMap; root = new TOMLMap;
/* toml_node *node = new toml_node; */
bool completed = false; bool completed = false;
while (!completed) while (!completed)
{ {
@@ -280,10 +263,6 @@ namespace config
} }
else else
throw std::logic_error("unexpected token in parseMapArray"); throw std::logic_error("unexpected token in parseMapArray");
/* if (current.type != NEWLINE) */
/* { */
/* throw std::logic_error("EXPECTED newline"); */
/* } */
TOMLMap::iterator it; TOMLMap::iterator it;
std::string name = current.value; std::string name = current.value;
@@ -302,20 +281,9 @@ namespace config
(it->second)->getMapArray()->push_back(map_node->getMap()); (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 else
{ {
/* take key make decision */
std::string key = current.value; std::string key = current.value;
std::cerr << key << std::endl; std::cerr << key << std::endl;
if (tokenizer.getToken().type != ASSIGN) if (tokenizer.getToken().type != ASSIGN)
@@ -362,86 +330,14 @@ namespace config
{ {
throw std::logic_error("EXPECTED newline"); throw std::logic_error("EXPECTED newline");
} }
/* if (tokenizer.getToken().type == NEWLINE) */
/* completed = true; */
/* else */
/* throw std::logic_error("EXPECTED newline"); */
} }
} }
else else
{ {
/* throw std::logic_error("parseMap: no more tokens"); */
completed = true; completed = true;
break; 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); return (root);
} }
} }

View File

@@ -34,10 +34,10 @@ namespace config
{ {
std::cout << it->first std::cout << it->first
<< ": " << ": "
<< *(it->second->toString()) << *(it->second->toString());
<< std::endl; std::cout << ", " << std::endl;
/* << std::endl << "-------" << std::endl; */
} }
std::cout << "-------" << std::endl;
} }
} }