fix(merge conflicts)

This commit is contained in:
matteo 2026-01-29 18:52:51 +01:00
parent 6948bbae63
commit 148db79788
2 changed files with 18 additions and 11 deletions

View file

@ -74,7 +74,7 @@ struct ast *parse_prefix(struct lexer_context *ctx)
} }
else if (is_first(*token, RULE_REDIRECTION)) else if (is_first(*token, RULE_REDIRECTION))
return parse_redirection(ctx); return parse_redirection(ctx);
else else
{ {
perror("Syntax error: expected a prefix (redirection or assignment)"); perror("Syntax error: expected a prefix (redirection or assignment)");
return NULL; return NULL;

View file

@ -173,7 +173,7 @@ struct ast *parse_command(struct lexer_context *ctx)
* @return: NULL * @return: NULL
*/ */
static void *err_simple_command(struct list *command_elements, static void *err_simple_command(struct list *command_elements,
struct list *redirections) struct list *redirections)
{ {
list_deep_destroy(command_elements); list_deep_destroy(command_elements);
list_deep_destroy(redirections); list_deep_destroy(redirections);
@ -184,6 +184,7 @@ struct ast *parse_simple_command(struct lexer_context *ctx)
{ {
struct list *command_elements = NULL; struct list *command_elements = NULL;
struct list *redirections = NULL; // list of redirection ASTs struct list *redirections = NULL; // list of redirection ASTs
struct list *assignments = NULL;
bool has_prefix = false; bool has_prefix = false;
struct token *token = PEEK_TOKEN(); struct token *token = PEEK_TOKEN();
@ -192,12 +193,19 @@ struct ast *parse_simple_command(struct lexer_context *ctx)
has_prefix = true; has_prefix = true;
while (is_first(*token, RULE_PREFIX)) while (is_first(*token, RULE_PREFIX))
{ {
struct ast *redir = parse_prefix(ctx); struct ast *prefix = parse_prefix(ctx);
if (redir == NULL) if (prefix == NULL)
{ {
return err_simple_command(command_elements, redirections); return err_simple_command(command_elements, redirections);
} }
redirections = list_append(redirections, redir); if (prefix->type == AST_ASSIGNEMENT)
{
assignments = list_append(assignments, prefix)
}
else if (prefix->type == AST_REDIR)
{
redirections = list_append(redirections, prefix);
}
token = PEEK_TOKEN(); token = PEEK_TOKEN();
} }
} }
@ -250,8 +258,7 @@ struct ast *parse_simple_command(struct lexer_context *ctx)
else else
{ {
perror("Internal error: unexpected return value from " perror("Internal error: unexpected return value from "
"parse_element " "parse_element in parse_simple_command");
"in parse_simple_command");
return err_simple_command(command_elements, redirections); return err_simple_command(command_elements, redirections);
} }
@ -260,9 +267,8 @@ struct ast *parse_simple_command(struct lexer_context *ctx)
} }
} }
// Result struct ast *result =
// TODO handle assignments ast_create_command(command_elements, redirections, assignments);
struct ast *result = ast_create_command(command_elements, redirections);
if (result == NULL) if (result == NULL)
{ {
return err_simple_command(command_elements, redirections); return err_simple_command(command_elements, redirections);
@ -297,7 +303,8 @@ struct ast *parse_shell_command(struct lexer_context *ctx)
/* @brief: frees all the arguments. (helper func) /* @brief: frees all the arguments. (helper func)
* @return: NULL. * @return: NULL.
*/ */
static void *err_if_rule(struct ast **cond, struct ast **then_clause, struct ast **else_clause) static void *err_if_rule(struct ast **cond, struct ast **then_clause,
struct ast **else_clause)
{ {
ast_free(cond); ast_free(cond);
ast_free(then_clause); ast_free(then_clause);