From 148db797880aaf3896b006afa41a53af8d4ec3e3 Mon Sep 17 00:00:00 2001 From: matteo Date: Thu, 29 Jan 2026 18:52:51 +0100 Subject: [PATCH] fix(merge conflicts) --- src/parser/grammar_advanced.c | 2 +- src/parser/grammar_basic.c | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/parser/grammar_advanced.c b/src/parser/grammar_advanced.c index 1964f49..eb5869d 100644 --- a/src/parser/grammar_advanced.c +++ b/src/parser/grammar_advanced.c @@ -74,7 +74,7 @@ struct ast *parse_prefix(struct lexer_context *ctx) } else if (is_first(*token, RULE_REDIRECTION)) return parse_redirection(ctx); - else + else { perror("Syntax error: expected a prefix (redirection or assignment)"); return NULL; diff --git a/src/parser/grammar_basic.c b/src/parser/grammar_basic.c index 9621d31..ad78673 100644 --- a/src/parser/grammar_basic.c +++ b/src/parser/grammar_basic.c @@ -173,7 +173,7 @@ struct ast *parse_command(struct lexer_context *ctx) * @return: NULL */ static void *err_simple_command(struct list *command_elements, - struct list *redirections) + struct list *redirections) { list_deep_destroy(command_elements); list_deep_destroy(redirections); @@ -184,6 +184,7 @@ struct ast *parse_simple_command(struct lexer_context *ctx) { struct list *command_elements = NULL; struct list *redirections = NULL; // list of redirection ASTs + struct list *assignments = NULL; bool has_prefix = false; struct token *token = PEEK_TOKEN(); @@ -192,12 +193,19 @@ struct ast *parse_simple_command(struct lexer_context *ctx) has_prefix = true; while (is_first(*token, RULE_PREFIX)) { - struct ast *redir = parse_prefix(ctx); - if (redir == NULL) + struct ast *prefix = parse_prefix(ctx); + if (prefix == NULL) { 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(); } } @@ -250,8 +258,7 @@ struct ast *parse_simple_command(struct lexer_context *ctx) else { perror("Internal error: unexpected return value from " - "parse_element " - "in parse_simple_command"); + "parse_element in parse_simple_command"); return err_simple_command(command_elements, redirections); } @@ -260,9 +267,8 @@ struct ast *parse_simple_command(struct lexer_context *ctx) } } - // Result - // TODO handle assignments - struct ast *result = ast_create_command(command_elements, redirections); + struct ast *result = + ast_create_command(command_elements, redirections, assignments); if (result == NULL) { 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) * @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(then_clause);