parsing: refactor minishell_optional_pipeline_parse into own file

This commit is contained in:
Khaïs COLIN 2025-04-15 10:44:27 +02:00
parent 811ce3ef8e
commit b7871be426
5 changed files with 60 additions and 24 deletions

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/31 10:28:28 by jguelen #+# #+# */
/* Updated: 2025/04/15 10:40:22 by khais ### ########.fr */
/* Updated: 2025/04/15 10:43:57 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,6 +19,7 @@
#include "simple_cmd/simple_cmd_parse.h"
#include "cmd/cmd_destroy.h"
#include "redirect/redirect_parse.h"
#include "pipeline/optional_pipeline_parse.h"
void parse_error(t_minishell *app, t_worddesc *token)
{
@ -27,24 +28,6 @@ void parse_error(t_minishell *app, t_worddesc *token)
app->last_return_value = 2;
}
t_cmd *minishell_opt_pipeline_parse(t_minishell *app, t_wordlist *tokens)
{
t_cmd *opt;
t_worddesc *token;
token = tokens->word;
if (token->token_type == PIPE_TOKEN)
{
token = wordlist_pop(&tokens);
worddesc_destroy(token);
opt = minishell_group_or_simple_parse(app, tokens);
if (!opt)
ft_errno(FT_EERRNO);
return (opt);
}
return (NULL);
}
t_cmd *minishell_group_parse(t_minishell *app, t_wordlist *tokens)
{
t_cmd *subtree;
@ -140,7 +123,7 @@ t_cmd *minishell_pipeline_parse(t_minishell *app, t_wordlist *tokens)
subtree = minishell_group_or_simple_parse(app, tokens);
if (!subtree)
return (NULL);
opt = minishell_opt_pipeline_parse(app, tokens);
opt = minishell_optional_pipeline_parse(app, tokens);
if (!opt && ft_errno_get() != FT_ESUCCESS)
return (NULL);
if (!opt)
@ -152,7 +135,7 @@ t_cmd *minishell_pipeline_parse(t_minishell *app, t_wordlist *tokens)
app->last_return_value = 1;
return (ft_perror("minishell_pipeline_parse"), NULL);
}
opt = minishell_opt_pipeline_parse(app, tokens);
opt = minishell_optional_pipeline_parse(app, tokens);
}
if (ft_errno_get() != FT_ESUCCESS)
return (cmd_destroy(subtree), NULL);

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 10:14:13 by khais #+# #+# */
/* Updated: 2025/04/15 10:36:45 by khais ### ########.fr */
/* Updated: 2025/04/15 10:42:48 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -27,7 +27,5 @@ t_cmd *minishell_opt_cmds_parse(t_minishell *app, t_wordlist *tokens,
t_connector *connec);
t_cmd *minishell_group_or_simple_parse(t_minishell *app,
t_wordlist *tokens);
t_cmd *minishell_opt_pipeline_parse(t_minishell *app,
t_wordlist *tokens);
#endif

View file

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* optional_pipeline_parse.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 10:43:04 by khais #+# #+# */
/* Updated: 2025/04/15 10:43:40 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#include "optional_pipeline_parse.h"
#include "../../ft_errno.h"
#include "../cmd_parsing.h"
t_cmd *minishell_optional_pipeline_parse(t_minishell *app, t_wordlist *tokens)
{
t_cmd *opt;
t_worddesc *token;
token = tokens->word;
if (token->token_type == PIPE_TOKEN)
{
token = wordlist_pop(&tokens);
worddesc_destroy(token);
opt = minishell_group_or_simple_parse(app, tokens);
if (!opt)
ft_errno(FT_EERRNO);
return (opt);
}
return (NULL);
}

View file

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* optional_pipeline_parse.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 10:42:34 by khais #+# #+# */
/* Updated: 2025/04/15 10:42:57 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef OPTIONAL_PIPELINE_PARSE_H
# define OPTIONAL_PIPELINE_PARSE_H
# include "../../minishell.h"
t_cmd *minishell_optional_pipeline_parse(t_minishell *app,
t_wordlist *tokens);
#endif // OPTIONAL_PIPELINE_PARSE_H