From 2025376e43a174586f087ff284d1f65798f555b2 Mon Sep 17 00:00:00 2001 From: nass1pro Date: Tue, 14 Jul 2020 13:12:55 +0200 Subject: update lexer --- src/error.c | 57 ------------------------------------------------- src/eval/error.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++ src/lexer/lexer.c | 7 +++++- src/lexer/trim.c | 3 +++ src/parse/parse.c | 10 +++++---- src/parse/parse_error.c | 2 +- src/utils.c | 2 +- 7 files changed, 72 insertions(+), 64 deletions(-) delete mode 100644 src/error.c create mode 100644 src/eval/error.c (limited to 'src') diff --git a/src/error.c b/src/error.c deleted file mode 100644 index f5848a6..0000000 --- a/src/error.c +++ /dev/null @@ -1,57 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* error.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: charles +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/06/14 11:02:52 by charles #+# #+# */ -/* Updated: 2020/07/14 09:23:38 by charles ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "eval.h" - -static t_error g_errors[] = -{ - {ERROR_AMBIGUOUS_REDIR, 1, "ambiguous redirect"}, - {ERROR_OPEN, 1, NULL}, - {ERROR_CMD_NOT_FOUND, 127, "command not found"}, - /* {ERROR_CMD_FOUND_ERROR, 126, NULL}, */ - {ERROR_SYNTAX, 2, "syntax error near unexpected token "}, -}; - -t_error *st_error_get(enum e_error id) -{ - size_t i; - t_error *match; - - match = NULL; - i = 0; - while (i < sizeof(g_errors) / sizeof(t_error)) - { - if (g_errors[i].id == id) - match = &g_errors[i]; - i++; - } - return (match); -} - -void error_eval_put(enum e_error id, char *unexpected) -{ - t_error *err; - - err = st_error_get(id); - ft_putstr_fd("minishell: ", STDERR_FILENO); - ft_putstr_fd(unexpected, STDERR_FILENO); - ft_putstr_fd(": ", STDERR_FILENO); - if (err->msg == NULL) - ft_putendl_fd(strerror(errno), STDERR_FILENO); - else - ft_putendl_fd(err->msg, STDERR_FILENO); -} - -int error_status(enum e_error id) -{ - return (st_error_get(id)->status); -} diff --git a/src/eval/error.c b/src/eval/error.c new file mode 100644 index 0000000..10f5740 --- /dev/null +++ b/src/eval/error.c @@ -0,0 +1,55 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* error.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/06/14 11:02:52 by charles #+# #+# */ +/* Updated: 2020/07/14 11:10:12 by nahaddac ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "eval.h" + +static t_error g_errors[] = +{ + {ERROR_AMBIGUOUS_REDIR, 1, "ambiguous redirect"}, + {ERROR_OPEN, 1, NULL}, + {ERROR_CMD_NOT_FOUND, 127, "command not found"}, +}; + +t_error *st_error_get(enum e_error id) +{ + size_t i; + t_error *match; + + match = NULL; + i = 0; + while (i < sizeof(g_errors) / sizeof(t_error)) + { + if (g_errors[i].id == id) + match = &g_errors[i]; + i++; + } + return (match); +} + +void error_eval_put(enum e_error id, char *unexpected) +{ + t_error *err; + + err = st_error_get(id); + ft_putstr_fd("minishell: ", STDERR_FILENO); + ft_putstr_fd(unexpected, STDERR_FILENO); + ft_putstr_fd(": ", STDERR_FILENO); + if (err->msg == NULL) + ft_putendl_fd(strerror(errno), STDERR_FILENO); + else + ft_putendl_fd(err->msg, STDERR_FILENO); +} + +int error_status(enum e_error id) +{ + return (st_error_get(id)->status); +} diff --git a/src/lexer/lexer.c b/src/lexer/lexer.c index 3bf9dc2..400c161 100644 --- a/src/lexer/lexer.c +++ b/src/lexer/lexer.c @@ -24,14 +24,19 @@ int len_is_not_sep(char *input) int check_input(char *input) { int i; + int op; i = 0; + op = 1; if (input[i] == '(' || input[i] == ')') return (i + 1); if (lexer_sep(input[i])) { - while(input[i] == input[i + 1]) + while(input[i] == input[i + 1] && op < 2) + { i++; + op++; + } i += lexe_space(&input[i + 1]); return (i + 1); } diff --git a/src/lexer/trim.c b/src/lexer/trim.c index 6c435d5..911004c 100644 --- a/src/lexer/trim.c +++ b/src/lexer/trim.c @@ -35,6 +35,9 @@ char *del_quote(char *str) if (str[i] == '\'' || str[i] == '"') break; } + + if(str[i] != '\'' && str[i] != '"') + return str; s = ft_strsubf(str, 1, i - 1); return (s); } diff --git a/src/parse/parse.c b/src/parse/parse.c index b2532ac..5633a23 100644 --- a/src/parse/parse.c +++ b/src/parse/parse.c @@ -6,7 +6,7 @@ /* By: nahaddac +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/06/17 18:09:04 by nahaddac #+# #+# */ -/* Updated: 2020/07/14 10:03:00 by charles ### ########.fr */ +/* Updated: 2020/07/14 11:48:42 by nahaddac ### ########.fr */ /* */ /* ************************************************************************** */ @@ -103,6 +103,7 @@ t_ret *parse_op(t_ftlst *input) return ret_wrap_ast(left_ret->ast, input); tag = ((t_token*)input->data)->tag; + /* les sep */ input = input->next; right_ret = parse_op(input); @@ -135,7 +136,6 @@ t_ret *parse_expr(t_ftlst *input) tmp->ast = new_ast; if (input == NULL) return tmp; - // could reuse parse_redir instead tag = ((t_token*)input->data)->tag; while (tag & TAG_IS_REDIR) @@ -172,8 +172,10 @@ t_ret *parse(t_ftlst *input) return (NULL); ret->ast = NULL; ret->rest = NULL; - /* if((ret->unexpected = error_syntax_simple(input))) */ - /* return (ret); */ + ret->syntax_error = false; + // ret = error_syntax_simple(input, ret); + // if (ret->syntax_error == TRUE) + // return ret; ret = parse_op(input); return (ret); } diff --git a/src/parse/parse_error.c b/src/parse/parse_error.c index 3d988ae..1116a88 100644 --- a/src/parse/parse_error.c +++ b/src/parse/parse_error.c @@ -6,7 +6,7 @@ /* By: nahaddac +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/06/18 15:09:48 by nahaddac #+# #+# */ -/* Updated: 2020/07/14 10:01:43 by charles ### ########.fr */ +/* Updated: 2020/07/14 11:49:48 by nahaddac ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/utils.c b/src/utils.c index 7c1f496..4a9ecb8 100644 --- a/src/utils.c +++ b/src/utils.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/28 11:56:31 by cacharle #+# #+# */ -/* Updated: 2020/07/14 10:00:16 by charles ### ########.fr */ +/* Updated: 2020/07/14 10:40:59 by nahaddac ### ########.fr */ /* */ /* ************************************************************************** */ -- cgit