diff --git a/src/main.cpp b/src/main.cpp index 797cb44..cc3a0c6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,7 +3,7 @@ #include int main() { - auto eof = TokenType::ILLEGAL; + token::type eof = token::type::ILLEGAL; std::cout << eof << std::endl; return 0; } diff --git a/src/token/type.cpp b/src/token/type.cpp new file mode 100644 index 0000000..48454da --- /dev/null +++ b/src/token/type.cpp @@ -0,0 +1,21 @@ +#include "type.hpp" + +namespace token { + + // Array mapping enum values to their string representations + constexpr std::array(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(type); + if (idx < tokenTypeStrings.size()) + return os << tokenTypeStrings[idx]; + return os << "Unknown"; + } + +} // namespace token diff --git a/src/token/type.hpp b/src/token/type.hpp index 2a7dd17..48b0d7e 100644 --- a/src/token/type.hpp +++ b/src/token/type.hpp @@ -30,20 +30,5 @@ namespace token { #undef X }; - // Array mapping enum values to their string representations - static constexpr std:: - array(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(type); - if (idx < tokenTypeStrings.size()) - return os << tokenTypeStrings[idx]; - return os << "Unknown"; - } + std::ostream& operator<<(std::ostream& os, type type); } // namespace token