From cc0300b66cd8abed7a34b50dd6862dbcb522231e Mon Sep 17 00:00:00 2001 From: Pasha Bibko <156938226+PashaBibko@users.noreply.github.com> Date: Sun, 20 Jul 2025 18:38:42 +0100 Subject: [PATCH] Fixed bugs with lexer --- Common/IO.h | 4 ++-- Lexer/src/Lexer.cpp | 6 +++--- Lexer/src/Token.cpp | 6 +++--- example/example.lx | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Common/IO.h b/Common/IO.h index a60077d..4874309 100644 --- a/Common/IO.h +++ b/Common/IO.h @@ -115,7 +115,7 @@ namespace LXC::Util if (log.is_open()) _UNLIKELY { // Opening symbol to make the log look fancy // - log << "[LXC-M] \""; + log << "[LXC] \""; // Fowards the arguments to the log and flushes // (log << ... << args); @@ -135,7 +135,7 @@ namespace LXC::Util if (log.is_open()) _UNLIKELY { // Opening symbol to make log look fancy // - log << "[LXC-S] "; + log << "[LXC] "; // Logic if it can call LogStr() // if constexpr (HasLogStrFunc) diff --git a/Lexer/src/Lexer.cpp b/Lexer/src/Lexer.cpp index 8a83a18..bd50c3f 100644 --- a/Lexer/src/Lexer.cpp +++ b/Lexer/src/Lexer.cpp @@ -57,7 +57,7 @@ namespace LXC::Lexer // Creates the token (if at the end of the string literal) // if (!trackers.inStrLiteral) - ctx.out.emplace_back(ctx, trackers.sectionStart, (USHORT)(ctx.index - trackers.sectionStart), Token::String_Literal); + ctx.out.emplace_back(ctx, trackers.sectionStart + 1, (USHORT)(ctx.index - trackers.sectionStart - 1), 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.emplace_back(ctx, trackers.sectionStart, (USHORT)(ctx.index - trackers.sectionStart), Token::Num_Literal); + ctx.out.emplace_back(ctx, trackers.sectionStart, (USHORT)(ctx.index - trackers.sectionStart + 1), 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.emplace_back(ctx, trackers.sectionStart, static_cast(ctx.index - trackers.sectionStart), Token::Identifier); + ctx.out.emplace_back(ctx, trackers.sectionStart, (USHORT)(ctx.index - trackers.sectionStart + 1), Token::Identifier); trackers.inIdentifier = false; } } diff --git a/Lexer/src/Token.cpp b/Lexer/src/Token.cpp index c817c0b..9992edf 100644 --- a/Lexer/src/Token.cpp +++ b/Lexer/src/Token.cpp @@ -78,12 +78,12 @@ namespace LXC::Lexer { // Output stream to log to // std::ostringstream os; - os << std::setw(15) << std::left << TokenTypeToCStr(type) << " | "; + os << std::setw(25) << std::left << TokenTypeToCStr(type) << " | "; if (contents != nullptr) - os << '"' << contents << '"'; + os << std::setw(25) << std::left << std::string('"' + std::string(contents) + '"'); else - os << "EMPTY"; + os << std::setw(25) << std::left << "EMPTY"; return os.str(); } diff --git a/example/example.lx b/example/example.lx index 02c30d5..1c8f718 100644 --- a/example/example.lx +++ b/example/example.lx @@ -1 +1 @@ -FILE CONTENTS GO HERE +FILE 4 CONTENTS "A" GO B HERE 34 "ELLO THER"