feat(redirections): ast commands now have a field for the list of redirections + redirections implemented in parser

This commit is contained in:
Matteo Flebus 2026-01-27 21:06:36 +01:00
parent 8a5c589742
commit 399d1ed3e1
3 changed files with 13 additions and 6 deletions

View file

@ -171,6 +171,7 @@ struct ast *parse_command(struct lexer_context *ctx)
struct ast *parse_simple_command(struct lexer_context *ctx)
{
struct list *command_elements = NULL;
struct list *redirections = NULL; // list of redirection ASTs
// WORD
struct token *token = POP_TOKEN();
@ -204,15 +205,15 @@ struct ast *parse_simple_command(struct lexer_context *ctx)
}
else if (ast_is_redir(element))
{
// TODO
perror("NOT IMPLEMENTED");
return NULL;
// append redirections to the list of redirections
redirections = list_append(redirections, element);
}
else
{
perror("Internal error: unexpected return value from parse_element "
"in parse_simple_command");
list_deep_destroy(command_elements);
list_deep_destroy(redirections);
return NULL;
}
@ -221,10 +222,11 @@ struct ast *parse_simple_command(struct lexer_context *ctx)
}
// Result
struct ast *result = ast_create_command(command_elements);
struct ast *result = ast_create_command(command_elements, redirections);
if (result == NULL)
{
list_deep_destroy(command_elements);
list_deep_destroy(redirections);
return NULL;
}
return result;