Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions includes/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <iostream>
#include <map>
#include <set>
#include <deque>
#include <string>
#include <limits>
#include <sys/stat.h>
Expand Down
29 changes: 27 additions & 2 deletions models/headers/Parser.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,40 @@
#ifndef PARSER_HPP
#define PARSER_HPP

#include <Server.hpp>
#include <ServerContainer.hpp>
#include <utils.hpp>

typedef struct tagParserEntry
{
std::string entryName;
std::deque<std::string> values;
} ParserEntry;

typedef struct tagParserBlock
{
std::string blockName;
std::deque<std::string> headerData;
std::deque<ParserEntry> entries;
std::deque<struct tagParserBlock *> innerBlocks;
} ParserBlock;

class Parser
{
private:
std::vector<Server> _servers;
std::string _filePath;
std::deque<std::string> _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();

Copilot AI Aug 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name 'parseTokinizer' contains a spelling error. It should be 'parseTokenizer'.

Suggested change
void parseTokinizer();
void parseTokenizer();

Copilot uses AI. Check for mistakes.
ParserBlock *parserPrepBlocks();
ServerContainer *parserProcess();

public:
Parser(const std::string &filePath);

Copilot AI Aug 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructor declaration is missing the destructor declaration. The destructor is implemented in the .cpp file but not declared in the header.

Suggested change
Parser(const std::string &filePath);
Parser(const std::string &filePath);
~Parser();

Copilot uses AI. Check for mistakes.
ServerContainer *parseFile();
};

#endif
41 changes: 24 additions & 17 deletions models/srcs/Parser.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
#include <Parser.hpp>

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

Copilot AI Aug 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name 'parseTokinizer' contains a spelling error. It should be 'parseTokenizer'.

Suggested change
void Parser::parseTokinizer()
void Parser::parseTokenizer()

Copilot uses AI. Check for mistakes.
{
}

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();

Copilot AI Aug 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using raw pointer with 'new' without corresponding 'delete' can lead to memory leaks. Consider using smart pointers or ensure proper memory management.

Copilot uses AI. Check for mistakes.

Copilot AI Aug 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using raw pointer with 'new' without corresponding 'delete' can lead to memory leaks. Consider using smart pointers or ensure proper memory management.

Copilot uses AI. Check for mistakes.

Copilot AI Aug 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ParserBlock pointer returned from parserPrepBlocks() is not used or freed, creating a potential memory leak.

Suggested change
ServerContainer* serverContainer = parserProcess();
ServerContainer* serverContainer = parserProcess();
delete parserBlock;

Copilot uses AI. Check for mistakes.
return serverContainer;
}