From e1bf337ded9e7c8e75238a7bfeebf207acab58fe Mon Sep 17 00:00:00 2001 From: gazhonsepaskwa Date: Fri, 14 Feb 2025 08:58:14 +0100 Subject: [PATCH] syntax fixes --- srcs/parsing/ast/nodes/subsh.c | 2 +- srcs/parsing/ast/utils/top_token.c | 2 +- srcs/parsing/syntax/syntax.c | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/srcs/parsing/ast/nodes/subsh.c b/srcs/parsing/ast/nodes/subsh.c index e9d7b85..d49351c 100644 --- a/srcs/parsing/ast/nodes/subsh.c +++ b/srcs/parsing/ast/nodes/subsh.c @@ -23,7 +23,7 @@ t_node *remove_parentheses(t_node *lst) it = lst; it = it->next; deepness = 1; - while (1) + while (it) { str = ft_strdup(it->val); if (it->pressision == SUBSH_S) diff --git a/srcs/parsing/ast/utils/top_token.c b/srcs/parsing/ast/utils/top_token.c index 9577e58..f3c4879 100644 --- a/srcs/parsing/ast/utils/top_token.c +++ b/srcs/parsing/ast/utils/top_token.c @@ -28,7 +28,7 @@ static int last_tok_redir(t_node *lst) { while (lst) { - if ((lst->next == NULL + if ((lst->next == NULL || lst->next->pressision == D_RED_R || lst->next->pressision == RED_R || lst->next->pressision == RED_L diff --git a/srcs/parsing/syntax/syntax.c b/srcs/parsing/syntax/syntax.c index 84897f6..0db4968 100644 --- a/srcs/parsing/syntax/syntax.c +++ b/srcs/parsing/syntax/syntax.c @@ -107,6 +107,10 @@ int syntax_error(t_node *head) return (syntax_err_mess(cpy->val, 0)); while (cpy) { + if (is_redir(cpy) && !cpy->next) + return (syntax_err_mess(cpy->val, 3)); + if (is_redir(cpy) && cpy->next && cpy->next->next && !ft_strncmp(cpy->next->next->val, "(", 1)) + return (syntax_err_mess(cpy->next->next->val, 0)); if (unexpected_token(cpy)) return (syntax_err_mess(cpy->val, 0)); if (cpy->next == NULL && is_aop_operator(cpy)) @@ -115,6 +119,8 @@ int syntax_error(t_node *head) return (syntax_err_mess(cpy->next->val, 0)); if (!ft_strncmp(cpy->val, ")", 1) && cpy->next && !ft_strncmp(cpy->next->val, "(", 1)) return (syntax_err_mess(cpy->next->val, 0)); + if (is_aop_operator(cpy) && !ft_strncmp(cpy->next->val, ")", 1)) + return (syntax_err_mess(cpy->next->val, 0)); if (is_aop_operator(cpy) && is_aop_operator(cpy->next)) return (syntax_err_mess(cpy->next->val, 0)); if (is_aop_operator(cpy) && ft_strlen(cpy->val) > 2)