This commit is contained in:
Nathan Lebrun
2025-01-29 11:40:30 +01:00
parent 9bce0bf9cb
commit 64100fe0f4
19 changed files with 29 additions and 91 deletions

View File

@@ -36,7 +36,7 @@ $(NAME): $(LIBFT) $(OBJS)
# test part
TEST_SRCDIR = tests
TEST_SRCDIR = test
TEST_OBJDIR = .TEST_objs
TEST_SRCS = $(shell find $(TEST_SRCDIR) -name "*.c")
TEST_OBJS = $(patsubst $(TEST_SRCDIR)/%.c, $(TEST_OBJDIR)/%.o, $(TEST_SRCS))
@@ -46,8 +46,8 @@ $(TEST_OBJDIR)/%.o: $(TEST_SRCDIR)/%.c
@mkdir -p $(dir $@)
@$(CC) $(WFLAGS) -MMD -MP -I$(INCDIR) -c $< -g3 -ggdb -o $@ $(LINK)
tests: $(LIBFT) $(TEST_OBJS)
@$(CC) $(WFLAGS) $(TEST_OBJS) $(LIBFT) -o test $(LINK)
parser: $(LIBFT) $(TEST_OBJS)
@$(CC) $(WFLAGS) $(TEST_OBJS) $(LIBFT) -o parser $(LINK)
@echo "$(CYAN)Test build completed: test$(RESET)"
# test part end

BIN
parser Executable file

Binary file not shown.

View File

@@ -47,10 +47,11 @@ void setup_cmd(t_ast_n *node, char *cmd, char *args)
node->args = ft_split(args, " ");
}
t_ast_n *return_hardcode_ast(char **envp)
t_ast_n *get_ast(char **envp, t_node *lst)
{
t_ast_n *head;
(void)lst;
// head
head = created_ast_n(_AND, NULL, NULL);
head->env = init_env(envp);
@@ -72,7 +73,7 @@ t_ast_n *return_hardcode_ast(char **envp)
// right
head->left->right->right = created_ast_n(_CMD, head->left->right, head);
setup_cmd(head->left->right->right, "echo", "echo coucou");
// right
head->right = created_ast_n(_PLINE, head, head);
head->right->pline = malloc(sizeof(t_ast_n *) * 4);
@@ -81,11 +82,11 @@ t_ast_n *return_hardcode_ast(char **envp)
setup_cmd(head->right->pline[0], "ls", "ls");
// ===1===
head->right->pline[1] = created_ast_n(_AND, head->right, head);
// left
head->right->pline[1]->left = created_ast_n(_CMD, head->right->pline[1], head);
setup_cmd(head->right->pline[1]->left, "echo", "echo coucou");
// right
head->right->pline[1]->right = created_ast_n(_CMD, head->right->pline[1], head);
setup_cmd(head->right->pline[1]->right, "echo", "echo coucou");
@@ -93,7 +94,7 @@ t_ast_n *return_hardcode_ast(char **envp)
// ===2===
head->right->pline[2] = created_ast_n(_CMD, head->right, head);
setup_cmd(head->right->pline[2], "cat", "cat -e");
// ===NULL===
head->right->pline[3] = NULL;

View File

@@ -15,6 +15,7 @@
/*# include "../../includes/env.h"*/
# include "../../lib/libft/libft.h"
# include "../tokenizer/tokenizer.h"
typedef enum e_state
{
@@ -54,7 +55,7 @@ typedef struct s_ast_n
char **env;
} t_ast_n;
t_ast_n *return_hardcode_ast(char **envp);
t_ast_n *get_ast(char **envp, t_node *lst);
// env TMP
char **init_env(char **envp);

View File

@@ -13,11 +13,13 @@
#ifndef PARSING_H
# define PARSING_H
# define DEBUG 1
# include "tokenizer/tokenizer.h"
# include "ast/ast.h"
# include "drawio/drawio.h"
// drawio
# include "drawio/drawio.h"
// tmp_env
char **init_env(char **envp);

View File

@@ -11,7 +11,6 @@
/* ************************************************************************** */
#include "parsing.h"
/*#include "../includes/env.h"*/
void truncate_comment(char *str)
{
@@ -37,37 +36,34 @@ void truncate_comment(char *str)
}
}
/*static t_data *init_data(char **envp)*/
/*{*/
/* t_data *data;*/
/**/
/* data = malloc (sizeof(t_data));*/
/* data->env = init_env(envp);*/
/* return (data);*/
/*}*/
int main(int ac, char **av, char **envp)
{
t_node *lst;
t_ast_n *ast;
int dio;
/*t_data data;*/
if (ac != 3)
{
ft_error("./test drawio_file command_str\n");
return (1);
}
/*data = init_data(envp);*/
truncate_comment(av[1]);
lst = tokenize(av[2]);
if (!lst)
return (1);
dio = drawio_init(av[1]);
gen_dio_linked_list(lst, dio);
/*debug_linked_list(lst, "ff");*/
ast = return_hardcode_ast(envp);
gen_dio_ast(ast, dio);
drawio_end_file(dio);
if (DEBUG)
{
dio = drawio_init(av[1]);
gen_dio_linked_list(lst, dio);
}
ast = get_ast(envp, lst);
if (!ast)
return (1);
if (DEBUG)
{
gen_dio_ast(ast, dio);
drawio_end_file(dio);
ft_debug(" draw.io file generated !\n");
}
free_linked_list(lst);
}

