Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use an array instead of a switch in token_kind_name #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 6 additions & 25 deletions src/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,12 @@ const char *keywords[] = {

const char *token_kind_name(Token_Kind kind)
{
switch (kind) {
case TOKEN_END:
return "end of content";
case TOKEN_INVALID:
return "invalid token";
case TOKEN_PREPROC:
return "preprocessor directive";
case TOKEN_SYMBOL:
return "symbol";
case TOKEN_OPEN_PAREN:
return "open paren";
case TOKEN_CLOSE_PAREN:
return "close paren";
case TOKEN_OPEN_CURLY:
return "open curly";
case TOKEN_CLOSE_CURLY:
return "close curly";
case TOKEN_SEMICOLON:
return "semicolon";
case TOKEN_KEYWORD:
return "keyword";
default:
UNREACHABLE("token_kind_name");
}
return NULL;
char *toknames[] = {
"end of content", "invalid token", "preprocessor directive",
"symbol", "open paren", "close paren", "open curly", "close curly",
"semicolon", "keyword", "comment", "string"
};
return toknames[kind];
}

Lexer lexer_new(Free_Glyph_Atlas *atlas, const char *content, size_t content_len)
Expand Down