brought back namespaces because i think i get it
now
This commit is contained in:
@ -4,7 +4,9 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
struct token {
|
namespace token {
|
||||||
TokenType type;
|
struct token {
|
||||||
|
token::Type type;
|
||||||
std::string literal;
|
std::string literal;
|
||||||
};
|
};
|
||||||
|
} // namespace token
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
|
namespace token {
|
||||||
|
|
||||||
// X-macro list of token types and their string representations
|
// X-macro list of token types and their string representations
|
||||||
#define TOKEN_LIST \
|
#define TOKEN_LIST \
|
||||||
X(ILLEGAL, "ILLEGAL") \
|
X(ILLEGAL, "ILLEGAL") \
|
||||||
@ -21,26 +23,27 @@
|
|||||||
X(FUNCTION, "FUNCTION") \
|
X(FUNCTION, "FUNCTION") \
|
||||||
X(LET, "LET")
|
X(LET, "LET")
|
||||||
|
|
||||||
// Define the TokenType enum using the X-macro
|
// Define the TokenType enum using the X-macro
|
||||||
enum class TokenType {
|
enum class type {
|
||||||
#define X(name, str) name,
|
#define X(name, str) name,
|
||||||
TOKEN_LIST
|
TOKEN_LIST
|
||||||
#undef X
|
#undef X
|
||||||
};
|
};
|
||||||
|
|
||||||
// Array mapping enum values to their string representations
|
// Array mapping enum values to their string representations
|
||||||
static constexpr std::
|
static constexpr std::
|
||||||
array<std::string_view, static_cast<size_t>(TokenType::LET) + 1>
|
array<std::string_view, static_cast<size_t>(type::LET) + 1>
|
||||||
tokenTypeStrings = {
|
tokenTypeStrings = {
|
||||||
#define X(name, str) str,
|
#define X(name, str) str,
|
||||||
TOKEN_LIST
|
TOKEN_LIST
|
||||||
#undef X
|
#undef X
|
||||||
};
|
};
|
||||||
|
|
||||||
// Stream insertion operator using the lookup array
|
// Stream insertion operator using the lookup array
|
||||||
inline std::ostream& operator<<(std::ostream& os, TokenType type) {
|
inline std::ostream& operator<<(std::ostream& os, type type) {
|
||||||
auto idx = static_cast<size_t>(type);
|
auto idx = static_cast<size_t>(type);
|
||||||
if (idx < tokenTypeStrings.size())
|
if (idx < tokenTypeStrings.size())
|
||||||
return os << tokenTypeStrings[idx];
|
return os << tokenTypeStrings[idx];
|
||||||
return os << "Unknown";
|
return os << "Unknown";
|
||||||
}
|
}
|
||||||
|
} // namespace token
|
||||||
|
Reference in New Issue
Block a user