Integrated with newest TracingHeap, refactoring for functions

This commit is contained in:
vegowotenks 2025-01-12 17:40:09 +01:00
parent dfd2f81f3d
commit 702bb6f850
5 changed files with 67 additions and 52 deletions

View file

@ -1,6 +1,8 @@
#include "tokenizer.h"
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <inttypes.h>
static StringView StringViewOfNumberTillNextNonDigit(StringView* source) {
StringView stringViewOfNumber = StringView_Slice(*source, 0, 0);
@ -310,3 +312,54 @@ const char* TokenType_ToString(enum TokenType type)
return "INVALID";
}
void _TokenContent_Print(Token* token)
{
switch (token->type) {
case TOKENTYPE_INTEGER:
printf("%" PRIi64, token->get.integer);
break;
case TOKENTYPE_DOUBLE:
printf("%f", token->get.decimal);
break;
case TOKENTYPE_IDENTIFIER:
case TOKENTYPE_COMMENT:
case TOKENTYPE_STRING:
case TOKENTYPE_ERROR:
printf("%s", token->get.identifier.source);
break;
case TOKENTYPE_NONE:
case TOKENTYPE_LEFT_BRACE:
case TOKENTYPE_RIGHT_BRACE:
case TOKENTYPE_AMPERSAND:
case TOKENTYPE_PLUS:
case TOKENTYPE_MINUS:
case TOKENTYPE_MULTIPLY:
case TOKENTYPE_DIVIDE:
case TOKENTYPE_PIPE:
case TOKENTYPE_ARROW:
case TOKENTYPE_COLON:
case TOKENTYPE_SEMICOLON:
case TOKENTYPE_EQUALITY:
case TOKENTYPE_INEQUALITY:
case TOKENTYPE_LESSTHAN:
case TOKENTYPE_LESSEQUAL:
case TOKENTYPE_GREATERTHAN:
case TOKENTYPE_GREATEREQUAL:
case TOKENTYPE_COMMA:
case TOKENTYPE_BIND:
case TOKENTYPE_AS:
case TOKENTYPE_LEFT_PAREN:
case TOKENTYPE_RIGHT_PAREN:
break;
}
}
void Token_Print(Token* token)
{
printf("Token: type: %s, TokenContent: ", TokenType_ToString(token->type));
_TokenContent_Print(token);
printf(" , contex: row: %i, col: %i\n", token->context.row, token->context.col);
}