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, COMMA,
BOOL, BOOL,
NIL, NIL,
ARR_OPEN, OPEN_BRACKET,
ARR_CLOSE, CLOSE_BRACKET,
MAP_OPEN, MAP_OPEN,
MAP_CLOSE, MAP_CLOSE,
MAPARRAY_DECL MAPARRAY_DECL

View File

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

View File

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