Update so '$BANANE=truc' works

This commit is contained in:
Maix0 2024-08-12 17:02:46 +02:00
parent ecf01a6b8b
commit 11ec5cfa3c
14 changed files with 183 additions and 120 deletions

View file

@ -10,7 +10,6 @@ from_node/artihmetic_node \
from_node/boucle_node \
from_node/condition_node \
from_node/dev_node \
from_node/expand_node \
from_node/expansion_node \
from_node/file_node \
from_node/from_node \
@ -18,12 +17,12 @@ from_node/node_utils \
from_node/node_utils2 \
from_node/redirect_node \
from_node/scripting_node \
print_ast/ast_print \
print_ast/ast_print_arithmetic \
print_ast/ast_print_command \
print_ast/ast_print_global \
print_ast/ast_print_helper_function \
print_ast/ast_print_node \
print_ast/ast_print_redirection \
print_ast/ast_print_subshell \
print_ast/helper_function_print \
print_ast/print_arithmetic \
print_ast/print_ast \

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/11 14:23:40 by maiboyer #+# #+# */
/* Updated: 2024/08/02 17:02:03 by maiboyer ### ########.fr */
/* Updated: 2024/08/12 16:10:42 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -92,7 +92,8 @@ struct s_ast_node
t_ast_node_data data;
};
void ast_free(t_ast_node self);
t_ast_node ast_alloc(t_ast_node_kind kind);
void ast_free(t_ast_node self);
void ast_print(t_ast_node self);
#endif /* AST_H */

View file

