ast bigest fix + norm

This commit is contained in:
gazhonsepaskwa
2025-02-15 13:43:26 +01:00
parent d9687a8e3a
commit 07cf3a7066
11 changed files with 70 additions and 54 deletions

View File

@@ -32,7 +32,7 @@ int is_export_valid(char *str)
while ((++str) < key_end)
{
if (!ft_isalnum(*str) && *str != '_')
return (0);
return (0);
}
return (1);
}

View File

@@ -12,12 +12,12 @@
#include "../../includes/minishell.h"
int is_append(char *str)
int is_append(char *str)
{
if (*(ft_strchr(str, '=') - 1) == '+')
return (1);
return (1);
else
return (0);
return (0);
}
void set_new_export(char *str, t_ast_n *node)
@@ -37,5 +37,4 @@ void set_new_export(char *str, t_ast_n *node)
}
else
set_var_env(str, NULL, node->msh);
}

View File

@@ -13,32 +13,6 @@
#include "../../../../includes/minishell.h"
#include <string.h>
static int last_tok_subsh(t_node *lst)
{
while (lst)
{
if ((lst->next == NULL) && !ft_strncmp(lst->val, ")", 1))
return (1);
lst = lst->next;
}
return (0);
}
static int last_tok_redir(t_node *lst)
{
while (lst)
{
if ((lst->next == NULL || lst->next->pressision == D_RED_R
|| lst->next->pressision == RED_R
|| lst->next->pressision == RED_L
|| lst->next->pressision == HEREDOC) && !ft_strncmp(lst->val,
")", 1))
return (1);
lst = lst->next;
}
return (0);
}
static void skip_parentheses(t_node **lst)
{
if (!ft_strncmp((*lst)->val, "(", 1))
@@ -69,15 +43,31 @@ static t_node *find_token(char *tok, t_node *lst)
return (NULL);
}
static t_node *rfind_token(char *tok, t_node *lst)
{
t_node *lst_it;
lst_it = NULL;
while (lst)
{
skip_parentheses(&lst);
if (lst && !ft_strncmp(lst->val, tok, ft_strlen(tok)))
lst_it = lst;
if (lst)
lst = lst->next;
}
return (lst_it);
}
t_node *get_top_token(t_node *lst, t_state *state)
{
*state = _SUBSH;
if (find_token("&&", lst))
if (rfind_token("&&", lst) > rfind_token("||", lst))
{
*state = _AND;
return (find_token("&&", lst));
}
else if (find_token("||", lst))
else if (rfind_token("||", lst) > rfind_token("&&", lst))
{
*state = _OR;
return (find_token("||", lst));

View File

@@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* top_token_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/15 13:28:47 by nalebrun #+# #+# */
/* Updated: 2025/02/15 13:31:44 by nalebrun ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../../../includes/minishell.h"
int last_tok_subsh(t_node *lst)
{
while (lst)
{
if ((lst->next == NULL) && !ft_strncmp(lst->val, ")", 1))
return (1);
lst = lst->next;
}
return (0);
}
int last_tok_redir(t_node *lst)
{
while (lst)
{
if ((lst->next == NULL || lst->next->pressision == D_RED_R
|| lst->next->pressision == RED_R
|| lst->next->pressision == RED_L
|| lst->next->pressision == HEREDOC) && !ft_strncmp(lst->val,
")", 1))
return (1);
lst = lst->next;
}
return (0);
}

View File

@@ -62,7 +62,6 @@ 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);
ast = get_ast(msh, lst);
debug_dio_ast(ast, dio);
if (!ast)

View File

@@ -75,7 +75,7 @@ int syntax_error(t_node *head)
return (syntax_err_mess(cpy->val, 0));
while (cpy)
{
if (redir_error(cpy))
if (redir_error(cpy))
return (1);
if (parenthesis_error(cpy))
return (1);

View File

@@ -116,31 +116,17 @@ t_node *tokenize(char *str)
head = tokenize_base(str);
if (!head)
return (NULL);
// debug_token_list(head, "tokenizer base");
if (!trim_nodes(head))
return (NULL);
// debug_token_list(head, "trim");
if (!unstick_nodes(head))
return (NULL);
// debug_token_list(head, "unstick");
stick_quote_node(head, 39);
stick_quote_node(head, '"');
// 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);