diff --git a/includes/utils.hpp b/includes/utils.hpp index 0613076..7c2974e 100644 --- a/includes/utils.hpp +++ b/includes/utils.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include diff --git a/models/headers/Parser.hpp b/models/headers/Parser.hpp index 8c50f1c..b918bc2 100644 --- a/models/headers/Parser.hpp +++ b/models/headers/Parser.hpp @@ -1,15 +1,40 @@ #ifndef PARSER_HPP #define PARSER_HPP -#include +#include #include +typedef struct tagParserEntry +{ + std::string entryName; + std::deque values; +} ParserEntry; + +typedef struct tagParserBlock +{ + std::string blockName; + std::deque headerData; + std::deque entries; + std::deque innerBlocks; +} ParserBlock; + class Parser { private: - std::vector _servers; + std::string _filePath; + std::deque _tokens; + /* + I tried to keep the parser 2 phases but dealing with ParserBlock directly can be difficult + because of inner blocks which would require hardcoding the behaviour and especially + inheritance handling which can be painful if we would process entries one by one + */ + void parseTokinizer(); + ParserBlock *parserPrepBlocks(); + ServerContainer *parserProcess(); public: + Parser(const std::string &filePath); + ServerContainer *parseFile(); }; #endif \ No newline at end of file diff --git a/models/srcs/Parser.cpp b/models/srcs/Parser.cpp index 7a2c427..34b558d 100644 --- a/models/srcs/Parser.cpp +++ b/models/srcs/Parser.cpp @@ -1,26 +1,33 @@ #include -Parser::Parser(const std::string &filePath) +Parser::Parser(const std::string &filePath) : _filePath(filePath) { - std::ifstream file(filePath); - if (!file.is_open()) - throw CommonExceptions::OpenFileException(); - try - { - file.exceptions(std::ios::badbit); - - } - catch (...) - { - file.close(); - throw; - } - file.close(); } -Parser::~Parser() {} +Parser::~Parser() +{ +} -void Parser::validateServers() const +void Parser::parseTokinizer() { +} +ParserBlock* Parser::parserPrepBlocks() +{ + ParserBlock* parserBlock = new ParserBlock; + return parserBlock; } + +ServerContainer* Parser::parserProcess() +{ + ServerContainer* serverContainer = new ServerContainer(); + return serverContainer; +} + +ServerContainer* Parser::parseFile() +{ + parseTokinizer(); + ParserBlock* parserBlock = parserPrepBlocks(); + ServerContainer* serverContainer = parserProcess(); + return serverContainer; +} \ No newline at end of file