diff options
| author | nass1pro <nass1pro@gmail.com> | 2020-07-13 14:55:46 +0200 |
|---|---|---|
| committer | nass1pro <nass1pro@gmail.com> | 2020-07-13 14:55:46 +0200 |
| commit | 4ad25e7fe330df66725bf74a662a49bcd31b8a8a (patch) | |
| tree | 81d325bde4ad453ffcca4f382810ae6e62ffb6dc /src | |
| parent | 051d035e57918d824eab50b81288bd98a1a95675 (diff) | |
| download | minishell-4ad25e7fe330df66725bf74a662a49bcd31b8a8a.tar.gz minishell-4ad25e7fe330df66725bf74a662a49bcd31b8a8a.tar.bz2 minishell-4ad25e7fe330df66725bf74a662a49bcd31b8a8a.zip | |
test error gestion
Diffstat (limited to 'src')
| -rw-r--r-- | src/lexer/lexer.c | 9 | ||||
| -rw-r--r-- | src/lexer/lexer_utils.c | 4 | ||||
| -rw-r--r-- | src/lexer/trim.c | 21 | ||||
| -rw-r--r-- | src/main.c | 5 | ||||
| -rw-r--r-- | src/parse/parse.c | 44 | ||||
| -rw-r--r-- | src/parse/parse_error.c | 45 |
6 files changed, 46 insertions, 82 deletions
diff --git a/src/lexer/lexer.c b/src/lexer/lexer.c index 47dedc6..3bf9dc2 100644 --- a/src/lexer/lexer.c +++ b/src/lexer/lexer.c @@ -8,12 +8,7 @@ int len_is_not_sep(char *input) while(input[++i]) { if (lexer_sep(input[i])) - { - //if (input[i + 1] == ' ') - // while(input[++i] == ' ') - // ; return(i); - } if (input[i] == '\'' || input[i] == '"') return(i); if (input[i] == ' ') @@ -31,8 +26,8 @@ int check_input(char *input) int i; i = 0; - /* if (input[i] == '(' || input[i] == ')') */ - /* return (i + 1); */ + if (input[i] == '(' || input[i] == ')') + return (i + 1); if (lexer_sep(input[i])) { while(input[i] == input[i + 1]) diff --git a/src/lexer/lexer_utils.c b/src/lexer/lexer_utils.c index 3ee41ff..a6da3d4 100644 --- a/src/lexer/lexer_utils.c +++ b/src/lexer/lexer_utils.c @@ -14,7 +14,7 @@ enum e_token_tag ret_token(char *input, int i) { if (input[i] == ';') return(TAG_END); - if (input[i] == '&') + if (input[i] == '&' && input[i + 1] == '&') return(TAG_AND); if (input[i] == '|' && input[i + 1] == '|') return(TAG_OR); @@ -66,11 +66,11 @@ static int lex_verif_simple_cote(char *input, int i) i++; while(input[i] != '\0') { - ++i; if(input[i] == '\\') i+=1; if(input[i] == '\'') break; + ++i; } if (input[i + 1] == ' ') while(input[i + 1] == ' ') diff --git a/src/lexer/trim.c b/src/lexer/trim.c index f47aa6d..6c435d5 100644 --- a/src/lexer/trim.c +++ b/src/lexer/trim.c @@ -1,25 +1,6 @@ #include "lexer.h" -t_ftlst *stick_parent(t_ftlst *lst) -{ - t_ftlst *first; - t_token *tk; - - first = lst; - while (lst != NULL) - { - tk = lst->data; - if (tk->tag & TAG_PARENT_OPEN || tk->tag & TAG_PARENT_CLOSE) - { - if (ft_strlen(tk->content) >= 2) - tk->tag = tk->tag | TAG_STICK; - } - lst = lst->next; - } - return (first); -} - char *del_space(t_token *tk) { int i; @@ -83,5 +64,5 @@ t_ftlst *lexe_trim_out(t_ftlst *lst) } lst = lst->next; } - return (stick_parent(first)); + return (first); } @@ -6,7 +6,7 @@ /* By: cacharle <cacharle@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/28 11:45:44 by cacharle #+# #+# */ -/* Updated: 2020/07/13 10:54:54 by charles ### ########.fr */ +/* Updated: 2020/07/13 14:55:16 by nahaddac ### ########.fr */ /* */ /* ************************************************************************** */ @@ -85,6 +85,7 @@ int main(int argc, char **argv, char **envp) /* ft_lstiter(lex_out, token_debug); */ t_ret *parser_out = parse(lex_out); + printf("%s\n","ssss" ); if (parser_out == NULL || parser_out->unexpected != NULL) return (1); @@ -97,7 +98,7 @@ int main(int argc, char **argv, char **envp) /* ft_lstiter(parser_out->ast->cmd_argv, token_debug); */ /* printf("===redirs===\n"); */ /* ft_lstiter(parser_out->ast->redirs, token_debug); */ - + printf("%s\n", "salut "); int fds[2] = {MS_NO_FD, MS_NO_FD}; int eval_out = eval(fds, env, path, parser_out->ast); (void)eval_out; diff --git a/src/parse/parse.c b/src/parse/parse.c index 740726c..610b640 100644 --- a/src/parse/parse.c +++ b/src/parse/parse.c @@ -6,7 +6,7 @@ /* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/06/17 18:09:04 by nahaddac #+# #+# */ -/* Updated: 2020/06/23 08:35:29 by charles ### ########.fr */ +/* Updated: 2020/07/13 14:54:37 by nahaddac ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,6 @@ #include "parser.h" #include "lexer.h" - t_ftlst *push_token(t_ftlst **tokens, t_token *pushed) { t_ftlst *tmp; @@ -99,10 +98,8 @@ t_ret *parse_op(t_ftlst *input) enum e_token_tag tag; left_ret = parse_expr(input); - /* printf("%p\n", left_ret); */ input = left_ret->rest; - - if (input == NULL || ((t_token*)input->data)->tag == TAG_PARENT_CLOSE) + if (input == NULL || ((t_token*)input->data)->tag & TAG_PARENT_CLOSE) return ret_wrap_ast(left_ret->ast, input); tag = ((t_token*)input->data)->tag; @@ -121,18 +118,19 @@ t_ret *parse_expr(t_ftlst *input) { t_ret *tmp; enum e_token_tag tag; + t_ast *new_ast; tag = ((t_token*)input->data)->tag; - if (tag == TAG_PARENT_OPEN) + if (tag & TAG_PARENT_OPEN) { tmp = parse_op(input->next); input = tmp->rest; tag = ((t_token*)input->data)->tag; - if (tag != TAG_PARENT_CLOSE) + if (!(tag & TAG_PARENT_CLOSE)) return (NULL); input = input->next; - t_ast *new_ast = ast_new(AST_PARENT); + new_ast = ast_new(AST_PARENT); new_ast->parent_ast = tmp->ast; tmp->ast = new_ast; if (input == NULL) @@ -158,8 +156,6 @@ t_ret *parse_expr(t_ftlst *input) break; tag = ((t_token*)input->data)->tag; } - /* token_debug(input->data); */ - tmp->rest = input; return tmp; } @@ -169,19 +165,21 @@ t_ret *parse_expr(t_ftlst *input) t_ret *parse(t_ftlst *input) { t_ret *ret; - /* t_ftlst *in_f; */ - - /* in_f = input; */ - /* if (input == NULL) */ - /* return NULL; */ - /* if (!(ret = malloc(sizeof(t_ret) * 1))) */ - /* return (NULL); */ - /* ret->ast = NULL; */ - /* ret->rest = NULL; */ - /* if((ret->unexpected = error_syntax_simple(input)) != NULL) */ - /* printf("%s\n", ret->unexpected->content); */ + t_ftlst *in_f; + + in_f = input; + if (input == NULL) + return NULL; + if (!(ret = malloc(sizeof(t_ret) * 1))) + return (NULL); + ret->ast = NULL; + ret->rest = NULL; + + if((ret->unexpected = error_syntax_simple(input))) + return (ret); + printf("%s\n",((t_token *)ret->unexpected)->content); ret = parse_op(input); - /* ast_destroy(ret->ast); */ - /* ft_lstdestroy(&ret->rest, (void (*)(void*))token_destroy); */ + //ast_destroy(ret->ast); + //ft_lstdestroy(&ret->rest, (void (*)(void*))token_destroy); return (ret); } diff --git a/src/parse/parse_error.c b/src/parse/parse_error.c index b721c28..e48eda2 100644 --- a/src/parse/parse_error.c +++ b/src/parse/parse_error.c @@ -6,38 +6,27 @@ /* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/06/18 15:09:48 by nahaddac #+# #+# */ -/* Updated: 2020/06/19 12:46:56 by nahaddac ### ########.fr */ +/* Updated: 2020/07/13 14:30:39 by nahaddac ### ########.fr */ /* */ /* ************************************************************************** */ #include "parser.h" -t_token *error_syntax_parent(t_ftlst *in) -{ - int op; - int cl; - t_token *tk; - - op = 0; - cl = 0; - while(in != NULL) - { - tk = in->data; - if (tk->tag & TAG_PARENT_OPEN) - op++; - if(tk->tag & TAG_PARENT_CLOSE) - cl++; - if (cl && op == 0) - { - tk->content = ft_strjoin3( - "minishell: syntax error near unexpected token `", - tk->content, "'"); - return tk; - } - in = in->next; - } - return NULL; -} +// t_token *error_syntax_parent(t_ftlst *in) +// { +// t_token *tk; +// t_ftlst *first; +// +// first = in; +// while(in != NULL) +// { +// tk = in->data; +// if (tk->tag & TAG_PARENT_OPEN || tk->tag & TAG_PARENT_CLOSE) +// printf("%s\n", "coucouc"); +// in = in->next; +// } +// return first; +// } int out_error_first(t_token *tk) { @@ -101,6 +90,6 @@ t_token *error_syntax_simple(t_ftlst *in) } in = in->next; } - return error_syntax_parent(first); + return first; } |