@ -6,15 +6,13 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/26 10:55:52 by rparodi #+# #+# */
/* Updated: 2024/08/09 16:26:13 by rparodi ### ########.fr */
/* Updated: 2024/08/12 16:35:07 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "ast/_from_node.h"
#include "ast/ast.h"
#include "gmr/field_identifiers.h"
#include "gmr/field_identifiers.h"
#include "gmr/symbols.h"
#include "gmr/symbols.h"
#include "me/str/str.h"
#include "me/types.h"
@ -105,7 +103,7 @@ if (symbol == anon_sym_LT_GT)
*/
// RAPH
t_error ast_from_node(t_parse_node node, t_const_str input, t_ast_node *out);
t_error ast_from_node(t_parse_node node, t_const_str input, t_ast_node *out);
/* FUNCTION THAT ARE DONE */
@ -114,12 +112,11 @@ t_error ast_from_node(t_parse_node node, t_const_str input, t_ast_node *out);
// RAPH
// PLUS RAPH
t_error build_sym_command_substitution(\
t_parse_node self, t_const_str input, t_ast_node *out)
t_error build_sym_command_substitution(t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
t_ast_node tmp;
t_usize i;
t_ast_node ret;
t_ast_node tmp;
t_usize i;
if (out == NULL)
return (ERROR);
@ -130,14 +127,12 @@ t_error build_sym_command_substitution(\
while (i < ts_node_child_count(self))
{
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
continue ;
continue;
if (ts_node_symbol(ts_node_child(self, i)) == field_term)
{
if (ret->data.command_substitution.body.len != 0)
ast_set_term(\
&ret->data.command_substitution.body.buffer[\
ret->data.command_substitution.body.len - 1], \
_select_term(ts_node_child(self, i)));
ast_set_term(&ret->data.command_substitution.body.buffer[ret->data.command_substitution.body.len - 1],
_select_term(ts_node_child(self, i)));
}
else
{
@ -157,13 +152,12 @@ t_error build_sym_command_substitution(\
/* ret->data.file_redirection.input = tmp; */
/* } */
t_error build_sym_do_group(\
t_parse_node self, t_const_str input, t_ast_node *out)
t_error build_sym_do_group(t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
t_ast_node tmp;
t_usize i;
t_ast_terminator_kind term;
t_ast_node ret;
t_ast_node tmp;
t_usize i;
t_ast_terminator_kind term;
(void)(out);
(void)(input);
@ -176,19 +170,15 @@ t_error build_sym_do_group(\
i = 0;
while (i < ts_node_child_count(self))
{
if (ts_node_symbol(ts_node_child(self, i)) == anon_sym_do \
|| ts_node_symbol(ts_node_child(self, i)) == anon_sym_done)
if (ts_node_symbol(ts_node_child(self, i)) == anon_sym_do || ts_node_symbol(ts_node_child(self, i)) == anon_sym_done)
{
i++;
continue ;
continue;
}
if (ts_node_field_id_for_child(self, i) == field_term \
&& ret->data.compound_statement.body.len != 0)
if (ts_node_field_id_for_child(self, i) == field_term && ret->data.compound_statement.body.len != 0)
{
term = _select_term(ts_node_child(self, i));
ast_set_term(
&ret->data.compound_statement.body.buffer[\
ret->data.compound_statement.body.len - 1], term);
ast_set_term(&ret->data.compound_statement.body.buffer[ret->data.compound_statement.body.len - 1], term);
}
else
{
@ -201,13 +191,12 @@ t_error build_sym_do_group(\
return (*out = ret, NO_ERROR);
}
t_error build_sym_subshell(\
t_parse_node self, t_const_str input, t_ast_node *out)
t_error build_sym_subshell(t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
t_ast_node tmp;
t_usize i;
t_ast_terminator_kind term;
t_ast_node ret;
t_ast_node tmp;
t_usize i;
t_ast_terminator_kind term;
(void)(out);
(void)(input);
@ -220,18 +209,15 @@ t_error build_sym_subshell(\
i = 0;
while (i < ts_node_child_count(self))
{
if (ts_node_field_id_for_child(self, i) == field_term \
&& ret->data.subshell.body.len != 0)
if (ts_node_field_id_for_child(self, i) == field_term && ret->data.subshell.body.len != 0)
{
term = _select_term(ts_node_child(self, i));
ast_set_term(\
&ret->data.subshell.body.buffer[\
ret->data.subshell.body.len - 1], term);
ast_set_term(&ret->data.subshell.body.buffer[ret->data.subshell.body.len - 1], term);
}
else
{
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
continue ;
continue;
if (ast_from_node(ts_node_child(self, i), input, &tmp))
return (ast_free(ret), ERROR);
vec_ast_push(&ret->data.subshell.body, tmp);
@ -243,13 +229,12 @@ t_error build_sym_subshell(\
// t_error buildw
t_error build_sym_compound_statement(\
t_parse_node self, t_const_str input, t_ast_node *out)
t_error build_sym_compound_statement(t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
t_ast_node tmp;
t_usize i;
t_ast_terminator_kind term;
t_ast_node ret;
t_ast_node tmp;
t_usize i;
t_ast_terminator_kind term;
(void)(out);
(void)(input);
@ -262,17 +247,15 @@ t_error build_sym_compound_statement(\
i = 0;
while (i < ts_node_child_count(self))
{
if (ts_node_field_id_for_child(self, i) == field_term \
&& ret->data.compound_statement.body.len != 0)
if (ts_node_field_id_for_child(self, i) == field_term && ret->data.compound_statement.body.len != 0)
{
term = _select_term(ts_node_child(self, i));
ast_set_term(&ret->data.compound_statement.body.buffer[\
ret->data.compound_statement.body.len - 1], term);
ast_set_term(&ret->data.compound_statement.body.buffer[ret->data.compound_statement.body.len - 1], term);
}
else
{
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
continue ;
continue;
if (ast_from_node(ts_node_child(self, i), input, &tmp))
return (ast_free(ret), ERROR);
vec_ast_push(&ret->data.compound_statement.body, tmp);
@ -282,11 +265,11 @@ t_error build_sym_compound_statement(\
return (*out = ret, NO_ERROR);
}
t_error build_sym_string(t_parse_node self, t_const_str input, t_ast_node *out)
t_error build_sym_string(t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
t_usize i;
t_ast_node temp;
t_ast_node ret;
t_usize i;
t_ast_node temp;
(void)(self);
(void)(input);
@ -301,7 +284,7 @@ t_error build_sym_string(t_parse_node self, t_const_str input, t_ast_node *out)
while (i < ts_node_child_count(self))
{
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
continue ;
continue;
if (ast_from_node(ts_node_child(self, i), input, &temp))
return (ast_free(ret), ERROR);
vec_ast_push(&ret->data.word.inner, temp);
@ -310,12 +293,11 @@ t_error build_sym_string(t_parse_node self, t_const_str input, t_ast_node *out)
return (*out = ret, NO_ERROR);
}
t_error build_sym_concatenation(\
t_parse_node self, t_const_str input, t_ast_node *out)
t_error build_sym_concatenation(t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
t_usize i;
t_ast_node temp;
t_ast_node ret;
t_usize i;
t_ast_node temp;
(void)(self);
(void)(input);
@ -337,11 +319,10 @@ t_error build_sym_concatenation(\
return (*out = ret, NO_ERROR);
}
t_error build_sym_string_content(\
t_parse_node self, t_const_str input, t_ast_node *out)
t_error build_sym_string_content(t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
t_str temp_str;
t_ast_node ret;
t_str temp_str;
if (out == NULL)
return (ERROR);
@ -355,12 +336,11 @@ t_error build_sym_string_content(\
return (*out = ret, NO_ERROR);
}
t_error build_sym_raw_string(\
t_parse_node self, t_const_str input, t_ast_node *out)
t_error build_sym_raw_string(t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
t_ast_node temp;
t_str temp_str;
t_ast_node ret;
t_ast_node temp;
t_str temp_str;
if (out == NULL)
return (ERROR);
@ -379,11 +359,11 @@ t_error build_sym_raw_string(\
return (*out = ret, NO_ERROR);
}
t_error build_sym_program(t_parse_node self, t_const_str input, t_ast_node *out)
t_error build_sym_program(t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
t_usize i;
t_ast_node temp;
t_ast_node ret;
t_usize i;
t_ast_node temp;
if (out == NULL)
return (ERROR);
@ -403,18 +383,15 @@ t_error build_sym_program(t_parse_node self, t_const_str input, t_ast_node *out)
if (ts_node_field_id_for_child(self, i) == field_term)
{
if (ret->data.program.body.len == 0 && (i++, true))
continue ;
ast_set_term(&ret->data.program.body.buffer[\
ret->data.program.body.len - 1], \
_select_term(ts_node_child(self, i)));
continue;
ast_set_term(&ret->data.program.body.buffer[ret->data.program.body.len - 1], _select_term(ts_node_child(self, i)));
}
i++;
}
return (*out = ret, NO_ERROR);
}
t_error build_sym_command_name(\
t_parse_node self, t_const_str input, t_ast_node *out)
t_error build_sym_command_name(t_parse_node self, t_const_str input, t_ast_node *out)
{
if (out == NULL)
return (ERROR);
@ -423,11 +400,11 @@ t_error build_sym_command_name(\
return (ast_from_node(ts_node_child(self, 0), input, out));
}
t_error build_sym_word(t_parse_node self, t_const_str input, t_ast_node *out)
t_error build_sym_word(t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
t_str temp_str;
t_ast_node temp;
t_ast_node ret;
t_str temp_str;
t_ast_node temp;
if (out == NULL)
return (ERROR);
@ -444,12 +421,12 @@ t_error build_sym_word(t_parse_node self, t_const_str input, t_ast_node *out)
return (*out = ret, NO_ERROR);
}
t_error build_sym_command(t_parse_node self, t_const_str input, t_ast_node *out)
t_error build_sym_command(t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
t_usize i;
t_usize vec_idx;
t_ast_node temp;
t_ast_node ret;
t_usize i;
t_usize vec_idx;
t_ast_node temp;
if (out == NULL)
return (ERROR);
@ -471,10 +448,10 @@ t_error build_sym_command(t_parse_node self, t_const_str input, t_ast_node *out)
return (*out = ret, NO_ERROR);
}
t_error build_sym_list(t_parse_node self, t_const_str input, t_ast_node *out)
t_error build_sym_list(t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
t_ast_node *output;
t_ast_node *output;
t_usize i;
t_symbol temp;
@ -578,7 +555,7 @@ sym_while_statement
sym_word
*/
t_error ast_from_node(t_parse_node node, t_const_str input, t_ast_node *out)
t_error ast_from_node(t_parse_node node, t_const_str input, t_ast_node *out)
{
if (out == NULL)
return (ERROR);
@ -589,8 +566,7 @@ t_error ast_from_node(t_parse_node node, t_const_str input, t_ast_node *out)
if (ts_node_symbol(node) == sym_arithmetic_literal)
return (build_sym_arithmetic_literal(node, input, out));
if (ts_node_symbol(node) == sym_arithmetic_parenthesized_expression)
return (build_sym_arithmetic_parenthesized_expression(\
node, input, out));
return (build_sym_arithmetic_parenthesized_expression(node, input, out));
if (ts_node_symbol(node) == sym_arithmetic_postfix_expression)
return (build_sym_arithmetic_postfix_expression(node, input, out));
if (ts_node_symbol(node) == sym_arithmetic_ternary_expression)

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print_ast.c :+: :+: :+: */
/* ast_print.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/03 20:38:29 by maiboyer #+# #+# */
/* Updated: 2024/07/30 18:38:50 by maiboyer ### ########.fr */
/* Updated: 2024/08/12 16:34:50 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -80,8 +80,6 @@ static inline void ast_print_block2(t_ast_node self)
return (ast_print_node_for(self));
if (self->kind == AST_FUNCTION_DEFINITION)
return (ast_print_node_function_definition(self));
if (self == NULL)
return ((void)printf("ast == NULL\n"));
if (self->kind == AST_HEREDOC_REDIRECTION)
return (ast_print_node_heredoc_redirection(self));
if (self->kind == AST_IF)
@ -114,7 +112,9 @@ static inline void ast_print_block3(t_ast_node self)
printf("Unknown ast->kind: %#04x\n", self->kind);
}
void ast_print_node(t_ast_node self)
void ast_print(t_ast_node self)
{
if (self == NULL)
return ((void)printf("ast == NULL\n"));
ast_print_block1(self);
}

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/03 20:38:29 by maiboyer #+# #+# */
/* Updated: 2024/07/26 13:21:44 by rparodi ### ########.fr */
/* Updated: 2024/08/12 16:33:47 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -64,6 +64,7 @@ void ast_print_node_command(t_ast_node self)
ast_print_node(self->data.command.prefixes.buffer[i++]);
printf(" ");
}
return (ast_print_node_command_helper(self));
}
void ast_print_node_expansion_choose_op(t_ast_node self)