View File

@@ -81,65 +81,3 @@ int merge_with_next_node(t_node *node)
node->next = tmp_next;
return (1);
}
// have to be deleted after
void debug_linked_list(t_node *head, char *msg)
{
t_node *current;
char *token;
char *pres;
current = head;
printf("----------------------------------------------------------{%s} \n",
msg);
while (current != NULL)
{
// set val for base token
if (current->token == OPERATOR)
token = ft_strdup("OPERATOR");
else if (current->token == WORD)
token = ft_strdup(" WORD");
else if (current->token == UNSET)
token = ft_strdup(" UNSET");
else
token = ft_strdup(" ???");
// set vals for pressision token
if (current->pressision == COMMAND)
pres = ft_strdup("COMMAND ");
else if (current->pressision == UNDEFINED)
pres = ft_strdup("UNDEF ");
else if (current->pressision == AND)
pres = ft_strdup("AND ");
else if (current->pressision == OR)
pres = ft_strdup("OR ");
else if (current->pressision == PIPE)
pres = ft_strdup("PIPE ");
else if (current->pressision == SUBSH_S)
pres = ft_strdup("SUBSH_S ");
else if (current->pressision == SUBSH_E)
pres = ft_strdup("SUBSH_E ");
else if (current->pressision == RED_L)
pres = ft_strdup("RED_L ");
else if (current->pressision == RED_R)
pres = ft_strdup("RED_R ");
else if (current->pressision == HEREDOC)
pres = ft_strdup("HEREDOC ");
else if (current->pressision == D_RED_R)
pres = ft_strdup("D_RED_R ");
else if (current->pressision == PARAMETER)
pres = ft_strdup("PARAMETER");
else if (current->pressision == RED_FILE)
pres = ft_strdup("RED_FILE ");
else if (current->pressision == LIM)
pres = ft_strdup("LIM ");
else
pres = ft_strdup("??? ");
printf("| Node - TOKEN: %s.%s -> val: |%s|\n", token, pres, current->val);
free(token);
free(pres);
current = current->next;
}
printf("----------------------------------------------------------\n\n");
}

View File

@@ -13,7 +13,7 @@
#ifndef TOKENIZER_H
# define TOKENIZER_H
# include "../includes/minishell.h"
# include "../../lib/libft/libft.h"
typedef enum e_token
{