refactor: token names and misc

This commit is contained in:
3lswear
2022-01-22 14:07:54 +03:00
parent 51a3050beb
commit d9f3330440
3 changed files with 342 additions and 334 deletions

View File

@@ -24,8 +24,8 @@ namespace config
COMMA,
BOOL,
NIL,
ARR_OPEN,
ARR_CLOSE,
OPEN_BRACKET,
CLOSE_BRACKET,
MAP_OPEN,
MAP_CLOSE,
MAPARRAY_DECL

View File

@@ -22,11 +22,14 @@
/* return (*this); */
/* } */
config::TOMLParser::TOMLParser(const std::string filename) : tokenizer(filename)
{};
toml_node *config::TOMLParser::parseMap(void)
namespace config
{
TOMLParser::TOMLParser(const std::string filename) : tokenizer(filename)
{};
toml_node *TOMLParser::parseMap(void)
{
std::cerr << "Parsing map" << std::endl;
toml_node *node = new toml_node;
TOMLMap *mapObject = new TOMLMap;
@@ -46,6 +49,10 @@ toml_node *config::TOMLParser::parseMap(void)
{
tokenizer.rollBackToken();
break;
}
else if (nextToken.type == OPEN_BRACKET)
{
}
std::string key = nextToken.value;
std::cerr << key << std::endl;
@@ -60,7 +67,7 @@ toml_node *config::TOMLParser::parseMap(void)
(*mapObject)[key] = parseString();
break;
}
case ARR_OPEN:
case OPEN_BRACKET:
{
(*mapObject)[key] = parseArray();
break;
@@ -107,10 +114,10 @@ toml_node *config::TOMLParser::parseMap(void)
}
node->setObject(mapObject);
return (node);
}
}
void config::TOMLParser::parseMapArray(void)
{
void TOMLParser::parseMapArray(void)
{
std::cerr << "Parsing MapArray" << std::endl;
toml_node *map_node;
@@ -199,10 +206,10 @@ void config::TOMLParser::parseMapArray(void)
++subname;
}
}
}
toml_node *config::TOMLParser::parseString(void)
{
toml_node *TOMLParser::parseString(void)
{
/* toml_node *node; */
toml_node *node = new toml_node;
std::string *sValue;
@@ -213,10 +220,10 @@ toml_node *config::TOMLParser::parseString(void)
node->setString(sValue);
return (node);
}
}
toml_node *config::TOMLParser::parseNumber(void)
{
toml_node *TOMLParser::parseNumber(void)
{
toml_node *node = new toml_node;
int value;
@@ -226,10 +233,10 @@ toml_node *config::TOMLParser::parseNumber(void)
node->setNumber(value);
return (node);
}
}
toml_node *config::TOMLParser::parseArray(void)
{
toml_node *TOMLParser::parseArray(void)
{
std::cerr << "Parsing array" << std::endl;
toml_node *node;
toml_node *result = new toml_node;
@@ -246,7 +253,7 @@ toml_node *config::TOMLParser::parseArray(void)
current = tokenizer.getToken();
switch (current.type)
{
case ARR_OPEN:
case OPEN_BRACKET:
{
node = parseArray();
break;
@@ -284,7 +291,7 @@ toml_node *config::TOMLParser::parseArray(void)
current = tokenizer.getToken();
if (current.type == COMMA)
continue;
else if (current.type == ARR_CLOSE)
else if (current.type == CLOSE_BRACKET)
completed = true;
else
throw std::invalid_argument("Unexpected token in array!");
@@ -292,10 +299,10 @@ toml_node *config::TOMLParser::parseArray(void)
}
result->setArr(array);
return (result);
}
}
toml_node *config::TOMLParser::parseBool(void)
{
toml_node *TOMLParser::parseBool(void)
{
toml_node *node = new toml_node;
bool value;
@@ -310,19 +317,19 @@ toml_node *config::TOMLParser::parseBool(void)
node->setBool(value);
return (node);
}
}
toml_node *config::TOMLParser::parseNil(void)
{
toml_node *TOMLParser::parseNil(void)
{
toml_node *node = new toml_node;
std::cerr << "Parsing NIL" << std::endl;
node->setNil();
return (node);
}
}
/* parse tha root ! */
TOMLMap *config::TOMLParser::parse(void)
{
/* parse tha root ! */
TOMLMap *TOMLParser::parse(void)
{
std::cerr << "Parsing ROOT" << std::endl;
root = new TOMLMap;
bool completed = false;
@@ -358,7 +365,7 @@ TOMLMap *config::TOMLParser::parse(void)
(*root)[key] = parseString();
break;
}
case ARR_OPEN:
case OPEN_BRACKET:
{
(*root)[key] = parseArray();
break;
@@ -400,4 +407,5 @@ TOMLMap *config::TOMLParser::parse(void)
}
}
return (root);
}
}

View File

@@ -108,13 +108,13 @@ namespace config
}
else
{
token.type = ARR_OPEN;
token.type = OPEN_BRACKET;
file.seekg(prev_pos);
}
}
else if (c == ']')
token.type = ARR_CLOSE;
token.type = CLOSE_BRACKET;
else if (c == '=')
token.type = ASSIGN;
else if (c == '\n')