From dc3f8cfba9c53965758a773e3729fc2be6244c2a Mon Sep 17 00:00:00 2001 From: Maix0 Date: Tue, 2 Jul 2024 12:30:53 +0200 Subject: [PATCH] Pushed --- ast/include/ast/ast.h | 12 ++++--- ast/include/ast/ast_forward_def.h | 9 ++--- ast/include/ast/ast_raw_structs.h | 13 +++++-- ast/src/from_node.c | 56 ++++++++++++++++++++++++++----- 4 files changed, 71 insertions(+), 19 deletions(-) diff --git a/ast/include/ast/ast.h b/ast/include/ast/ast.h index 9f587c04..5486d3df 100644 --- a/ast/include/ast/ast.h +++ b/ast/include/ast/ast.h @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/11 14:23:40 by maiboyer #+# #+# */ -/* Updated: 2024/06/20 18:22:03 by maiboyer ### ########.fr */ +/* Updated: 2024/07/01 21:36:48 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,6 +43,7 @@ enum e_ast_node_kind AST_VARIABLE_ASSIGNMENT = S_AST_NONE | 0x000E, AST_EXTGLOB = S_AST_NONE | 0x001A, AST_REGEX = S_AST_NONE | 0x001B, + AST_NUMBER = S_AST_NONE | 0x001C, AST_FILE_REDIRECTION = S_AST_REDIRECT | 0x000F, AST_HEREDOC_REDIRECTION = S_AST_REDIRECT | 0x0010, @@ -62,32 +63,33 @@ enum e_ast_node_kind union u_ast_node_data { t_ast_arithmetic_expansion arithmetic_expansion; - t_ast_case_item case_item; t_ast_case case_; - t_ast_command_substitution command_substitution; + t_ast_case_item case_item; t_ast_command command; + t_ast_command_substitution command_substitution; t_ast_compound_statement compound_statement; t_ast_elif elif; t_ast_else else_; t_ast_empty empty; t_ast_expansion expansion; + t_ast_extglob extglob; t_ast_file_redirection file_redirection; t_ast_for for_; t_ast_function_definition function_definition; t_ast_heredoc_redirection heredoc_redirection; t_ast_if if_; t_ast_list list; + t_ast_number number; 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; t_ast_while while_; t_ast_word word; - t_ast_extglob extglob; - t_ast_regex regex; }; struct s_ast_node diff --git a/ast/include/ast/ast_forward_def.h b/ast/include/ast/ast_forward_def.h index 68686bc0..f11bb2e0 100644 --- a/ast/include/ast/ast_forward_def.h +++ b/ast/include/ast/ast_forward_def.h @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/11 14:24:24 by maiboyer #+# #+# */ -/* Updated: 2024/06/20 14:22:36 by maiboyer ### ########.fr */ +/* Updated: 2024/07/01 21:35:22 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,10 +25,10 @@ typedef union u_ast_node_data t_ast_node_data; typedef struct s_ast_node *t_ast_node; typedef struct s_ast_arithmetic_expansion t_ast_arithmetic_expansion; -typedef struct s_ast_case_item t_ast_case_item; typedef struct s_ast_case t_ast_case; -typedef struct s_ast_command_substitution t_ast_command_substitution; +typedef struct s_ast_case_item t_ast_case_item; typedef struct s_ast_command t_ast_command; +typedef struct s_ast_command_substitution t_ast_command_substitution; typedef struct s_ast_compound_statement t_ast_compound_statement; typedef struct s_ast_elif t_ast_elif; typedef struct s_ast_else t_ast_else; @@ -41,16 +41,17 @@ typedef struct s_ast_function_definition t_ast_function_definition; typedef struct s_ast_heredoc_redirection t_ast_heredoc_redirection; typedef struct s_ast_if t_ast_if; typedef struct s_ast_list t_ast_list; +typedef struct s_ast_number t_ast_number; 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; typedef struct s_ast_while t_ast_while; typedef struct s_ast_word t_ast_word; -typedef struct s_ast_regex t_ast_regex; /* t_ast_arithmetic_expansion arithmetic_expansion; diff --git a/ast/include/ast/ast_raw_structs.h b/ast/include/ast/ast_raw_structs.h index 89846aa0..4267002d 100644 --- a/ast/include/ast/ast_raw_structs.h +++ b/ast/include/ast/ast_raw_structs.h @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/14 17:46:58 by maiboyer #+# #+# */ -/* Updated: 2024/06/29 14:44:04 by maiboyer ### ########.fr */ +/* Updated: 2024/07/01 21:34:57 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -322,7 +322,7 @@ struct s_ast_file_redirection { t_ast_node output; t_ast_redirection_kind op; - t_str input; + t_ast_node input; }; /// File Redirection @@ -396,4 +396,13 @@ struct s_ast_regex t_str pattern; }; +/// Regex +/// ```shell +/// ~pattern +/// ``` +struct s_ast_number +{ + t_i64 number; +}; + #endif /* AST_RAW_STRUCTS_H */ diff --git a/ast/src/from_node.c b/ast/src/from_node.c index f4f950e2..83c8bae8 100644 --- a/ast/src/from_node.c +++ b/ast/src/from_node.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/17 12:41:56 by maiboyer #+# #+# */ -/* Updated: 2024/06/30 16:50:25 by maiboyer ### ########.fr */ +/* Updated: 2024/07/01 21:44:49 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -213,6 +213,9 @@ void ast_free(t_ast_node elem) { mem_free(elem->data.regex.pattern); } + if (elem->kind == AST_NUMBER) + { + } mem_free(elem); } @@ -373,6 +376,10 @@ t_ast_node ast_alloc(t_ast_node_kind kind) { ret->data.regex.pattern = NULL; } + if (kind == AST_NUMBER) + { + ret->data.number.number = 0; + } return (ret); } @@ -529,22 +536,23 @@ t_error build_sym_compound_statement(t_parse_node self, t_const_str input, t_ast t_error build_sym_elif_clause(t_parse_node self, t_const_str input, t_ast_node *out); t_error build_sym_else_clause(t_parse_node self, t_const_str input, t_ast_node *out); t_error build_sym_extglob_pattern(t_parse_node self, t_const_str input, t_ast_node *out); +t_error build_sym_file_redirect(t_parse_node self, t_const_str input, t_ast_node *out); t_error build_sym_for_statement(t_parse_node self, t_const_str input, t_ast_node *out); t_error build_sym_function_definition(t_parse_node self, t_const_str input, t_ast_node *out); t_error build_sym_if_statement(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_error build_sym_negated_command(t_parse_node self, t_const_str input, t_ast_node *out); +t_error build_sym_number(t_parse_node self, t_const_str input, t_ast_node *out); t_error build_sym_pipeline(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_error build_sym_raw_string(t_parse_node self, t_const_str input, t_ast_node *out); t_error build_sym_redirected_statement(t_parse_node self, t_const_str input, t_ast_node *out); +t_error build_sym_regex(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_error build_sym_subshell(t_parse_node self, t_const_str input, t_ast_node *out); t_error build_sym_variable_assignment(t_parse_node self, t_const_str input, t_ast_node *out); t_error build_sym_while_statement(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_error build_sym_regex(t_parse_node self, t_const_str input, t_ast_node *out); -t_error build_sym_file_redirect(t_parse_node self, t_const_str input, t_ast_node *out); /* FUNCTION THAT ARE NOT DONE */ @@ -562,9 +570,6 @@ t_error build_sym_expansion_expression(t_parse_node self, t_const_str input, t_a t_error build_sym_expansion_regex(t_parse_node self, t_const_str input, t_ast_node *out); t_error build_sym_simple_expansion(t_parse_node self, t_const_str input, t_ast_node *out); -t_error build_sym_file_descriptor(t_parse_node self, t_const_str input, t_ast_node *out); -t_error build_sym_number(t_parse_node self, t_const_str input, t_ast_node *out); - t_error build_sym_heredoc_redirect(t_parse_node self, t_const_str input, t_ast_node *out); t_error build_sym_simple_heredoc_body(t_parse_node self, t_const_str input, t_ast_node *out); @@ -575,6 +580,40 @@ t_error build_sym_heredoc_start(t_parse_node self, t_const_str input, t_ast_node #include +t_error build_sym_file_descriptor(t_parse_node self, t_const_str input, t_ast_node *out) +{ + t_ast_node ret; + + (void)(out); + (void)(input); + (void)(self); + if (out == NULL) + return (ERROR); + if (ts_node_symbol(self) != sym_regex) + return (ERROR); + ret = ast_alloc(AST_RAW_STRING); + ret->data.raw_string.str = _extract_str(self, input); + ret->data.raw_string.len = str_len(ret->data.raw_string.str); + return (*out = ret, NO_ERROR); +} + +t_error build_sym_number(t_parse_node self, t_const_str input, t_ast_node *out) +{ + t_ast_node ret; + + (void)(out); + (void)(input); + (void)(self); + if (out == NULL) + return (ERROR); + if (ts_node_symbol(self) != sym_regex) + return (ERROR); + ret = ast_alloc(AST_RAW_STRING); + ret->data.raw_string.str = _extract_str(self, input); + ret->data.raw_string.len = str_len(ret->data.raw_string.str); + return (*out = ret, NO_ERROR); +} + t_error build_sym_file_redirect(t_parse_node self, t_const_str input, t_ast_node *out) { t_ast_node ret; @@ -596,8 +635,9 @@ t_error build_sym_file_redirect(t_parse_node self, t_const_str input, t_ast_node continue; if (ts_node_field_id_for_child(self, i) == field_fd) { - - ret->data.file_redirection.input = _extract_str(ts_node_child(self, i), input); + if (ast_from_node(ts_node_child(self, i), input, &tmp)) + return (ast_free(ret), ERROR); + ret->data.file_redirection.input = tmp; } if (ts_node_field_id_for_child(self, i) == field_op) {