fix(ast)!: assignment typo
This commit is contained in:
parent
988d8ef298
commit
a98161d885
9 changed files with 60 additions and 59 deletions
|
|
@ -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)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -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"
|
||||||
|
|
|
||||||
|
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
@ -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 */
|
|
||||||
36
src/utils/ast/ast_assignment.c
Normal file
36
src/utils/ast/ast_assignment.c
Normal 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);
|
||||||
|
}
|
||||||
17
src/utils/ast/ast_assignment.h
Normal file
17
src/utils/ast/ast_assignment.h
Normal 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 */
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue