Further work on the ast printing
This commit is contained in:
parent
776ccfa9c0
commit
519aa1a781
5 changed files with 90 additions and 33 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/11 14:23:40 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/07/01 21:36:48 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/07/03 22:33:51 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -38,7 +38,6 @@ enum e_ast_node_kind
|
|||
AST_ELSE = S_AST_NONE | 0x0007,
|
||||
AST_EMPTY = S_AST_NONE | 0x0008,
|
||||
AST_RAW_STRING = S_AST_NONE | 0x000A,
|
||||
AST_STRING = S_AST_NONE | 0x000B,
|
||||
AST_WORD = S_AST_NONE | 0x000C,
|
||||
AST_VARIABLE_ASSIGNMENT = S_AST_NONE | 0x000E,
|
||||
AST_EXTGLOB = S_AST_NONE | 0x001A,
|
||||
|
|
@ -82,7 +81,6 @@ union u_ast_node_data {
|
|||
t_ast_program program;
|
||||
t_ast_raw_string raw_string;
|
||||
t_ast_regex regex;
|
||||
t_ast_string string;
|
||||
t_ast_subshell subshell;
|
||||
t_ast_until until;
|
||||
t_ast_variable_assignment variable_assignment;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/11 14:24:24 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/07/01 21:35:22 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/07/03 22:30:23 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -45,7 +45,6 @@ typedef struct s_ast_pipeline t_ast_pipeline;
|
|||
typedef struct s_ast_program t_ast_program;
|
||||
typedef struct s_ast_raw_string t_ast_raw_string;
|
||||
typedef struct s_ast_regex t_ast_regex;
|
||||
typedef struct s_ast_string t_ast_string;
|
||||
typedef struct s_ast_subshell t_ast_subshell;
|
||||
typedef struct s_ast_until t_ast_until;
|
||||
typedef struct s_ast_variable_assignment t_ast_variable_assignment;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/14 17:46:58 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/07/02 21:45:29 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/07/03 22:30:01 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -82,11 +82,6 @@ struct s_ast_raw_string
|
|||
t_usize len;
|
||||
};
|
||||
|
||||
struct s_ast_string
|
||||
{
|
||||
t_vec_ast parts;
|
||||
};
|
||||
|
||||
struct s_ast_word
|
||||
{
|
||||
t_ast_word_kind kind;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/17 12:41:56 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/07/03 21:57:05 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/07/03 22:30:35 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -175,10 +175,6 @@ void ast_free(t_ast_node elem)
|
|||
{
|
||||
mem_free(elem->data.raw_string.str);
|
||||
}
|
||||
if (elem->kind == AST_STRING)
|
||||
{
|
||||
vec_ast_free(elem->data.string.parts);
|
||||
}
|
||||
if (elem->kind == AST_SUBSHELL)
|
||||
{
|
||||
vec_ast_free(elem->data.subshell.body);
|
||||
|
|
@ -331,10 +327,6 @@ t_ast_node ast_alloc(t_ast_node_kind kind)
|
|||
ret->data.raw_string.len = 0;
|
||||
ret->data.raw_string.str = NULL;
|
||||
}
|
||||
if (kind == AST_STRING)
|
||||
{
|
||||
ret->data.string.parts = vec_ast_new(16, ast_free);
|
||||
}
|
||||
if (kind == AST_SUBSHELL)
|
||||
{
|
||||
ret->data.subshell.term = AST_TERM_NONE;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/03 20:38:29 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/07/03 22:06:15 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/07/03 22:34:13 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -44,7 +44,6 @@ t_ast_pipeline pipeline;
|
|||
t_ast_program program;
|
||||
t_ast_raw_string raw_string;
|
||||
t_ast_regex regex;
|
||||
t_ast_string string;
|
||||
t_ast_subshell subshell;
|
||||
t_ast_until until;
|
||||
t_ast_variable_assignment variable_assignment;
|
||||
|
|
@ -53,15 +52,19 @@ t_ast_word word;
|
|||
*/
|
||||
|
||||
void ast_print_node_command(t_ast_node self);
|
||||
void ast_print_node_command_substitution(t_ast_node self);
|
||||
void ast_print_node_compound_statement(t_ast_node self);
|
||||
void ast_print_node_expansion(t_ast_node self);
|
||||
void ast_print_node_extglob(t_ast_node self);
|
||||
void ast_print_node_file_redirection(t_ast_node self);
|
||||
void ast_print_node_list(t_ast_node self);
|
||||
void ast_print_node_pipeline(t_ast_node self);
|
||||
void ast_print_node_program(t_ast_node self);
|
||||
void ast_print_node_raw_string(t_ast_node self);
|
||||
void ast_print_node_regex(t_ast_node self);
|
||||
void ast_print_node_subshell(t_ast_node self);
|
||||
void ast_print_node_variable_assignment(t_ast_node self);
|
||||
void ast_print_node_word(t_ast_node self);
|
||||
void ast_print_node_command_substitution(t_ast_node self);
|
||||
void ast_print_node_file_redirection(t_ast_node self);
|
||||
|
||||
/*^^^ DONE ^^^*/
|
||||
/*vvv NOT DONE vvv*/
|
||||
|
|
@ -71,16 +74,11 @@ void ast_print_node_case(t_ast_node self) NOT_DONE;
|
|||
void ast_print_node_case_item(t_ast_node self) NOT_DONE;
|
||||
void ast_print_node_elif(t_ast_node self) NOT_DONE;
|
||||
void ast_print_node_else(t_ast_node self) NOT_DONE;
|
||||
void ast_print_node_extglob(t_ast_node self) NOT_DONE;
|
||||
void ast_print_node_for(t_ast_node self) NOT_DONE;
|
||||
void ast_print_node_function_definition(t_ast_node self) NOT_DONE;
|
||||
void ast_print_node_heredoc_redirection(t_ast_node self) NOT_DONE;
|
||||
void ast_print_node_if(t_ast_node self) NOT_DONE;
|
||||
void ast_print_node_list(t_ast_node self) NOT_DONE;
|
||||
void ast_print_node_pipeline(t_ast_node self) NOT_DONE;
|
||||
void ast_print_node_string(t_ast_node self) NOT_DONE;
|
||||
void ast_print_node_until(t_ast_node self) NOT_DONE;
|
||||
void ast_print_node_variable_assignment(t_ast_node self) NOT_DONE;
|
||||
void ast_print_node_while(t_ast_node self) NOT_DONE;
|
||||
|
||||
/// HELPER_FUNCS
|
||||
|
|
@ -101,13 +99,89 @@ void _print_term(t_ast_terminator_kind term)
|
|||
|
||||
/// IMPL
|
||||
|
||||
void ast_print_node_variable_assignment(t_ast_node self)
|
||||
{
|
||||
if (self == NULL)
|
||||
return;
|
||||
if (self->kind != AST_VARIABLE_ASSIGNMENT)
|
||||
return;
|
||||
if (self->data.variable_assignment.bang)
|
||||
printf("! ");
|
||||
printf("%s=", self->data.variable_assignment.name);
|
||||
if (self->data.variable_assignment.value != NULL)
|
||||
ast_print_node(self->data.variable_assignment.value);
|
||||
printf(" ");
|
||||
}
|
||||
|
||||
void ast_print_node_pipeline(t_ast_node self)
|
||||
{
|
||||
t_usize i;
|
||||
|
||||
if (self == NULL)
|
||||
return;
|
||||
if (self->kind != AST_PIPELINE)
|
||||
return;
|
||||
if (self->data.pipeline.bang)
|
||||
printf("! ");
|
||||
if (self->data.pipeline.statements.len != 0)
|
||||
{
|
||||
i = 0;
|
||||
ast_print_node(self->data.pipeline.statements.buffer[i++]);
|
||||
while (i < self->data.pipeline.statements.len)
|
||||
{
|
||||
printf(" | ");
|
||||
ast_print_node(self->data.pipeline.statements.buffer[i++]);
|
||||
}
|
||||
}
|
||||
i = 0;
|
||||
while (i < self->data.pipeline.suffixes_redirections.len)
|
||||
{
|
||||
printf(" ");
|
||||
ast_print_node(self->data.pipeline.suffixes_redirections.buffer[i++]);
|
||||
}
|
||||
_print_term(self->data.pipeline.term);
|
||||
}
|
||||
|
||||
void ast_print_node_list(t_ast_node self)
|
||||
{
|
||||
t_usize i;
|
||||
|
||||
if (self == NULL)
|
||||
return;
|
||||
if (self->kind != AST_LIST)
|
||||
return;
|
||||
ast_print_node(self->data.list.left);
|
||||
if (self->data.list.op == AST_LIST_OR)
|
||||
printf(" || ");
|
||||
if (self->data.list.op == AST_LIST_AND)
|
||||
printf(" && ");
|
||||
ast_print_node(self->data.list.right);
|
||||
i = 0;
|
||||
while (i < self->data.list.suffixes_redirections.len)
|
||||
{
|
||||
ast_print_node(self->data.list.suffixes_redirections.buffer[i++]);
|
||||
printf(" ");
|
||||
}
|
||||
_print_term(self->data.list.term);
|
||||
}
|
||||
|
||||
void ast_print_node_extglob(t_ast_node self)
|
||||
{
|
||||
if (self == NULL)
|
||||
return;
|
||||
if (self->kind != AST_EXTGLOB)
|
||||
return;
|
||||
printf("%s", self->data.extglob.pattern);
|
||||
}
|
||||
|
||||
void ast_print_node_file_redirection(t_ast_node self)
|
||||
{
|
||||
if (self == NULL)
|
||||
return;
|
||||
if (self->kind != AST_FILE_REDIRECTION)
|
||||
return;
|
||||
ast_print_node(self->data.file_redirection.input);
|
||||
if (self->data.file_redirection.input != NULL)
|
||||
ast_print_node(self->data.file_redirection.input);
|
||||
|
||||
if (self->data.file_redirection.op == AST_REDIR_INPUT)
|
||||
printf("<");
|
||||
|
|
@ -128,7 +202,8 @@ void ast_print_node_file_redirection(t_ast_node self)
|
|||
// if (self->data.file_redirection.op == AST_REDIR_HEREDOC_INDENT)
|
||||
// printf("<<-");
|
||||
|
||||
ast_print_node(self->data.file_redirection.output);
|
||||
if (self->data.file_redirection.output != NULL)
|
||||
ast_print_node(self->data.file_redirection.output);
|
||||
}
|
||||
|
||||
void ast_print_node_expansion(t_ast_node self)
|
||||
|
|
@ -382,8 +457,6 @@ void ast_print_node(t_ast_node self)
|
|||
return (ast_print_node_raw_string(self));
|
||||
if (self->kind == AST_REGEX)
|
||||
return (ast_print_node_regex(self));
|
||||
if (self->kind == AST_STRING)
|
||||
return (ast_print_node_string(self));
|
||||
if (self->kind == AST_SUBSHELL)
|
||||
return (ast_print_node_subshell(self));
|
||||
if (self->kind == AST_UNTIL)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue