lang: lex: add function for creating fake ident tokens

This commit is contained in:
2025-03-26 21:09:07 +00:00
parent 02ebb5c32b
commit 0c500dc19b
2 changed files with 24 additions and 1 deletions

View File

@@ -1066,6 +1066,27 @@ bool ivy_lexer_tokens_available(struct ivy_lexer *lex)
return false;
}
struct ivy_token *ivy_token_create_ident(const char *s)
{
struct ivy_token *tok = malloc(sizeof *tok);
if (!tok) {
return NULL;
}
memset(tok, 0x0, sizeof *tok);
tok->t_type = IVY_TOK_IDENT;
tok->t_str = b_strdup(s);
if (!tok->t_str) {
free(tok);
return NULL;
}
return tok;
}
void ivy_token_destroy(struct ivy_token *tok)
{
switch (tok->t_type) {