From eb21f001563cd4f857d35eac03bf2953c5a9f22b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Mon, 24 Feb 2025 17:52:05 +0100 Subject: [PATCH] command list parsing: handle empty input This is really not that usefull, it is more to setup the groundwork --- Makefile | 1 + src/parser/command_list/command_list.c | 25 ++++++++++ src/parser/command_list/command_list.h | 66 ++++++++++++++++++++++++++ tests/Makefile | 1 + tests/parse_command_lists.c | 36 ++++++++++++++ 5 files changed, 129 insertions(+) create mode 100644 src/parser/command_list/command_list.c create mode 100644 src/parser/command_list/command_list.h create mode 100644 tests/parse_command_lists.c diff --git a/Makefile b/Makefile index af60ce8..2393226 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,7 @@ srcs = \ src/env/envp.c \ src/ft_errno.c \ src/get_command.c \ + src/parser/command_list/command_list.c \ src/parser/matchers/blank.c \ src/parser/matchers/identifier.c \ src/parser/matchers/metacharacter.c \ diff --git a/src/parser/command_list/command_list.c b/src/parser/command_list/command_list.c new file mode 100644 index 0000000..c0e4ef5 --- /dev/null +++ b/src/parser/command_list/command_list.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* command_list.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: khais +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/24 17:49:46 by khais #+# #+# */ +/* Updated: 2025/02/24 17:51:25 by khais ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "command_list.h" +#include + +t_command_list *command_list_from_wordlist(t_wordlist *words) +{ + (void)words; + return (NULL); +} + +void command_list_destroy(t_command_list *cmd) +{ + (void)cmd; +} diff --git a/src/parser/command_list/command_list.h b/src/parser/command_list/command_list.h new file mode 100644 index 0000000..aa05f83 --- /dev/null +++ b/src/parser/command_list/command_list.h @@ -0,0 +1,66 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* command_list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: khais +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/24 17:45:01 by khais #+# #+# */ +/* Updated: 2025/02/24 17:49:33 by khais ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef COMMAND_LIST_H +# define COMMAND_LIST_H + +# include "../wordlist/wordlist.h" +/* +** cf. 3.2.4 Lists of Commands +** +** A list is a sequence of one or more pipelines separated by one of the +** **operators** ‘&&’, or ‘||’, and optionally terminated by a newline. +** +** AND and OR lists are sequences of one or more pipelines separated by the +** control operators ‘&&’ and ‘||’, respectively. +** +** AND and OR lists are executed with left associativity. +** +** e.g. +** +** ```shell +** A && B && C +** ``` +** +** is the same as +** +** ```shell +** (A && B) && C +** ``` +** +** An AND list has the form +** +** ```shell +** A && B +** ``` +** +** B is execute if and only if A has an exit status of 0 (succes). +** +** An OR list has the form +** +** ```shell +** A || B +** ``` +** +** B is execute if and only if A has a non-zero exit status (failure). +** +** The return status of AND and OR lists is the exit status of the last command +** executed in the list. +*/ +typedef struct s_command_list +{ +} t_command_list; + +t_command_list *command_list_from_wordlist(t_wordlist *words); +void command_list_destroy(t_command_list *cmd); + +#endif // COMMAND_LIST_H diff --git a/tests/Makefile b/tests/Makefile index 52c92c7..55ce7ef 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -3,6 +3,7 @@ rawtests = \ quote_removal \ metacharacters \ + parse_command_lists \ parse_pipelines \ parse_simple_cmds \ test_env_manip \ diff --git a/tests/parse_command_lists.c b/tests/parse_command_lists.c new file mode 100644 index 0000000..c93706b --- /dev/null +++ b/tests/parse_command_lists.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parse_command_lists.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: khais +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/24 17:40:48 by khais #+# #+# */ +/* Updated: 2025/02/24 17:47:39 by khais ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../src/parser/command_list/command_list.h" +#include "../src/parser/wordsplit/wordsplit.h" +#include + +static t_command_list *parse_command_list(char *input) +{ + t_wordlist *words = minishell_wordsplit(input); + t_command_list *cmd = command_list_from_wordlist(words); + return (cmd); +} + + +static void test_parse_command_list_empty(void) +{ + t_command_list *cmd = parse_command_list(""); + assert(cmd == NULL); + command_list_destroy(cmd); +} + +int main(void) +{ + test_parse_command_list_empty(); + return (0); +}