From 09a0dc7b6d4e01d72655d3d9dce7eef53ecd5ead Mon Sep 17 00:00:00 2001 From: Karma Riuk Date: Sun, 29 Jun 2025 10:14:04 +0200 Subject: [PATCH] brought back namespaces because i think i get it now --- src/token/token.hpp | 10 ++++++---- src/token/type.hpp | 37 ++++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/token/token.hpp b/src/token/token.hpp index 115b75c..8b35420 100644 --- a/src/token/token.hpp +++ b/src/token/token.hpp @@ -4,7 +4,9 @@ #include -struct token { - TokenType type; - std::string literal; -}; +namespace token { + struct token { + token::Type type; + std::string literal; + }; +} // namespace token diff --git a/src/token/type.hpp b/src/token/type.hpp index eb75005..2a7dd17 100644 --- a/src/token/type.hpp +++ b/src/token/type.hpp @@ -4,6 +4,8 @@ #include #include +namespace token { + // X-macro list of token types and their string representations #define TOKEN_LIST \ X(ILLEGAL, "ILLEGAL") \ @@ -21,26 +23,27 @@ X(FUNCTION, "FUNCTION") \ X(LET, "LET") -// Define the TokenType enum using the X-macro -enum class TokenType { + // Define the TokenType enum using the X-macro + enum class type { #define X(name, str) name, - TOKEN_LIST + TOKEN_LIST #undef X -}; + }; -// Array mapping enum values to their string representations -static constexpr std:: - array(TokenType::LET) + 1> - tokenTypeStrings = { + // Array mapping enum values to their string representations + static constexpr std:: + array(type::LET) + 1> + tokenTypeStrings = { #define X(name, str) str, - TOKEN_LIST + TOKEN_LIST #undef X -}; + }; -// Stream insertion operator using the lookup array -inline std::ostream& operator<<(std::ostream& os, TokenType type) { - auto idx = static_cast(type); - if (idx < tokenTypeStrings.size()) - return os << tokenTypeStrings[idx]; - return os << "Unknown"; -} + // Stream insertion operator using the lookup array + inline std::ostream& operator<<(std::ostream& os, type type) { + auto idx = static_cast(type); + if (idx < tokenTypeStrings.size()) + return os << tokenTypeStrings[idx]; + return os << "Unknown"; + } +} // namespace token