#define _POSIX_C_SOURCE 200809L #include "ast_word.h" #include #include #include struct ast *ast_create_word(char *word) { struct ast_word *ast_node = malloc(sizeof(struct ast_word)); if (ast_node == NULL) return NULL; ast_node->type = AST_WORD; ast_node->word = strdup(word); struct ast *res = ast_create(AST_WORD, ast_node); if (res == NULL) { free(ast_node->word); free(ast_node); return NULL; } return res; } struct ast_word *ast_get_word(struct ast *node) { if (node == NULL || node->type != AST_WORD) return NULL; return node->data; } bool ast_is_word(struct ast *node) { return node && node->type == AST_WORD; } void ast_free_word(struct ast_word *ast_node) { if (ast_node == NULL) return; if (ast_node->word != NULL) free(ast_node->word); free(ast_node); }