diff --git a/src/minishell.h b/src/minishell.h index d7f989c..e444d55 100644 --- a/src/minishell.h +++ b/src/minishell.h @@ -6,13 +6,14 @@ /* By: jguelen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/28 14:55:31 by khais #+# #+# */ -/* Updated: 2025/03/28 16:42:57 by jguelen ### ########.fr */ +/* Updated: 2025/04/04 16:05:25 by jguelen ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef MINISHELL_H # define MINISHELL_H +# include "libft.h" # include "env/env.h" # include "parser/wordlist/wordlist.h" # include @@ -115,6 +116,7 @@ typedef struct s_simple_cmd typedef struct s_minishell { t_env *env; + int lines_read; int last_return_value; } t_minishell; diff --git a/src/parser/cmd_parsing.c b/src/parser/cmd_parsing.c new file mode 100644 index 0000000..2b602ae --- /dev/null +++ b/src/parser/cmd_parsing.c @@ -0,0 +1,79 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* cmd_parsing.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jguelen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/03/31 10:28:28 by jguelen #+# #+# */ +/* Updated: 2025/04/04 18:21:17 by jguelen ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "cmd_parsing.h" + +/* +** NOTE: Tjis file will temporarily include way more fucntions than allowed. +*/ + +void parse_error(t_minishell *app, t_worddesc *token) +{ + ft_dprintf(STDERR_FILENO, "minishell: syntax error near unexpected " + "token `%s'", token->word); + app->last_return_value = 2; +} + +t_connector which_connector_type(t_worddesc *token) +{ +} + +t_cmd *minishell_simple_lst_parse(t_minishell *app, t_cmd_builder *builder) +{ +} + +t_cmd *minishell_redir_parse(t_minishell *app, t_cmd_builder *builder) +{ +} + +t_cmd *minishell_simple_parse(t_minishell *app, t_cmd_builder *builder) +{ +} + +t_cmd *minishell_opt_pipeline_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_cmds_parse(t_minishell *app, t_cmd_builder *builder) +{ +} + +t_cmd *minishell_pipeline_parse(t_minishell *app, t_cmd_builder *builder) +{ +} + +t_cmd *minishell_cmds_parse(t_minishell *app, t_cmd_builder *builder) +{ +} + +/* +** TODO Recheck error cases to see if allocation error occurred or something +** else and if this is necessary. +*/ +t_cmd *minishell_parse(t_minishell *app, char *command_line) +{ + t_cmd_builder builder; + t_cmd *root_cmd; + + builder.tokens = minishell_wordsplit(command_line); + root_cmd = minishell_cmds_parse(app, &builder); + if (!root_cmd || builder.tokens) + { + parse_error(app, builder.tokens->word); + return (NULL); + } + return (root_cmd); +} diff --git a/src/parser/cmd_parsing.h b/src/parser/cmd_parsing.h index dfd2fe2..18c0622 100644 --- a/src/parser/cmd_parsing.h +++ b/src/parser/cmd_parsing.h @@ -3,16 +3,18 @@ /* ::: :::::::: */ /* cmd_parsing.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jguelen +#+ +:+ +#+ */ +/* By: jguelen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/28 17:49:55 by jguelen #+# #+# */ -/* Updated: 2025/03/28 18:55:00 by jguelen ### ########.fr */ +/* Updated: 2025/04/04 18:25:25 by jguelen ### ########.fr */ /* */ /* ************************************************************************** */ -#include "../minishell.h" +#ifndef CMD_PARSING_H +# define CMD_PARSING_H + +# include "../minishell.h" -//TODO typedef struct s_cmd_builder { t_wordlist *tokens; @@ -23,4 +25,20 @@ typedef struct s_cmd_builder ** last_here_doc is meant to store only one entry. */ 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); + +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_connector which_connector_type(t_worddesc *token); + +#endif