aboutsummaryrefslogtreecommitdiff
path: root/src/lexer
diff options
context:
space:
mode:
Diffstat (limited to 'src/lexer')
-rw-r--r--src/lexer/token.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/lexer/token.c b/src/lexer/token.c
index 490c7b1..966a443 100644
--- a/src/lexer/token.c
+++ b/src/lexer/token.c
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/09 13:38:08 by charles #+# #+# */
-/* Updated: 2020/06/09 17:55:23 by charles ### ########.fr */
+/* Updated: 2020/06/15 11:38:24 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -16,10 +16,11 @@ t_token *token_new(enum e_token_tag tag, char *content)
{
t_token *token;
- if (content == NULL
- || (token = (t_token*)malloc(sizeof(t_token))) == NULL)
+ if ((token = (t_token*)malloc(sizeof(t_token))) == NULL)
return (NULL);
- if ((token->content = ft_strdup(content)) == NULL)
+ if (content == NULL)
+ token->content = NULL;
+ else if ((token->content = ft_strdup(content)) == NULL)
{
free(token);
return (NULL);
@@ -33,3 +34,14 @@ void token_destroy(t_token *token)
free(token->content);
free(token);
}
+
+void token_destroy_lst(t_ftlst *tokens)
+{
+ ft_lstdestroy(&tokens, (void (*)(void*))token_destroy);
+}
+
+void token_destroy_lst2(t_ftlst *tokens1, t_ftlst *tokens2)
+{
+ ft_lstdestroy(&tokens1, (void (*)(void*))token_destroy);
+ ft_lstdestroy(&tokens2, (void (*)(void*))token_destroy);
+}