From 979ce70a2bc3ad71330d29ce28fd6ac6bf9d138e Mon Sep 17 00:00:00 2001 From: 3lswear Date: Wed, 12 Jan 2022 20:40:39 +0300 Subject: [PATCH] intermed changes --- src/config/TOMLNode.hpp | 5 +++++ src/config/TOMLParser.hpp | 28 ++++++++++++++++++++++++++++ src/config/Tokenizer.hpp | 35 ++++++++++++++--------------------- 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/src/config/TOMLNode.hpp b/src/config/TOMLNode.hpp index f265d31..5638b46 100644 --- a/src/config/TOMLNode.hpp +++ b/src/config/TOMLNode.hpp @@ -76,6 +76,11 @@ class toml_node value.map = obj; type = MAP; } + void setMapArray(TOMLMapArray *map_array) + { + value.map_array = map_array; + type = MAPARRAY; + } std::string *toString(void) const { switch (type) diff --git a/src/config/TOMLParser.hpp b/src/config/TOMLParser.hpp index 92ed80a..404d339 100644 --- a/src/config/TOMLParser.hpp +++ b/src/config/TOMLParser.hpp @@ -96,6 +96,30 @@ namespace config return (node); } + toml_node *parseMapArray(void) + { + std::cerr << "Parsing MapArray" << std::endl; + toml_node *node = new toml_node; + TOMLMapArray *servers = new TOMLMapArray; + + while (tokenizer.hasMoreTokens()) + { + s_token current; + try { current = tokenizer.getToken(); } + catch (std::logic_error e) + { + std::cerr << e.what() << std::endl; + break; + } + if (current.type == MAPARRAY_DECL) + servers->push_back(parseMap()->getMap()); + else + throw std::logic_error("unexpected token in parseMapArray"); + } + node->setMapArray(servers); + return (node); + } + toml_node *parseString(void) { /* toml_node *node; */ @@ -272,6 +296,10 @@ namespace config root = parsedBool; } break; + case MAPARRAY_DECL: + { + + } default: { throw std::logic_error("JOPA :("); diff --git a/src/config/Tokenizer.hpp b/src/config/Tokenizer.hpp index e2990f3..73148b7 100644 --- a/src/config/Tokenizer.hpp +++ b/src/config/Tokenizer.hpp @@ -25,8 +25,7 @@ namespace config ARR_CLOSE, MAP_OPEN, MAP_CLOSE, - MAPARRAY_OPEN, - MAPARRAY_CLOSE + MAPARRAY_DECL }; struct s_token @@ -144,27 +143,23 @@ namespace config file.get(c); } } - else if (c == ']') - { - std::streampos prev_pos = file.tellg(); - file.get(c); - if (c == ']') - { - token.type = MAPARRAY_CLOSE; - } - else - { - token.type = ARR_CLOSE; - file.seekg(prev_pos); - } - } else if (c == '[') { std::streampos prev_pos = file.tellg(); file.get(c); if (c == '[') { - token.type = MAPARRAY_OPEN; + token.type = MAPARRAY_DECL; + file.get(c); + while (c != ']') + { + token.value += c; + file.get(c); + } + if (c == ']') + file.get(c); + if (c != ']') + throw std::logic_error("error in MAPARRAY_DECL"); } else { @@ -173,10 +168,8 @@ namespace config } } - /* else if (c == '[') */ - /* token.type = ARR_OPEN; */ - /* else if (c == ']') */ - /* token.type = ARR_CLOSE; */ + else if (c == ']') + token.type = ARR_CLOSE; else if (c == '=') token.type = ASSIGN; else if (c == '\n')