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
5
Makefile
5
Makefile
|
|
@ -15,7 +15,8 @@ IFLAGS = -I$(LIBFTDIR)
|
|||
LINCLUDE = -L$(LIBFTDIR)
|
||||
|
||||
ifeq ($(CFLAGS),)
|
||||
CFLAGS = -Wall -Wextra -Werror $(DEBUG)
|
||||
CFLAGS = $(DEBUG)
|
||||
# CFLAGS = -Wall -Wextra -Werror $(DEBUG)
|
||||
endif
|
||||
export CFLAGS
|
||||
srcs = \
|
||||
|
|
@ -83,6 +84,8 @@ srcs = \
|
|||
src/subst/wildcard_exp_utils.c \
|
||||
src/subst/wildcard_exp_utils2.c \
|
||||
src/treedrawing.c \
|
||||
src/parser/cmd_parsing.c
|
||||
|
||||
|
||||
objs = $(srcs:.c=.o)
|
||||
export objs
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ LIST_OP -> ||
|
|||
## Grammar after removal of left recursivity
|
||||
|
||||
The same priorities as the previous version except it is now LL(1) and
|
||||
therefore compatible with descending syntax analysisi (LL(1)).
|
||||
therefore compatible with descending syntax analysis (LL(1)).
|
||||
|
||||
```
|
||||
LINE -> CMDS eol
|
||||
|
|
@ -41,7 +41,7 @@ OPT_PIPELINE -> | GROUP_OR_SIMPLE OPT_PIPELINE
|
|||
OPT_PIPELINE -> ε
|
||||
GROUP_OR_SIMPLE -> (CMDS) REDIR
|
||||
GROUP_OR_SIMPLE -> SIMPLE
|
||||
SIMPLE -> REDIR word REDIR SIMPLE_LST
|
||||
SIMPLE -> REDIR word REDIR SIMPLST
|
||||
SIMPLE_LST -> word REDIR SIMPLE_LST
|
||||
SIMPLE_LST -> ε
|
||||
REDIR -> > word REDIR
|
||||
|
|
|
|||
|
|
@ -3,15 +3,14 @@
|
|||
/* ::: :::::::: */
|
||||
/* builtin_cd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/31 16:20:17 by khais #+# #+# */
|
||||
/* Updated: 2025/03/31 20:04:28 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/07 17:35:16 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "builtins.h"
|
||||
#include "ft_printf.h"
|
||||
#include "libft.h"
|
||||
#include <unistd.h>
|
||||
#include "../../env/env_manip.h"
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
/* ::: :::::::: */
|
||||
/* minishell.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/06 13:44:06 by kcolin #+# #+# */
|
||||
/* Updated: 2025/04/01 13:36:52 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/07 18:07:30 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -23,6 +23,7 @@
|
|||
#include "env/env_convert.h"
|
||||
#include "postprocess/expansion/expand_vars.h"
|
||||
|
||||
|
||||
/*
|
||||
** Parse shell commands from line.
|
||||
**
|
||||
|
|
@ -75,12 +76,33 @@ static void app_init(t_minishell *app, char **envp)
|
|||
app->env = env_from_envp(envp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
t_cmd *minishell_parse(t_minishell *app, char *command_line);
|
||||
|
||||
int main(int argc, char *argv[], char **envp)
|
||||
{
|
||||
char *line;
|
||||
t_simple_cmd *cmd;
|
||||
t_minishell app;
|
||||
|
||||
|
||||
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
app_init(&app, envp);
|
||||
|
||||
|
||||
line = "echo coucou";
|
||||
|
||||
minishell_parse(&app, line);
|
||||
|
||||
return (0);
|
||||
|
||||
|
||||
|
||||
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
app_init(&app, envp);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/28 14:55:31 by khais #+# #+# */
|
||||
/* Updated: 2025/04/04 16:05:25 by jguelen ### ########.fr */
|
||||
/* Updated: 2025/04/07 18:09:12 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
# include "libft.h"
|
||||
# include "env/env.h"
|
||||
# include "parser/wordlist/wordlist.h"
|
||||
# include "parser/wordsplit/wordsplit.h"
|
||||
# include <sys/stat.h>
|
||||
# include <fcntl.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/28 17:49:55 by jguelen #+# #+# */
|
||||
/* Updated: 2025/04/04 18:25:25 by jguelen ### ########.fr */
|
||||
/* Updated: 2025/04/07 17:59:08 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,6 +14,7 @@
|
|||
# define CMD_PARSING_H
|
||||
|
||||
# include "../minishell.h"
|
||||
# include "../ft_errno.h"
|
||||
|
||||
typedef struct s_cmd_builder
|
||||
{
|
||||
|
|
@ -27,17 +28,21 @@ typedef struct s_cmd_builder
|
|||
t_redirectee *last_here_doc;
|
||||
} t_cmd_builder;
|
||||
|
||||
void parse_error(t_minishell *app, t_worddesc *token);
|
||||
t_cmd *minishell_parse(t_minishell *app, char *command_line);
|
||||
void parse_error(t_minishell *app, t_worddesc *token);
|
||||
t_cmd *minishell_parse(t_minishell *app, char *command_line);
|
||||
|
||||
t_cmd *minishell_cmds_parse(t_minishell *app, t_cmd_builder *builder);
|
||||
t_cmd *minishell_pipeline_parse(t_minishell *app, t_cmd_builder *builder);
|
||||
t_cmd *minishell_opt_cmds_parse(t_minishell *app, t_cmd_builder *builder);
|
||||
t_cmd *minishell_group_or_smp_parse(t_minishell *app, t_cmd_builder *builder);
|
||||
t_cmd *minishell_opt_pipeline_parse(t_minishell *app, t_cmd_builder *builder);
|
||||
t_cmd *minishell_simple_parse(t_minishell *app, t_cmd_builder *builder);
|
||||
t_cmd *minishell_redir_parse(t_minishell *app, t_cmd_builder *builder);
|
||||
t_cmd *minishell_simple_lst_parse(t_minishell *app, t_cmd_builder *builder);
|
||||
t_cmd *minishell_cmds_parse(t_minishell *app, t_cmd_builder *builder);
|
||||
t_cmd *minishell_pipeline_parse(t_minishell *app, t_cmd_builder *builder);
|
||||
t_cmd *minishell_opt_cmds_parse(t_minishell *app, t_cmd_builder *builder,
|
||||
t_connector *connec);
|
||||
t_cmd *minishell_group_or_smp_parse(t_minishell *app,
|
||||
t_cmd_builder *builder);
|
||||
t_cmd *minishell_opt_pipeline_parse(t_minishell *app,
|
||||
t_cmd_builder *builder);
|
||||
t_cmd *minishell_simple_parse(t_minishell *app, t_cmd_builder *builder);
|
||||
t_redirect *minishell_redir_parse(t_minishell *app, t_cmd_builder *builder);
|
||||
t_cmd *minishell_simple_lst_parse(t_minishell *app,
|
||||
t_cmd_builder *builder);
|
||||
|
||||
t_connector which_connector_type(t_worddesc *token);
|
||||
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
/* ::: :::::::: */
|
||||
/* cmdgroup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/11 15:18:02 by khais #+# #+# */
|
||||
/* Updated: 2025/03/28 15:01:55 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/07 17:36:19 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,7 +16,6 @@
|
|||
#include "libft.h"
|
||||
#include "paren.h"
|
||||
#include "../../treedrawing.h"
|
||||
#include "libft/libft.h"
|
||||
|
||||
/*
|
||||
** Recursively parse a cmdgroup
|
||||
|
|
|
|||
|
|
@ -3,15 +3,14 @@
|
|||
/* ::: :::::::: */
|
||||
/* pipeline_parse.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/24 14:36:43 by khais #+# #+# */
|
||||
/* Updated: 2025/03/04 13:19:46 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/07 17:39:10 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "pipeline_parse.h"
|
||||
#include "ft_printf.h"
|
||||
#include "pipeline.h"
|
||||
#include "pipeline_parse_baseops.h"
|
||||
#include "../../ft_errno.h"
|
||||
|
|
|
|||
|
|
@ -3,16 +3,15 @@
|
|||
/* ::: :::::::: */
|
||||
/* worddesc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/13 17:20:36 by khais #+# #+# */
|
||||
/* Updated: 2025/03/27 13:58:41 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/07 17:40:03 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "worddesc.h"
|
||||
#include "libft.h"
|
||||
#include "libft/libft.h"
|
||||
#include <stdlib.h>
|
||||
#include "../../treedrawing.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
/* ::: :::::::: */
|
||||
/* worddesc.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/27 13:57:44 by khais #+# #+# */
|
||||
/* Updated: 2025/03/27 13:57:49 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/07 18:40:53 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ typedef struct s_worddesc
|
|||
char *word;
|
||||
/*
|
||||
** flags for this word
|
||||
**
|
||||
**s_worddesc
|
||||
** See above for flag definitions
|
||||
*/
|
||||
char flags;
|
||||
|
|
@ -48,7 +48,7 @@ typedef struct s_worddesc
|
|||
** a character mask for word to designate the status
|
||||
** of its characters and wether or not they are subject to modifications
|
||||
**
|
||||
** Possible flags are ''', '"', '$', ' '
|
||||
** Possible flags are ''', '"', '$', '&', ' '
|
||||
**
|
||||
** ' ' the default, no flag, no meaning
|
||||
** ''' corresponding character is single-quoted
|
||||
|
|
@ -56,6 +56,7 @@ typedef struct s_worddesc
|
|||
** '$' corresponding character is a result of $var expansion
|
||||
*/
|
||||
char *marker;
|
||||
int token_type;
|
||||
} t_worddesc;
|
||||
|
||||
t_worddesc *worddesc_create(char *word, char flags, char *marker);
|
||||
|
|
|
|||
|
|
@ -6,12 +6,11 @@
|
|||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/13 17:07:01 by khais #+# #+# */
|
||||
/* Updated: 2025/03/21 10:43:41 by jguelen ### ########.fr */
|
||||
/* Updated: 2025/04/07 17:40:30 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "wordlist.h"
|
||||
#include "ft_printf.h"
|
||||
#include "libft.h"
|
||||
#include "unistd.h"
|
||||
#include <stdlib.h>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue