This commit is contained in:
2025-01-08 19:04:40 +01:00
parent a987479617
commit aa0fab43e4
6 changed files with 166 additions and 123 deletions

View File

@@ -18,6 +18,7 @@ const char* tokenizerGetTagString(TokenizerTag tag) {
}
}
// clang-format off
const KeywordMap keywords[] = {
{ "addrspace", TOKEN_KEYWORD_ADDRSPACE },
{ "align", TOKEN_KEYWORD_ALIGN },
@@ -69,6 +70,7 @@ const KeywordMap keywords[] = {
{ "volatile", TOKEN_KEYWORD_VOLATILE },
{ "while", TOKEN_KEYWORD_WHILE }
};
// clang-format on
// TODO binary search
static TokenizerTag getKeyword(const char* bytes, const uint32_t len) {
@@ -113,13 +115,11 @@ state:
switch (self->buffer[self->index]) {
case 0:
if (self->index == self->buffer_len) {
return (TokenizerToken) {
.tag = TOKEN_EOF,
return (TokenizerToken) { .tag = TOKEN_EOF,
.loc = {
.start = self->index,
.end = self->index,
}
};
} };
} else {
state = TOKENIZER_STATE_INVALID;
goto state;
@@ -860,13 +860,11 @@ state:
state = TOKENIZER_STATE_INVALID;
goto state;
} else {
return (TokenizerToken) {
.tag = TOKEN_EOF,
return (TokenizerToken) { .tag = TOKEN_EOF,
.loc = {
.start = self->index,
.end = self->index,
}
};
} };
}
break;
case '!':
@@ -935,13 +933,11 @@ state:
state = TOKENIZER_STATE_INVALID;
goto state;
} else {
return (TokenizerToken) {
.tag = TOKEN_EOF,
return (TokenizerToken) { .tag = TOKEN_EOF,
.loc = {
.start = self->index,
.end = self->index,
}
};
} };
}
break;
case '\n':