diff --git a/ b/ new file mode 100644 index 0000000..f31fd07 --- /dev/null +++ b/ @@ -0,0 +1 @@ +Hello World tmp.txt diff --git a/.gitignore b/.gitignore index 33650c8..76fe498 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ ast.xml .TEST_objs .mmoat_history .heredoc +run_vg.sh file file2 diff --git a/includes/minishell.h b/includes/minishell.h index 091f8a9..4fc452f 100644 --- a/includes/minishell.h +++ b/includes/minishell.h @@ -33,7 +33,7 @@ # include "exec/exec.h" # include "exec/expander.h" -# define DEBUG 0 +# define DEBUG 1 # ifndef DIO_PATH # define DIO_PATH "ast.xml" diff --git a/srcs/parsing/ast/utils/top_token.c b/srcs/parsing/ast/utils/top_token.c index caa6e69..49c603c 100644 --- a/srcs/parsing/ast/utils/top_token.c +++ b/srcs/parsing/ast/utils/top_token.c @@ -72,8 +72,6 @@ static t_node *find_token(char *tok, t_node *lst) t_node *get_top_token(t_node *lst, t_state *state) { *state = _SUBSH; - if (!ft_strncmp(lst->val, "(", 1) && last_tok_subsh(lst)) - return (lst); if (find_token("&&", lst)) { *state = _AND; @@ -91,6 +89,8 @@ t_node *get_top_token(t_node *lst, t_state *state) } else if (!ft_strncmp(lst->val, "(", 1) && last_tok_redir(lst)) return (lst); + else if (!ft_strncmp(lst->val, "(", 1) && last_tok_subsh(lst)) + return (lst); else { *state = UNDEF; diff --git a/srcs/parsing/parser.c b/srcs/parsing/parser.c index 2791661..a92accb 100644 --- a/srcs/parsing/parser.c +++ b/srcs/parsing/parser.c @@ -61,10 +61,8 @@ t_ast_n *parser(char *input, t_msh *msh) } create_heredoc(lst, msh); if (DEBUG) - { dio = drawio_init(DIO_PATH); - gen_dio_linked_list(lst, dio); - } + // gen_dio_linked_list(lst, dio); ast = get_ast(msh, lst); debug_dio_ast(ast, dio); if (!ast) diff --git a/srcs/parsing/syntax/syntax.c b/srcs/parsing/syntax/syntax.c index 15c7ba2..3926d9e 100644 --- a/srcs/parsing/syntax/syntax.c +++ b/srcs/parsing/syntax/syntax.c @@ -25,7 +25,7 @@ static int parenthesis_error(t_node *cpy) && !ft_strncmp(cpy->next->val, ")", 1)) return (syntax_err_mess(cpy->next->val, 0)); if (cpy->next && !ft_strncmp(cpy->next->val, "(", 1) - && !is_aop_operator(cpy)) + && !is_aop_operator(cpy) && ft_strncmp(cpy->next->val, "(", 1)) return (syntax_err_mess(cpy->next->val, 0)); return (0); } @@ -71,11 +71,15 @@ int syntax_error(t_node *head) t_node *cpy; cpy = head; - if (is_aop_operator(cpy) && cpy->next == NULL) + if (is_aop_operator(cpy)) return (syntax_err_mess(cpy->val, 0)); while (cpy) { - if (redir_error(cpy) || parenthesis_error(cpy) || aop_error(cpy)) + if (redir_error(cpy)) + return (1); + if (parenthesis_error(cpy)) + return (1); + if (aop_error(cpy)) return (1); if (unexpected_token(cpy)) return (syntax_err_mess(cpy->val, 0)); diff --git a/srcs/parsing/tokenizer/tokenizer.c b/srcs/parsing/tokenizer/tokenizer.c index b9d7ed0..70b28dc 100644 --- a/srcs/parsing/tokenizer/tokenizer.c +++ b/srcs/parsing/tokenizer/tokenizer.c @@ -116,19 +116,31 @@ t_node *tokenize(char *str) head = tokenize_base(str); if (!head) return (NULL); - debug_token_list(head, "tokenizer"); + // debug_token_list(head, "tokenizer base"); + if (!trim_nodes(head)) return (NULL); - debug_token_list(head, "tokenizer"); + // debug_token_list(head, "trim"); + if (!unstick_nodes(head)) return (NULL); - debug_token_list(head, "tokenizer"); + // debug_token_list(head, "unstick"); + stick_quote_node(head, 39); stick_quote_node(head, '"'); - debug_token_list(head, "tokenizer"); + // debug_token_list(head, "stick_quote_node"); + set_token(head); + // debug_token_list(head, "set token"); + + if (!trim_nodes(head)) + return (NULL); + // debug_token_list(head, "trim2"); + del_void_nodes(&head); + // debug_token_list(head, "del_void_nodes"); debug_token_list(head, "tokenizer"); + if (syntax_error(head)) return (free_linked_list(head), NULL); return (head);