diff --git a/42sh/sample/while.sh b/42sh/sample/while.sh index 5c8513f7..229a5274 100644 --- a/42sh/sample/while.sh +++ b/42sh/sample/while.sh @@ -1,7 +1,8 @@ -while ls | cat ; pwd +while ls | cat ; do - while ls | cat + echo hello + while ls do - echo monde ; cat - done + echo ; cat + done done > file1 diff --git a/42sh/src/main/ft_putast.c b/42sh/src/main/ft_putast.c index e17643eb..cf95aa07 100644 --- a/42sh/src/main/ft_putast.c +++ b/42sh/src/main/ft_putast.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 18:18:04 by jhalford #+# #+# */ -/* Updated: 2017/02/03 19:35:03 by ariard ### ########.fr */ +/* Updated: 2017/02/05 00:32:21 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,6 +34,10 @@ char *ft_putast(void *nodein) return (" COM "); else if (node->type == TK_WHILE) return (" WHILE "); + else if (node->type == TK_DO) + return ("DO"); + else if (node->type == TK_DONE) + return ("DONE"); else if (node->type == TK_NEWLINE) return ("NEW"); else if (node->type == TK_LIST) diff --git a/42sh/src/parser/ft_parse.c b/42sh/src/parser/ft_parse.c index 3f2d2659..99f18c30 100644 --- a/42sh/src/parser/ft_parse.c +++ b/42sh/src/parser/ft_parse.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 17:14:58 by jhalford #+# #+# */ -/* Updated: 2017/02/05 00:14:17 by ariard ### ########.fr */ +/* Updated: 2017/02/05 00:39:31 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,7 @@ t_parser g_parser[] = { {TK_WHILE, &parse_while}, {TK_SEMI, &parse_separator}, +// {TK_NEWLINE, &parse_newline}, {TK_AND_IF | TK_OR_IF, &parse_separator}, {TK_AMP, &parse_separator}, {TK_PIPE, &parse_separator}, diff --git a/42sh/src/parser/parse_newline.c b/42sh/src/parser/parse_newline.c index 3078fe2f..5cd65c4b 100644 --- a/42sh/src/parser/parse_newline.c +++ b/42sh/src/parser/parse_newline.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/26 19:26:41 by ariard #+# #+# */ -/* Updated: 2017/02/04 20:22:57 by ariard ### ########.fr */ +/* Updated: 2017/02/05 00:40:14 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,17 +14,15 @@ int parse_newline(t_btree **ast, t_list **start, t_list **lst) { - t_list *temp; t_astnode *node; t_token *token; + (void)start; token = (*lst)->content; node = (*ast)->item; node->type = TK_NEWLINE; - temp = (*lst)->next; - (*lst)->next = NULL; - ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); - ft_parse(ast, start); - *start = temp; + ft_parse(&(*ast)->right, &(*lst)->next); + ft_lstdelone(lst, &token_free); + ft_parse(&(*ast)->left, start); return (0); } diff --git a/42sh/src/parser/parse_separator.c b/42sh/src/parser/parse_separator.c index a51f5dfe..34a09c65 100644 --- a/42sh/src/parser/parse_separator.c +++ b/42sh/src/parser/parse_separator.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 16:21:51 by jhalford #+# #+# */ -/* Updated: 2017/02/05 00:03:10 by ariard ### ########.fr */ +/* Updated: 2017/02/05 00:24:54 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/parse_while.c b/42sh/src/parser/parse_while.c index 14262d84..abb53505 100644 --- a/42sh/src/parser/parse_while.c +++ b/42sh/src/parser/parse_while.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/30 16:03:28 by ariard #+# #+# */ -/* Updated: 2017/02/05 00:14:32 by ariard ### ########.fr */ +/* Updated: 2017/02/05 00:40:21 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,11 +21,11 @@ static int delete_all_newline(t_list **lst) { token = (*lst)->content; start = *lst; + (*lst) = (*lst)->next; if (token->type & TK_NEWLINE) - ft_lst_delif(&start, (*lst)->content, &ft_addrcmp, &token_free); + ft_lstdelone(&start, &token_free); else break; - (*lst) = (*lst)->next; } return (0); } @@ -78,6 +78,8 @@ int parse_while(t_btree **ast, t_list **start, t_list **lst) ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); ft_parse(&(temp3)->left, start); + return (0); + delete_all_newline(&temp); ft_parse(&(temp3)->right, &temp);