fixed token header and made the tokenTypeStrings

not seeable from outside modules
This commit is contained in:
Karma Riuk
2025-06-29 10:43:12 +02:00
parent 9ad9a0b85b
commit 2aff81ba4c
3 changed files with 23 additions and 17 deletions

View File

@ -3,7 +3,7 @@
#include <iostream> #include <iostream>
int main() { int main() {
auto eof = TokenType::ILLEGAL; token::type eof = token::type::ILLEGAL;
std::cout << eof << std::endl; std::cout << eof << std::endl;
return 0; return 0;
} }

21
src/token/type.cpp Normal file
View File

@ -0,0 +1,21 @@
#include "type.hpp"
namespace token {
// Array mapping enum values to their string representations
constexpr std::array<std::string_view, static_cast<size_t>(type::LET) + 1>
tokenTypeStrings = {
#define X(name, str) str,
TOKEN_LIST
#undef X
};
// Stream insertion operator using the lookup array
std::ostream& operator<<(std::ostream& os, type type) {
auto idx = static_cast<size_t>(type);
if (idx < tokenTypeStrings.size())
return os << tokenTypeStrings[idx];
return os << "Unknown";
}
} // namespace token

View File

@ -30,20 +30,5 @@ namespace token {
#undef X #undef X
}; };
// Array mapping enum values to their string representations std::ostream& operator<<(std::ostream& os, type type);
static constexpr std::
array<std::string_view, static_cast<size_t>(type::LET) + 1>
tokenTypeStrings = {
#define X(name, str) str,
TOKEN_LIST
#undef X
};
// Stream insertion operator using the lookup array
inline std::ostream& operator<<(std::ostream& os, type type) {
auto idx = static_cast<size_t>(type);
if (idx < tokenTypeStrings.size())
return os << tokenTypeStrings[idx];
return os << "Unknown";
}
} // namespace token } // namespace token