intermed changes

This commit is contained in:
3lswear
2022-01-12 20:40:39 +03:00
parent 9e9620687f
commit 979ce70a2b
3 changed files with 47 additions and 21 deletions

View File

@@ -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)

View File

@@ -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 :(");

View File

@@ -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')