command list parsing: handle empty input

This is really not that usefull, it is more to setup the groundwork
This commit is contained in:
Khaïs COLIN 2025-02-24 17:52:05 +01:00 committed by Khaïs COLIN
parent 1c653d9665
commit eb21f00156
5 changed files with 129 additions and 0 deletions

View file

@ -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 \

View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* command_list.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/24 17:49:46 by khais #+# #+# */
/* Updated: 2025/02/24 17:51:25 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#include "command_list.h"
#include <stdlib.h>
t_command_list *command_list_from_wordlist(t_wordlist *words)
{
(void)words;
return (NULL);
}
void command_list_destroy(t_command_list *cmd)
{
(void)cmd;
}

View file

@ -0,0 +1,66 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* command_list.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -3,6 +3,7 @@
rawtests = \
quote_removal \
metacharacters \
parse_command_lists \
parse_pipelines \
parse_simple_cmds \
test_env_manip \

View file

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse_command_lists.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <assert.h>
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);
}