parse-cmd: A very basic skeleton of functions to come

This commit is contained in:
Jérôme Guélen 2025-04-04 18:26:10 +02:00 committed by Jerome
parent f490cc22f5
commit 5f95751b36
3 changed files with 105 additions and 6 deletions

View file

@ -6,13 +6,14 @@
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <sys/stat.h>
@ -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;

79
src/parser/cmd_parsing.c Normal file
View file

@ -0,0 +1,79 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cmd_parsing.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jguelen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -3,16 +3,18 @@
/* ::: :::::::: */
/* cmd_parsing.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jguelen <marvin@42.fr> +#+ +:+ +#+ */
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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