create token get value

This commit is contained in:
_N3m0 2024-01-04 15:02:39 +01:00
parent d4d0cc1812
commit 25f9d42e9f
1 changed files with 11 additions and 4 deletions

15
lexer.c
View File

@ -128,18 +128,25 @@ char* getParam(const char* word, int len, char* cursor, int* size){
} }
Token* create_text_token(Token* token, char* cursor){ Token* create_text_token(Token* token, char* cursor){
int i = 0; token = malloc(sizeof(Token));
token->value = malloc(sizeof(char) * DA_LEN);
int i = 0, cap = DA_LEN;
go_back();
do { do {
cursor = nextchar(); cursor = nextchar();
token->value[i] = *cursor;
i++; i++;
if (i >= cap){
cap *= 2;
token->value = realloc(token->value, cap);
}
} while (*cursor != '<'); } while (*cursor != '<');
token->value[i-1] = '\0';
go_back(); go_back();
token = malloc(sizeof(Token));
token->type = TEXT; token->type = TEXT;
token->value = "TODO"; token->len = i-1;
token->len = i;
return token; return token;
} }