extended lexer to new keywords

This commit is contained in:
Karma Riuk
2025-06-30 00:36:31 +02:00
parent 5cc7147909
commit 7973f7522c
3 changed files with 43 additions and 71 deletions

View File

@@ -6,10 +6,11 @@
namespace token {
// Array mapping enum values to their string representations
constexpr std::array<std::string_view, static_cast<size_t>(type::LET) + 1>
tokenTypeStrings = {
constexpr std::
array<std::string_view, static_cast<size_t>(type::RETURN) + 1>
tokenTypeStrings = {
#define X(name, str) str,
TOKEN_LIST
TOKEN_LIST
#undef X
};
@@ -24,6 +25,11 @@ namespace token {
static std::unordered_map<std::string, type> keywords{
{"fn", type::FUNCTION},
{"let", type::LET},
{"if", type::IF},
{"else", type::ELSE},
{"true", type::TRUE},
{"false", type::FALSE},
{"return", type::RETURN},
};
type lookup_identifier(std::string ident) {

View File

@@ -24,8 +24,13 @@ namespace token {
X(RPAREN, ")") \
X(LBRACE, "{") \
X(RBRACE, "}") \
X(LET, "LET") \
X(FUNCTION, "FUNCTION") \
X(LET, "LET")
X(IF, "IF") \
X(ELSE, "ELSE") \
X(TRUE, "TRUE") \
X(FALSE, "FALSE") \
X(RETURN, "RETURN")
// Define the TokenType enum using the X-macro
enum class type {