From: Brendan Hansen Date: Thu, 31 Aug 2023 19:22:13 +0000 (-0500) Subject: fixed: printing symbol name instead of "TOKEN_TYPE_SYMBOL" X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=251eeba3886e2adc770fce7c43053ec1961a0adf;p=onyx.git fixed: printing symbol name instead of "TOKEN_TYPE_SYMBOL" --- diff --git a/compiler/include/lex.h b/compiler/include/lex.h index bc9b0cf3..9a0638a3 100644 --- a/compiler/include/lex.h +++ b/compiler/include/lex.h @@ -112,7 +112,8 @@ typedef struct OnyxTokenizer { bh_arr(OnyxToken) tokens; } OnyxTokenizer; -const char* token_name(TokenType tkn_type); +const char *token_type_name(TokenType tkn_type); +const char* token_name(OnyxToken *tkn); void token_toggle_end(OnyxToken* tkn); OnyxToken* onyx_get_token(OnyxTokenizer* tokenizer); OnyxTokenizer onyx_tokenizer_create(bh_allocator allocator, bh_file_contents *fc); diff --git a/compiler/src/lex.c b/compiler/src/lex.c index 40d88478..5853b5c9 100644 --- a/compiler/src/lex.c +++ b/compiler/src/lex.c @@ -119,7 +119,7 @@ static inline b32 token_lit(OnyxTokenizer* tokenizer, OnyxToken* tk, char* lit, return 1; } -const char* token_name(TokenType tkn_type) { +const char *token_type_name(TokenType tkn_type) { if (tkn_type < Token_Type_Ascii_End) { return bh_aprintf(global_scratch_allocator, "%c", (char) tkn_type); } else { @@ -127,6 +127,16 @@ const char* token_name(TokenType tkn_type) { } } +const char* token_name(OnyxToken * tkn) { + TokenType tkn_type = tkn->type; + + if (tkn_type == Token_Type_Symbol) { + return bh_aprintf(global_scratch_allocator, "%b", tkn->text, tkn->length); + } + + return token_type_name(tkn_type); +} + void token_toggle_end(OnyxToken* tkn) { static char backup = 0; char tmp = tkn->text[tkn->length]; diff --git a/compiler/src/parser.c b/compiler/src/parser.c index 6b39d538..82d4d708 100644 --- a/compiler/src/parser.c +++ b/compiler/src/parser.c @@ -127,7 +127,7 @@ static OnyxToken* expect_token(OnyxParser* parser, TokenType token_type) { consume_token(parser); if (token->type != token_type) { - onyx_report_error(token->pos, Error_Critical, "expected token '%s', got '%s'.", token_name(token_type), token_name(token->type)); + onyx_report_error(token->pos, Error_Critical, "expected token '%s', got '%s'.", token_type_name(token_type), token_name(token)); parser->hit_unexpected_token = 1; // :LinearTokenDependent parser->curr = &parser->tokenizer->tokens[bh_arr_length(parser->tokenizer->tokens) - 1]; @@ -620,7 +620,7 @@ static AstTyped* parse_factor(OnyxParser* parser) { } if (parser->curr->type != '{') { - onyx_report_error(parser->curr->pos, Error_Critical, "Expected '{' after 'do', got '%s'.", token_name(parser->curr->type)); + onyx_report_error(parser->curr->pos, Error_Critical, "Expected '{' after 'do', got '%s'.", token_name(parser->curr)); retval = NULL; break; } @@ -906,7 +906,7 @@ static AstTyped* parse_factor(OnyxParser* parser) { default: no_match: - onyx_report_error(parser->curr->pos, Error_Critical, "Unexpected token '%s'.", token_name(parser->curr->type)); + onyx_report_error(parser->curr->pos, Error_Critical, "Unexpected token '%s'.", token_name(parser->curr)); return NULL; } @@ -3742,7 +3742,7 @@ static void parse_top_level_statement(OnyxParser* parser) { if (symbol_token->type > Token_Type_Keyword_Start && symbol_token->type < Token_Type_Keyword_End) { onyx_report_error(directive_token->pos, Error_Critical, "Did you mean the keyword, '%s'?", - token_name(symbol_token->type)); + token_name(symbol_token)); } return;