mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
fix(parsing/cmdgroup): report error the same way as everywhere else, prevent double report
before: ``` $ () minishell: syntax error near unexpected token `)' minishell: syntax error near unexpected token `)' ``` after: ``` $ () minishell: syntax error near unexpected token `)' ``` This probably fixes a few bugs as well, but I didn't look too hard. It just seemed nicer to have a consistent way to report errors.
This commit is contained in:
parent
ced979dd31
commit
96e46e9130
4 changed files with 23 additions and 20 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/31 10:28:28 by jguelen #+# #+# */
|
/* Created: 2025/03/31 10:28:28 by jguelen #+# #+# */
|
||||||
/* Updated: 2025/04/16 13:12:35 by khais ### ########.fr */
|
/* Updated: 2025/04/16 15:39:50 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,6 +17,14 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "cmd/cmd_destroy.h"
|
#include "cmd/cmd_destroy.h"
|
||||||
#include "cmd/cmds_parse.h"
|
#include "cmd/cmds_parse.h"
|
||||||
|
#include "../ft_errno.h"
|
||||||
|
|
||||||
|
static void parse_error(t_minishell *app, t_worddesc *token)
|
||||||
|
{
|
||||||
|
ft_dprintf(STDERR_FILENO, "minishell: syntax error near unexpected "
|
||||||
|
"token `%s'\n", token->word);
|
||||||
|
app->last_return_value = 2;
|
||||||
|
}
|
||||||
|
|
||||||
static void parse_error_newline(t_minishell *app)
|
static void parse_error_newline(t_minishell *app)
|
||||||
{
|
{
|
||||||
|
|
@ -27,13 +35,6 @@ static void parse_error_newline(t_minishell *app)
|
||||||
worddesc_destroy(token);
|
worddesc_destroy(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse_error(t_minishell *app, t_worddesc *token)
|
|
||||||
{
|
|
||||||
ft_dprintf(STDERR_FILENO, "minishell: syntax error near unexpected "
|
|
||||||
"token `%s'\n", token->word);
|
|
||||||
app->last_return_value = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** TODO check if we need to differentiate the cause of a NULL return.
|
** TODO check if we need to differentiate the cause of a NULL return.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/15 10:14:13 by khais #+# #+# */
|
/* Created: 2025/04/15 10:14:13 by khais #+# #+# */
|
||||||
/* Updated: 2025/04/16 13:11:11 by khais ### ########.fr */
|
/* Updated: 2025/04/16 15:39:16 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,10 +14,8 @@
|
||||||
# define CMD_PARSING_H
|
# define CMD_PARSING_H
|
||||||
|
|
||||||
# include "../minishell.h"
|
# include "../minishell.h"
|
||||||
# include "../ft_errno.h"
|
|
||||||
# include <stdbool.h>
|
# include <stdbool.h>
|
||||||
|
|
||||||
void parse_error(t_minishell *app, t_worddesc *token);
|
|
||||||
t_redirect *t_redirect_add_back(t_redirect **init, t_redirect *back);
|
t_redirect *t_redirect_add_back(t_redirect **init, t_redirect *back);
|
||||||
t_cmd *minishell_parse(t_minishell *app, char *command_line);
|
t_cmd *minishell_parse(t_minishell *app, char *command_line);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/15 10:46:28 by khais #+# #+# */
|
/* Created: 2025/04/15 10:46:28 by khais #+# #+# */
|
||||||
/* Updated: 2025/04/16 13:12:57 by khais ### ########.fr */
|
/* Updated: 2025/04/16 15:43:44 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "group_cmd_parse.h"
|
#include "group_cmd_parse.h"
|
||||||
#include "../cmd_parsing.h"
|
#include "../../ft_errno.h"
|
||||||
#include "../cmd/cmd_destroy.h"
|
#include "../cmd/cmd_destroy.h"
|
||||||
#include "../cmd/cmd.h"
|
#include "../cmd/cmd.h"
|
||||||
#include "../redirect/redirect_parse.h"
|
#include "../redirect/redirect_parse.h"
|
||||||
|
|
@ -24,14 +24,9 @@ t_cmd *minishell_group_cmd_parse(t_minishell *app, t_wordlist **tokens)
|
||||||
t_cmd *group;
|
t_cmd *group;
|
||||||
|
|
||||||
subtree = minishell_cmds_parse(app, tokens);
|
subtree = minishell_cmds_parse(app, tokens);
|
||||||
if (!subtree
|
if (!subtree || (*tokens) == NULL
|
||||||
|| (*tokens)->word->token_type != CLOSE_PARENTH_TOKEN)
|
|| (*tokens)->word->token_type != CLOSE_PARENTH_TOKEN)
|
||||||
{
|
return (cmd_destroy(subtree), ft_errno(FT_EERRNO), NULL);
|
||||||
ft_errno(FT_EERRNO);
|
|
||||||
if ((*tokens)->word->token_type != CLOSE_PARENTH_TOKEN)
|
|
||||||
parse_error(app, (*tokens)->word);
|
|
||||||
return (cmd_destroy(subtree), NULL);
|
|
||||||
}
|
|
||||||
worddesc_destroy(wordlist_pop(tokens));
|
worddesc_destroy(wordlist_pop(tokens));
|
||||||
group = cmd_create(FT_GROUP);
|
group = cmd_create(FT_GROUP);
|
||||||
if (!group)
|
if (!group)
|
||||||
|
|
|
||||||
9
test.sh
9
test.sh
|
|
@ -635,4 +635,13 @@ minishell: syntax error near unexpected token `|'
|
||||||
2
|
2
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
when_run <<EOF "unclosed cmdgroup"
|
||||||
|
(echo hi
|
||||||
|
echo \$?
|
||||||
|
EOF
|
||||||
|
expecting <<"EOF"
|
||||||
|
minishell: syntax error near unexpected token `newline'
|
||||||
|
2
|
||||||
|
EOF
|
||||||
|
|
||||||
finalize
|
finalize
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue