fix(ast)!: assignment typo

This commit is contained in:
william.valenduc 2026-01-29 11:40:55 +00:00 committed by matteo
parent a0b723fb30
commit 3d26c0a897
9 changed files with 60 additions and 59 deletions

View file

@ -261,7 +261,7 @@ struct ast *parse_simple_command(struct lexer_context *ctx)
} }
// Result // Result
// TODO handle assignements // TODO handle assignments
struct ast *result = ast_create_command(command_elements, redirections); struct ast *result = ast_create_command(command_elements, redirections);
if (result == NULL) if (result == NULL)
{ {

View file

@ -2,6 +2,7 @@
#define AST_H #define AST_H
#include "ast_and_or.h" #include "ast_and_or.h"
#include "ast_assignment.h"
#include "ast_base.h" #include "ast_base.h"
#include "ast_command.h" #include "ast_command.h"
#include "ast_end.h" #include "ast_end.h"

View file

@ -1,36 +0,0 @@
#include "ast_assignement.h"
#include <stdlib.h>
bool ast_is_assignement(struct ast *node)
{
return node != NULL && node->type == AST_ASSIGNEMENT;
}
struct ast_assignement *ast_get_assignement(struct ast *node)
{
if (node == NULL || node->type != AST_ASSIGNEMENT)
return NULL;
return (struct ast_assignement *)node->data;
}
struct ast *ast_create_assignement(char *name, char *value)
{
struct ast_assignement *assignement_data = malloc(sizeof(struct ast_assignement));
if (!assignement_data)
return NULL;
assignement_data->name = name;
assignement_data->value = value;
return ast_create(AST_ASSIGNEMENT, assignement_data);
}
void ast_free_assignement(struct ast_assignement *assignement_data)
{
if (assignement_data == NULL)
return;
free(assignement_data->name);
free(assignement_data->value);
free(assignement_data);
}

View file

@ -1,17 +0,0 @@
#ifndef AST_ASSIGNEMENT_H
#define AST_ASSIGNEMENT_H
#include "ast_base.h"
struct ast_assignement
{
char *name;
char *value;
};
bool ast_is_assignement(struct ast *node);
struct ast_assignement *ast_get_assignement(struct ast *node);
struct ast *ast_create_assignement(char *name, char *value);
void ast_free_assignement(struct ast_assignement *assignement_data);
#endif /* ! AST_ASSIGNEMENT_H */

View file

@ -0,0 +1,36 @@
#include "ast_assignment.h"
#include <stdlib.h>
bool ast_is_assignment(struct ast *node)
{
return node != NULL && node->type == AST_ASSIGNMENT;
}
struct ast_assignment *ast_get_assignment(struct ast *node)
{
if (node == NULL || node->type != AST_ASSIGNMENT)
return NULL;
return (struct ast_assignment *)node->data;
}
struct ast *ast_create_assignment(char *name, char *value)
{
struct ast_assignment *assignment_data = malloc(sizeof(struct ast_assignment));
if (!assignment_data)
return NULL;
assignment_data->name = name;
assignment_data->value = value;
return ast_create(AST_ASSIGNMENT, assignment_data);
}
void ast_free_assignment(struct ast_assignment *assignment_data)
{
if (assignment_data == NULL)
return;
free(assignment_data->name);
free(assignment_data->value);
free(assignment_data);
}

View file

@ -0,0 +1,17 @@
#ifndef AST_ASSIGNMENT_H
#define AST_ASSIGNMENT_H
#include "ast_base.h"
struct ast_assignment
{
char *name;
char *value;
};
bool ast_is_assignment(struct ast *node);
struct ast_assignment *ast_get_assignment(struct ast *node);
struct ast *ast_create_assignment(char *name, char *value);
void ast_free_assignment(struct ast_assignment *assignment_data);
#endif /* ! AST_ASSIGNMENT_H */

View file

@ -16,7 +16,7 @@ enum ast_type
AST_WORD, AST_WORD,
AST_PIPE, AST_PIPE,
AST_NEG, AST_NEG,
AST_ASSIGNEMENT AST_ASSIGNMENT
}; };
struct ast struct ast

View file

@ -6,7 +6,7 @@
#include "../lists/lists.h" #include "../lists/lists.h"
struct ast *ast_create_command(struct list *command, struct ast *ast_create_command(struct list *command,
struct list *redirections, struct ast_list *assignements) struct list *redirections, struct ast_list *assignments)
{ {
struct ast_command *command_data = malloc(sizeof(struct ast_command)); struct ast_command *command_data = malloc(sizeof(struct ast_command));
if (!command_data) if (!command_data)
@ -36,6 +36,6 @@ void ast_free_command(struct ast_command *command_data)
return; return;
list_deep_destroy(command_data->command); list_deep_destroy(command_data->command);
ast_list_deep_destroy(command_data->redirections); ast_list_deep_destroy(command_data->redirections);
ast_list_deep_destroy(command_data->assignements); ast_list_deep_destroy(command_data->assignments);
free(command_data); free(command_data);
} }

View file

@ -8,7 +8,7 @@ struct ast_command
{ {
struct list *command; // A list of words (char*) struct list *command; // A list of words (char*)
struct ast_list *redirections; // A list of ASTs, all ast_redir struct ast_list *redirections; // A list of ASTs, all ast_redir
struct ast_list *assignements; // A list of ASTs, all ast_assignement struct ast_list *assignments; // A list of ASTs, all ast_assignment
}; };
/** /**
@ -26,7 +26,7 @@ struct ast_command *ast_get_command(struct ast *node);
* Creates a new AST node representing a command. * Creates a new AST node representing a command.
*/ */
struct ast *ast_create_command(struct list *command, struct ast *ast_create_command(struct list *command,
struct list *redirections, struct ast_list *assignements); struct list *redirections, struct ast_list *assignments);
/* /*
* @brief: frees the given ast_command and sets the pointer to NULL. * @brief: frees the given ast_command and sets the pointer to NULL.