Added proper logging capabilities

This commit is contained in:
Pasha Bibko
2025-07-20 18:09:29 +01:00
parent 903b4da7df
commit 9dedcf30b1
6 changed files with 115 additions and 8 deletions

View File

@@ -92,7 +92,9 @@ namespace LXC::Lexer
// Getters for the c-string to stop it being reassigned (or deleted) //
inline const char* const Str() const { return contents; }
operator const char* const() { return contents; }
// Outputs all the relevant infomration in a string for logging purposes //
std::string LogStr() const;
// The type of the token //
const TokenType type;

View File

@@ -36,7 +36,7 @@ namespace LXC::Lexer
} trackers;
while (ctx.index > ctx.len)
while (ctx.index < ctx.len)
{
// The current char within the source that is being lexed //
const char current = ctx.source[ctx.index];
@@ -57,7 +57,7 @@ namespace LXC::Lexer
// Creates the token (if at the end of the string literal) //
if (!trackers.inStrLiteral)
ctx.out.push_back({ ctx, trackers.sectionStart, (USHORT)(ctx.index - trackers.sectionStart), Token::String_Literal });
ctx.out.emplace_back(ctx, trackers.sectionStart, (USHORT)(ctx.index - trackers.sectionStart), Token::String_Literal);
} else if (trackers.inStrLiteral) {}
@@ -71,7 +71,7 @@ namespace LXC::Lexer
// Checks for the end of the number literal to create the token //
if (!IsNumeric(next)) _UNLIKELY
{
ctx.out.push_back({ ctx, trackers.sectionStart, (USHORT)(ctx.index - trackers.sectionStart), Token::Num_Literal });
ctx.out.emplace_back(ctx, trackers.sectionStart, (USHORT)(ctx.index - trackers.sectionStart), Token::Num_Literal);
trackers.inNumLiteral = false;
}
}
@@ -86,7 +86,7 @@ namespace LXC::Lexer
// Checks for the end of the word to create the token //
if (!IsAlpha(next)) _UNLIKELY
{
ctx.out.push_back({ ctx, trackers.sectionStart, (USHORT)(ctx.index - trackers.sectionStart), Token::Identifier });
ctx.out.emplace_back(ctx, trackers.sectionStart, static_cast<unsigned short>(ctx.index - trackers.sectionStart), Token::Identifier);
trackers.inIdentifier = false;
}
}
@@ -94,7 +94,7 @@ namespace LXC::Lexer
// Iterates to the next index //
ctx.column++;
ctx.index++;
}
}
return ctx.out;
}

View File

@@ -23,9 +23,14 @@ namespace LXC::Lexer
Token::~Token()
{
// Frees any allocated memory //
if (contents != nullptr)
delete[] contents;
//if (contents != nullptr)
// delete[] contents;
contents = nullptr;
}
std::string LXC::Lexer::Token::LogStr() const
{
return std::string("CALL LogStr() function");
}
}