From ae510a886b202926b4a5502de02a938054844ad4 Mon Sep 17 00:00:00 2001 From: nass1pro Date: Wed, 17 Jun 2020 19:01:25 +0200 Subject: Update line op --- src/parse/parse.c | 90 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 60 insertions(+), 30 deletions(-) (limited to 'src/parse/parse.c') diff --git a/src/parse/parse.c b/src/parse/parse.c index 1fc24be..b9bb156 100755 --- a/src/parse/parse.c +++ b/src/parse/parse.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parse.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: nahaddac +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/06/17 18:09:04 by nahaddac #+# #+# */ +/* Updated: 2020/06/17 18:36:54 by nahaddac ### ########.fr */ +/* */ +/* ************************************************************************** */ + /* ** \file parse.c ** \brief Parser @@ -11,11 +23,43 @@ +t_ast *cmd_push_ast(t_ftlst *rest) +{ + enum e_token_tag tag; + t_ast *ast; + + ast = NULL; + while (rest != NULL) + { + tag = ((t_token *)rest->data)->tag; + if (parse_cmd_str_true_false(tag)) + { + ast = push_cmd(ast, rest); + } + else if (parse_redir_true_false(tag)) + { + while(rest != NULL) + { + ast = push_redir(ast, rest); + if (tag & TAG_IS_STR && tag & TAG_STICK) + rest = rest->next; + else if (tag & TAG_IS_REDIR) + rest = rest->next; + else + break; + tag = ((t_token *)rest->data)->tag; + } + } + rest = rest->next; + } + return ast; +} + t_ret *parse(t_ftlst *input) { t_ret *ret; t_ret *first; - enum e_token_tag tag; + t_ast *new_ast; if(!(ret = malloc(sizeof(t_ret) * 1))) return(NULL); @@ -24,38 +68,24 @@ t_ret *parse(t_ftlst *input) ret->unexpected = NULL; first = ret; - while (ret->rest != NULL) + if(!(new_ast = malloc(sizeof(t_ast) * 1))) + return(0); + new_ast = cmd_push_ast(ret->rest); + printf("%s\n",((t_token *)ret->rest->data)->content); + if (ret->ast) { - tag = ((t_token *)ret->rest->data)->tag; - if (parse_cmd_str_true_false(tag)) - ret->ast = push_cmd(ret->ast, ret->rest); - else if (parse_redir_true_false(tag)) + while(ret->ast->cmd_argv != NULL) + { + printf("[%s]\n", ((t_token *)ret->ast->cmd_argv->data)->content); + ret->ast->cmd_argv = ret->ast->cmd_argv->next; + } + while(ret->ast->redirs != NULL) { - while(ret->rest != NULL) - { - ret->ast = push_redir(ret->ast, ret->rest); - if (tag & TAG_IS_STR && tag & TAG_STICK) - ret->rest = ret->rest->next; - else if (tag & TAG_IS_REDIR) - ret->rest = ret->rest->next; - else - break; - tag = ((t_token *)ret->rest->data)->tag; - } + printf("[%s]\n", ((t_token *)ret->ast->redirs->data)->content); + ret->ast->redirs = ret->ast->redirs->next; } - ret->rest = ret->rest->next; } - /* while(ret->ast->cmd_argv != NULL) */ - /* { */ - /* printf("[%s]\n", ((t_token *)ret->ast->cmd_argv->data)->content); */ - /* ret->ast->cmd_argv = ret->ast->cmd_argv->next; */ - /* } */ - /* while(ret->ast->redirs != NULL) */ - /* { */ - /* printf("[%s]\n", ((t_token *)ret->ast->redirs->data)->content); */ - /* ret->ast->redirs = ret->ast->redirs->next; */ - /* } */ - /* 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 first; } -- cgit