update: exec works !

This commit is contained in:
maix0 2024-10-10 17:41:23 +02:00
parent 2363fadd02
commit 77e7f65b41
24 changed files with 192 additions and 499 deletions

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/07 18:04:13 by rparodi #+# #+# */
/* Updated: 2024/10/09 12:44:24 by maiboyer ### ########.fr */
/* Updated: 2024/10/10 17:28:21 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -37,7 +37,7 @@ t_str token_name(t_token *token);
/// les noms peuvent etre different idk
/// a terme la fonction utilisera t_error et tt;
/// struct s_ast_command `ast/include/ast/_raw_structs.h`
t_ast_node ast_from_cmd(t_token tok);
t_error ast_from_cmd(t_token tok, t_vec_ast *output_queue);
/// en fonction de op, qui peut etre: TOK_AND TOK_PIPE TOK_OR
/// choisir le bon ast_node a faire (t_ast_node->data.list + set operator ou t_asdt_node->data.pipeline)
@ -49,7 +49,7 @@ t_ast_node ast_from_cmd(t_token tok);
/// struct s_ast_list if (tok.type == TOK_AND || tok.type == TOK_OR)
/// struct s_ast_pipeline if (tok.type == TOK_PIPE)
/// `ast/include/ast/_raw_structs.h`
t_ast_node ast_from_op(t_token tok, t_vec_ast *output_queue);
t_error ast_from_op(t_token tok, t_vec_ast *output_queue);
t_error yarn(t_vec_token ts, t_vec_ast *out)
{
@ -63,7 +63,10 @@ t_error yarn(t_vec_token ts, t_vec_ast *out)
while (!vec_token_pop_front(&ts, &tok))
{
if (tok.type == TOK_CMD)
vec_ast_push(&output_queue, ast_from_cmd(tok));
{
if (ast_from_cmd(tok, &output_queue))
return (vec_token_free(stack), vec_ast_free(output_queue), token_free(tok), ERROR);
}
else if (tok.type == TOK_LPAREN)
vec_token_push(&stack, tok);
else if (tok.type == TOK_OR || tok.type == TOK_AND || tok.type == TOK_PIPE)
@ -71,31 +74,38 @@ t_error yarn(t_vec_token ts, t_vec_ast *out)
while (vec_token_last(&stack) != NULL && vec_token_last(&stack)->type != TOK_LPAREN && _get_precedance(vec_token_last(&stack)) > _get_precedance(&tok))
{
vec_token_pop(&stack, &op);
vec_ast_push(&output_queue, ast_from_op(op, &output_queue));
if (ast_from_op(op, &output_queue))
return (vec_token_free(stack), vec_ast_free(output_queue), token_free(tok), token_free(op), ERROR);
}
vec_token_push(&stack, tok);
}
else if (tok.type == TOK_RPAREN)
{
token_free(tok);
// ici il faut modifier pour push dans un ast_node->data.subshell
// je m'occuperai de ca ce soir/after
while (vec_token_last(&stack) != NULL && vec_token_last(&stack)->type != TOK_LPAREN)
{
vec_token_pop(&stack, &op);
vec_ast_push(&output_queue, ast_from_op(op, &output_queue));
if (ast_from_op(op, &output_queue))
return (vec_token_free(stack), vec_ast_free(output_queue), token_free(op), ERROR);
}
if (!(vec_token_last(&stack) != NULL && vec_token_last(&stack)->type == TOK_LPAREN))
return (ERROR);
return (vec_token_free(stack), vec_ast_free(output_queue), ERROR);
vec_token_pop(&stack, &tok);
token_free(tok);
t_ast_node snode;
t_ast_node tmp;
snode = ast_alloc(AST_SUBSHELL);
vec_ast_pop(&output_queue, &tmp);
vec_ast_push(&snode->data.subshell.body, tmp);
vec_ast_push(&output_queue, snode);
}
}
while (!vec_token_pop(&stack, &op))
{
if (op.type == TOK_LPAREN)
return (token_free(tok), ERROR);
vec_ast_push(&output_queue, ast_from_op(op, &output_queue));
return (token_free(op), ERROR);
if (ast_from_op(op, &output_queue))
return (vec_token_free(stack), vec_ast_free(output_queue), token_free(op), ERROR);
}
vec_token_free(ts);
vec_token_free(stack);