mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
parse-cmd: Various fixes and a rotation of the parsing tree
This commit is contained in:
parent
90d213bf98
commit
10a3c9c411
12 changed files with 155 additions and 48 deletions
|
|
@ -3,10 +3,10 @@
|
|||
/* ::: :::::::: */
|
||||
/* cmd_parsing.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jguelen <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/31 10:28:28 by jguelen #+# #+# */
|
||||
/* Updated: 2025/04/04 18:38:59 by jguelen ### ########.fr */
|
||||
/* Updated: 2025/04/08 10:21:41 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -27,72 +27,152 @@ void parse_error(t_minishell *app, t_worddesc *token)
|
|||
|
||||
t_connector which_connector_type(t_worddesc *token)
|
||||
{
|
||||
|
||||
return ((t_connector)0);
|
||||
}
|
||||
|
||||
t_cmd *minishell_simple_lst_parse(t_minishell *app, t_cmd_builder *builder)
|
||||
{
|
||||
|
||||
return ((t_cmd *)NULL);
|
||||
}
|
||||
|
||||
t_redirect *minishell_redir_parse(t_minishell *app, t_cmd_builder *builder)
|
||||
{
|
||||
}
|
||||
ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word);
|
||||
t_cmd *subtree;
|
||||
|
||||
// subtree = minishell_group_or_smp_parse(app, builder);
|
||||
|
||||
return ((t_redirect *)NULL);
|
||||
}
|
||||
#define FT_TOKENTYPE_WORD 65
|
||||
t_cmd *minishell_simple_parse(t_minishell *app, t_cmd_builder *builder)
|
||||
{
|
||||
ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word);
|
||||
t_cmd *subtree;
|
||||
t_worddesc *old_worddesc;
|
||||
|
||||
subtree = minishell_redir_parse(app, builder);
|
||||
|
||||
// a virer
|
||||
builder->tokens->word->token_type = FT_TOKENTYPE_WORD;
|
||||
|
||||
if (builder->tokens->word->token_type != FT_TOKENTYPE_WORD)
|
||||
return (parse_error(app, builder->tokens->word), NULL);
|
||||
|
||||
old_worddesc = wordlist_pop(builder->tokens);
|
||||
|
||||
|
||||
|
||||
subtree = minishell_redir_parse(app, builder);
|
||||
|
||||
return (subtree);
|
||||
}
|
||||
|
||||
t_cmd *minishell_opt_pipeline_parse(t_minishell *app, t_cmd_builder *builder)
|
||||
{
|
||||
return ((t_cmd *)NULL);
|
||||
}
|
||||
|
||||
t_cmd *minishell_group_or_smp_parse(t_minishell *app, t_cmd_builder *builder)
|
||||
{
|
||||
ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word);
|
||||
t_cmd *subtree;
|
||||
|
||||
subtree = minishell_simple_parse(app, builder);
|
||||
|
||||
|
||||
return (subtree);
|
||||
}
|
||||
|
||||
t_cmd *minishell_opt_cmds_parse(t_minishell *app, t_cmd_builder *builder)
|
||||
t_cmd *minishell_opt_cmds_parse(t_minishell *app, t_cmd_builder *builder,
|
||||
t_connector *connec)
|
||||
{
|
||||
ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word);
|
||||
|
||||
|
||||
return ((t_cmd *)NULL);
|
||||
}
|
||||
|
||||
t_cmd *minishell_pipeline_parse(t_minishell *app, t_cmd_builder *builder)
|
||||
{
|
||||
ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word);
|
||||
t_cmd *subtree;
|
||||
|
||||
subtree = minishell_group_or_smp_parse(app, builder);
|
||||
|
||||
|
||||
|
||||
|
||||
return (subtree);
|
||||
}
|
||||
|
||||
/*
|
||||
** Parse list of commands or pipeline.
|
||||
*/
|
||||
// TODO refactor
|
||||
t_cmd *minishell_cmds_parse(t_minishell *app, t_cmd_builder *builder)
|
||||
{
|
||||
t_cmd *subtree;
|
||||
t_cmd *opt;
|
||||
ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word);
|
||||
|
||||
t_cmd *subtree;
|
||||
t_cmd *opt;
|
||||
t_cmd *list;
|
||||
t_connector connec;
|
||||
|
||||
subtree = minishell_pipeline_parse(app, builder);
|
||||
if (!subtree)
|
||||
return (NULL); //ft_errno?
|
||||
ft_errno(FT_ESUCCESS);
|
||||
opt = minishell_opt_cmds_parse(app, builder);
|
||||
if (!opt && ft_errno_get() != FT_ESUCCESS)
|
||||
opt = minishell_opt_cmds_parse(app, builder, &connec);
|
||||
if (!opt && ft_errno_get() != FT_ESUCCESS) //error probably already signaled
|
||||
return (NULL);
|
||||
if ()
|
||||
return (subtree);
|
||||
if (!opt) //Simple Pipeline of some form
|
||||
return (subtree);
|
||||
while (opt)
|
||||
{
|
||||
list = ft_calloc(1, sizeof(t_cmd));
|
||||
if (!list)
|
||||
{
|
||||
app->last_return_value = 1;
|
||||
ft_errno(FT_ENOMEM);
|
||||
return (ft_perror("minishell_cmds_parse"), NULL);
|
||||
}
|
||||
list->type = FT_CONNECTION;
|
||||
list->connector = connec;
|
||||
list->first = subtree;
|
||||
list->second = opt;
|
||||
subtree = list;
|
||||
opt = minishell_opt_cmds_parse(app, builder, &connec);
|
||||
}
|
||||
if (ft_errno_get() != FT_ESUCCESS)
|
||||
return (NULL);
|
||||
return (list);
|
||||
}
|
||||
|
||||
/*
|
||||
** TODO Recheck error cases to see if allocation error occurred or something
|
||||
** else and if this is necessary.
|
||||
** TODO Include destruction of builder contents if necessary.
|
||||
*/
|
||||
t_cmd *minishell_parse(t_minishell *app, char *command_line)
|
||||
{
|
||||
t_cmd_builder builder;
|
||||
t_cmd *root_cmd;
|
||||
|
||||
ft_errno(FT_ESUCCESS);
|
||||
if (!command_line)
|
||||
return (NULL);
|
||||
builder.tokens = minishell_wordsplit(command_line);
|
||||
if (!builder.tokens)
|
||||
return (NULL);
|
||||
root_cmd = minishell_cmds_parse(app, &builder);
|
||||
if (!root_cmd || builder.tokens)
|
||||
if (!root_cmd)
|
||||
return (NULL); // destroy builder contents?
|
||||
if (builder.tokens)
|
||||
{
|
||||
parse_error(app, builder.tokens->word);
|
||||
return (NULL);
|
||||
return (NULL); /////// destroy builder contents?
|
||||
}
|
||||
return (root_cmd);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue