diff --git a/42sh/file1 b/42sh/file1 deleted file mode 100644 index e69de29b..00000000 diff --git a/42sh/file2 b/42sh/file2 deleted file mode 100644 index cfa36b69..00000000 --- a/42sh/file2 +++ /dev/null @@ -1,9 +0,0 @@ -hello -hello -hello -hello -hello -hello -hello -hello -hello diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index 6705e201..bbe528b3 100644 --- a/42sh/includes/lexer.h +++ b/42sh/includes/lexer.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */ -/* Updated: 2017/02/03 19:47:09 by ariard ### ########.fr */ +/* Updated: 2017/02/04 15:05:41 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -55,6 +55,7 @@ typedef long long t_type; # define TK_WORD (TK_N_WORD | TK_Q_WORD | TK_DQ_WORD) # define TK_REDIR (0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20) # define TK_NON_FREEABLE (TK_PAREN_OPEN | TK_PAREN_CLOSE | TK_BQUOTE) +# define SHELL_SEP (TK_NEWLINE | TK_AMP | TK_SEMI | TK_DO) enum e_lexstate { diff --git a/42sh/sample/while.sh b/42sh/sample/while.sh index 5b4bdabd..88d0b181 100644 --- a/42sh/sample/while.sh +++ b/42sh/sample/while.sh @@ -1,20 +1,9 @@ while [ 1 ] -do - while pwd - do - while pwd +do while pwd + do + while ls do - while pwd - do - echo "hello" - done - done - done - while pwd - do - while pwd - do - echo "bonjour" + echo hello done done done diff --git a/42sh/src/lexer/ft_lexer.c b/42sh/src/lexer/ft_lexer.c index f10f97ca..237127f8 100644 --- a/42sh/src/lexer/ft_lexer.c +++ b/42sh/src/lexer/ft_lexer.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/02 15:30:59 by jhalford #+# #+# */ -/* Updated: 2017/02/03 19:40:31 by ariard ### ########.fr */ +/* Updated: 2017/02/04 15:12:32 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/ft_post_tokenize.c b/42sh/src/lexer/ft_post_tokenize.c index 9727cf02..1f806fe1 100644 --- a/42sh/src/lexer/ft_post_tokenize.c +++ b/42sh/src/lexer/ft_post_tokenize.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/11 16:11:11 by jhalford #+# #+# */ -/* Updated: 2017/02/03 19:54:10 by ariard ### ########.fr */ +/* Updated: 2017/02/04 15:33:04 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,7 @@ int ft_post_tokenize(t_list **alst, char **str) int ret; t_flag tk; +// token_print(*alst); get_reserved_words(alst); while ((ret = reduce_parens(alst, *str))) if (ret == -1) diff --git a/42sh/src/lexer/ft_tokenize.c b/42sh/src/lexer/ft_tokenize.c index ae862e23..eabed451 100644 --- a/42sh/src/lexer/ft_tokenize.c +++ b/42sh/src/lexer/ft_tokenize.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:37:11 by jhalford #+# #+# */ -/* Updated: 2017/02/03 19:40:50 by ariard ### ########.fr */ +/* Updated: 2017/02/03 20:04:33 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/get_reserved_words.c b/42sh/src/lexer/get_reserved_words.c index d6f6ea6d..f02c9e0d 100644 --- a/42sh/src/lexer/get_reserved_words.c +++ b/42sh/src/lexer/get_reserved_words.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/26 00:07:05 by ariard #+# #+# */ -/* Updated: 2017/02/03 19:39:01 by ariard ### ########.fr */ +/* Updated: 2017/02/04 15:27:49 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,26 +15,18 @@ int get_reserved_words(t_list **alst) { t_token *token; + t_token *previous_token; t_list *temp; - int i; temp = *alst; - i = 0; + previous_token = NULL; while (temp) { token = temp->content; - if (i == 0) - if (token->type == TK_N_WORD) - if (ft_strncmp(token->data, "while", 5) == 0) - token->type = TK_WHILE; - if ((token->type & (TK_NEWLINE | TK_AMP | TK_SEMI))) + if (!previous_token || (previous_token->type & SHELL_SEP)) { - if ((temp = temp->next)) - token = temp->content; - else - break; if (token->type == TK_N_WORD) - { + { if (ft_strncmp(token->data, "while", 5) == 0) token->type = TK_WHILE; else if (ft_strncmp(token->data, "done", 4) == 0) @@ -43,8 +35,8 @@ int get_reserved_words(t_list **alst) token->type = TK_DO; } } + previous_token = token; temp = temp->next; - i++; } return (0); } diff --git a/42sh/src/main/shell_script.c b/42sh/src/main/shell_script.c index caef3e8b..9e038f8f 100644 --- a/42sh/src/main/shell_script.c +++ b/42sh/src/main/shell_script.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/22 23:06:34 by ariard #+# #+# */ -/* Updated: 2017/02/03 18:16:01 by ariard ### ########.fr */ +/* Updated: 2017/02/04 15:30:00 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/parse_newline.c b/42sh/src/parser/parse_newline.c index e7386b9d..f3faa810 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/03 17:16:47 by ariard ### ########.fr */ +/* Updated: 2017/02/03 20:04:40 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/parse_while.c b/42sh/src/parser/parse_while.c index 1fdc14f4..f3c53869 100644 --- a/42sh/src/parser/parse_while.c +++ b/42sh/src/parser/parse_while.c @@ -6,12 +6,28 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/30 16:03:28 by ariard #+# #+# */ -/* Updated: 2017/02/03 19:48:36 by ariard ### ########.fr */ +/* Updated: 2017/02/04 15:51:24 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "parser.h" +static int delete_all_newline(t_list **start, t_list **lst) +{ + t_token *token; + + while ((*lst)) + { + token = (*lst)->content; + if (token->type & TK_NEWLINE) + ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); + else + break; + (*lst) = (*lst)->next; + } + return (0); +} + int parse_while(t_btree **ast, t_list **start, t_list **lst) { t_list *temp; @@ -31,9 +47,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(&(*ast)->left, start); - (*lst) = temp; - ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); - temp = temp->next; + delete_all_newline(start, &temp); + (*lst) = temp; *start = temp; nest = 1; @@ -46,7 +61,6 @@ int parse_while(t_btree **ast, t_list **start, t_list **lst) nest--; if (nest == 0) break; - DG("nest : '%d'", nest); } temp = (*lst)->next; (*lst)->next = NULL;