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);
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 {
}
}
+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];
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];
}
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;
}
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;
}
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;