mirror of
https://github.com/3lswear/webserv.git
synced 2025-10-29 05:17:59 +03:00
feat: add comment handling
This commit is contained in:
@@ -40,6 +40,7 @@ namespace config
|
|||||||
}
|
}
|
||||||
Tokenizer::Tokenizer(char *filename)
|
Tokenizer::Tokenizer(char *filename)
|
||||||
{
|
{
|
||||||
|
last_token = NO_TOK;
|
||||||
file.open(filename, std::ios::in);
|
file.open(filename, std::ios::in);
|
||||||
if (!file.good())
|
if (!file.good())
|
||||||
{
|
{
|
||||||
@@ -50,7 +51,7 @@ namespace config
|
|||||||
bool Tokenizer::firstToken()
|
bool Tokenizer::firstToken()
|
||||||
{
|
{
|
||||||
// doesn't account for indent!
|
// doesn't account for indent!
|
||||||
if (file.tellg() == 0 || file.tellg() == 1 || (last_token == NEWLINE))
|
if (file.tellg() == 0 || file.tellg() == 1 || (last_token == NEWLINE || last_token == NO_TOK))
|
||||||
return (true);
|
return (true);
|
||||||
else
|
else
|
||||||
return (false);
|
return (false);
|
||||||
@@ -198,10 +199,37 @@ namespace config
|
|||||||
else if (c == ',')
|
else if (c == ',')
|
||||||
token.type = COMMA;
|
token.type = COMMA;
|
||||||
else if (c == '#')
|
else if (c == '#')
|
||||||
token.type = COMMENT;
|
{
|
||||||
|
// consume all comments
|
||||||
|
do
|
||||||
|
file.get(c);
|
||||||
|
while (c != '\n' || file.eof());
|
||||||
|
DBOUT << "getting comment token" << ENDL;
|
||||||
|
if (last_token == NO_TOK || last_token == NEWLINE)
|
||||||
|
{
|
||||||
|
DBOUT << "getting first token instead of comment" << ENDL;
|
||||||
|
struct s_token actual;
|
||||||
|
actual.type = NEWLINE;
|
||||||
|
while (actual.type == NEWLINE)
|
||||||
|
actual = getToken();
|
||||||
|
DBOUT
|
||||||
|
<< "actual token: '"
|
||||||
|
<< actual.value << "', type: "
|
||||||
|
<< actual.type
|
||||||
|
<< ENDL;
|
||||||
|
token = actual;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
token.type = NEWLINE;
|
||||||
|
|
||||||
|
}
|
||||||
last_token = token.type;
|
last_token = token.type;
|
||||||
|
|
||||||
|
DBOUT << YELLO << "GOT " << token.value << ", type: " << token.type << ENDL;
|
||||||
|
|
||||||
return (token);
|
return (token);
|
||||||
}
|
}
|
||||||
|
|
||||||
char Tokenizer::getWithoutWhiteSpace(void)
|
char Tokenizer::getWithoutWhiteSpace(void)
|
||||||
{
|
{
|
||||||
char c = ' ';
|
char c = ' ';
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ namespace config
|
|||||||
OPEN_BRACKET,
|
OPEN_BRACKET,
|
||||||
CLOSE_BRACKET,
|
CLOSE_BRACKET,
|
||||||
MAP_DECL,
|
MAP_DECL,
|
||||||
MAPARRAY_DECL
|
MAPARRAY_DECL,
|
||||||
|
COMMENT,
|
||||||
|
NO_TOK
|
||||||
};
|
};
|
||||||
|
|
||||||
struct s_token
|
struct s_token
|
||||||
|
|||||||
Reference in New Issue
Block a user