From c9b0d0875a6969ebbd70fcd1d9ba1f7db6603001 Mon Sep 17 00:00:00 2001 From: Kyler Date: Thu, 12 Jun 2025 22:33:50 -0600 Subject: [PATCH] Code cleanup --- src/lexer.c | 7 ++++++- src/main.c | 14 ++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/lexer.c b/src/lexer.c index 3aeab3f..90aa745 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -79,7 +79,12 @@ static char is_identifier_char(char c) { } static TokenResult lexer_result(Lexer *lexer, TokenType type, size_t start, size_t start_line) { - return (TokenResult){SYNC_RESULT, .result = (Token){type, &lexer->source[start], lexer->pos - start, get_file_info(lexer, start, start_line)}}; + return (TokenResult){SYNC_RESULT, .result = (Token){ + type, + &lexer->source[start], + lexer->pos - start, + get_file_info(lexer, start, start_line) + }}; } static TokenResult lexer_error(Lexer *lexer, const char *message, size_t start, size_t start_line) { diff --git a/src/main.c b/src/main.c index bed92fe..fb6078b 100644 --- a/src/main.c +++ b/src/main.c @@ -3,14 +3,16 @@ #include "sync/types.h" #include "sync/lexer.h" +const char *TOKEN_TYPES[] = { + "EOF", "IDENTIFIER", "NUMBER", "OPERATOR", + "LPAREN", "RPAREN", "SEMICOLON", "LBRACE", + "RBRACE", "LBRACKET", "RBRACKET", "CHARACTER", + "STRING" +}; + static void print_token(Token token) { printf("Token: %-15s | Text: %.*s\n", - (const char *[]){ - "EOF", "IDENTIFIER", "NUMBER", "OPERATOR", - "LPAREN", "RPAREN", "SEMICOLON", "LBRACE", - "RBRACE", "LBRACKET", "RBRACKET", "CHARACTER", - "STRING" - }[token.type], + TOKEN_TYPES[token.type], (int)token.length, token.start ); }