fixed token header and made the tokenTypeStrings
not seeable from outside modules
This commit is contained in:
@ -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
21
src/token/type.cpp
Normal 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
|
@ -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
|
||||||
|
Reference in New Issue
Block a user