From f9aa614ef271642963fe7e60a5173ba120f20538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Tue, 18 Mar 2025 11:48:03 +0100 Subject: [PATCH] cmdgroup parsing: start implementing the new architecture --- src/parser/cmdgroup/cmdgroup.c | 8 +------- src/parser/cmdgroup/cmdgroup.h | 18 +++++++++++------- tests/test_cmdgroup_parsing.c | 11 ++++------- tests/testutil.c | 11 ++--------- 4 files changed, 18 insertions(+), 30 deletions(-) diff --git a/src/parser/cmdgroup/cmdgroup.c b/src/parser/cmdgroup/cmdgroup.c index 55cbbf4..8ff2548 100644 --- a/src/parser/cmdgroup/cmdgroup.c +++ b/src/parser/cmdgroup/cmdgroup.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/11 15:18:02 by khais #+# #+# */ -/* Updated: 2025/03/11 18:14:24 by khais ### ########.fr */ +/* Updated: 2025/03/18 11:48:33 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,12 +25,6 @@ t_cmdgroup *cmdgroup_from_wordlist(t_wordlist *words) cmd = ft_calloc(1, sizeof(t_cmdgroup)); if (cmd == NULL) return (NULL); - cmd->item_num = 1; - cmd->items = ft_calloc(1, sizeof(t_cmdgroup_item)); - if (cmd->items == NULL) - return (free(cmd), NULL); - cmd->items[0].type = TYPE_LIST; - cmd->items[0].inner.cmdlist = cmdlist_from_wordlist(words); return (cmd); } diff --git a/src/parser/cmdgroup/cmdgroup.h b/src/parser/cmdgroup/cmdgroup.h index d090a44..05fd216 100644 --- a/src/parser/cmdgroup/cmdgroup.h +++ b/src/parser/cmdgroup/cmdgroup.h @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/11 15:11:57 by khais #+# #+# */ -/* Updated: 2025/03/11 18:14:33 by khais ### ########.fr */ +/* Updated: 2025/03/18 12:07:29 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,19 +14,23 @@ # define CMDGROUP_H # include "../wordlist/wordlist.h" +# include "../command_list/command_list.h" -struct s_cmdgroup_item; - +/* +** A grouping of commands, surrounded by parentheses. +** +** A top-level cmdgroup is modeled as having an implicit set of parentheses. +*/ typedef struct s_cmdgroup { /* - ** Number of items in this cmdgroup + ** list of the commands inside this group */ - int item_num; + struct s_cmdlist item; /* - ** array of items in this cmdgroup + ** redirections to apply to the whole group */ - struct s_cmdgroup_item *items; + struct s_redirection_list *redirections; } t_cmdgroup; t_cmdgroup *cmdgroup_from_wordlist(t_wordlist *words); diff --git a/tests/test_cmdgroup_parsing.c b/tests/test_cmdgroup_parsing.c index fb3f26e..403e9c1 100644 --- a/tests/test_cmdgroup_parsing.c +++ b/tests/test_cmdgroup_parsing.c @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/03/18 11:43/36 by khais #+# #+# */ -/* Updated: 2025/03/18 11:43:36 by khais ### ########.fr */ +/* Created: 2025/03/18 11:49/19 by khais #+# #+# */ +/* Updated: 2025/03/18 11:49:19 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,9 +39,7 @@ static void test_cmdgroup_parsing_single_cmdlist(void) cmd = parse_cmdgroup("echo this | cat -e && echo works | wc -c"); // assert assert(NULL != cmd); - assert(1 == cmd->item_num); - assert(TYPE_LIST == cmd->items[0].type); - assert_cmdgroup_itemlistequal("echo this | cat -e && echo works | wc -c", cmd, 0); + // TODO // cleanup cmdgroup_destroy(cmd); do_leak_check(); @@ -55,9 +53,8 @@ static void test_cmdgroup_parsing_two_cmdlist(void) ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__); cmd = parse_cmdgroup("echo this | cat -e && echo works | wc -c"); // assert + // TODO assert(NULL != cmd); - assert(1 == cmd->item_num); - assert(TYPE_LIST == cmd->items[0].type); assert_cmdgroup_itemlistequal("echo this | cat -e && echo works | wc -c", cmd, 0); // cleanup cmdgroup_destroy(cmd); diff --git a/tests/testutil.c b/tests/testutil.c index d9f6810..779e114 100644 --- a/tests/testutil.c +++ b/tests/testutil.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/13 15:21:09 by khais #+# #+# */ -/* Updated: 2025/03/11 18:12:05 by khais ### ########.fr */ +/* Updated: 2025/03/18 11:50:23 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -128,24 +128,17 @@ t_cmdgroup *parse_cmdgroup(char *input) void assert_cmdgroup_itemlistequal(char *expected_str, t_cmdgroup *got_cmd, int item_number) { ft_dprintf(STDERR_FILENO, "checking that item %d of cmdlist %p matches [%s]\n", item_number, got_cmd, expected_str); - ft_dprintf(STDERR_FILENO, "expecteing to have at least %d items, and got %d\n", item_number + 1, got_cmd->item_num); - assert(got_cmd->item_num > item_number); - ft_dprintf(STDERR_FILENO, "expecteing item %p to be of type list got %d\n", got_cmd->items[item_number], got_cmd->items[item_number].type); t_cmdlist *expected = parse_command_list(expected_str); - t_cmdlist *got = got_cmd->items[item_number].inner.cmdlist; if (expected == NULL) { ft_dprintf(STDERR_FILENO, "expecting the list to be null\n"); - assert(expected == got); return ; } ft_dprintf(STDERR_FILENO, "checking if the list matches...\n"); - assert(expected->num_pipelines == got->num_pipelines); int i = 0; while (i < expected->num_pipelines) { - assert_pipelineequal_raw(expected->pipelines[i], got->pipelines[i]); - assert(expected->operators[i] == got->operators[i]); i++; } + assert(false && "not yet implemented"); }