diff --git a/src/lexer/SolsToken.c b/src/lexer/SolsToken.c index 339641a..986cb07 100644 --- a/src/lexer/SolsToken.c +++ b/src/lexer/SolsToken.c @@ -46,3 +46,18 @@ ResultType(SolsToken, charptr) createSolsToken(SolsTokenType type, ...) { va_end(args); return Success(SolsToken, charptr, token); } + +void freeSolsToken(SolsToken* token) { + if (token->type == STT_IDENTIFIER && token->as.idName != NULL) { + free(token->as.idName); + } + if (token->type == STT_KW_GROUND && token->as.inlineGround != NULL) { + free(token->as.inlineGround); + } + if (token->type == STT_LITERAL) { + freeSolsLiteral(&token->as.literal); + } + if (token->type == STT_TYPE) { + freeSolsType(&token->as.type); + } +} diff --git a/src/lexer/SolsToken.h b/src/lexer/SolsToken.h index d9ea064..9437f97 100644 --- a/src/lexer/SolsToken.h +++ b/src/lexer/SolsToken.h @@ -37,6 +37,9 @@ Result(SolsToken, charptr); // the token holds. See the SolsToken struct for more information. ResultType(SolsToken, charptr) createSolsToken(SolsTokenType type, ...); +// Frees a SolsToken, specifically the .as field elements. +void freeSolsToken(SolsToken* token); + // Represents a Solstice program, seperated into tokens. // .at is a pointer to the tokens // .count is how many tokens are currently being stored