do as a sep + multiple newline
This commit is contained in:
parent
0a5143bd69
commit
9bbd6d7403
11 changed files with 37 additions and 49 deletions
|
|
@ -1,9 +0,0 @@
|
||||||
hello
|
|
||||||
hello
|
|
||||||
hello
|
|
||||||
hello
|
|
||||||
hello
|
|
||||||
hello
|
|
||||||
hello
|
|
||||||
hello
|
|
||||||
hello
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/01 12:15:50 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_WORD (TK_N_WORD | TK_Q_WORD | TK_DQ_WORD)
|
||||||
# define TK_REDIR (0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20)
|
# define TK_REDIR (0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20)
|
||||||
# define TK_NON_FREEABLE (TK_PAREN_OPEN | TK_PAREN_CLOSE | TK_BQUOTE)
|
# 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
|
enum e_lexstate
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,9 @@
|
||||||
while [ 1 ]
|
while [ 1 ]
|
||||||
|
do while pwd
|
||||||
do
|
do
|
||||||
while pwd
|
while ls
|
||||||
do
|
do
|
||||||
while pwd
|
echo hello
|
||||||
do
|
|
||||||
while pwd
|
|
||||||
do
|
|
||||||
echo "hello"
|
|
||||||
done
|
|
||||||
done
|
|
||||||
done
|
|
||||||
while pwd
|
|
||||||
do
|
|
||||||
while pwd
|
|
||||||
do
|
|
||||||
echo "bonjour"
|
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/02 15:30:59 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/11 16:11:11 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;
|
int ret;
|
||||||
t_flag tk;
|
t_flag tk;
|
||||||
|
|
||||||
|
// token_print(*alst);
|
||||||
get_reserved_words(alst);
|
get_reserved_words(alst);
|
||||||
while ((ret = reduce_parens(alst, *str)))
|
while ((ret = reduce_parens(alst, *str)))
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/10 13:37:11 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/26 00:07:05 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,24 +15,16 @@
|
||||||
int get_reserved_words(t_list **alst)
|
int get_reserved_words(t_list **alst)
|
||||||
{
|
{
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
t_token *previous_token;
|
||||||
t_list *temp;
|
t_list *temp;
|
||||||
int i;
|
|
||||||
|
|
||||||
temp = *alst;
|
temp = *alst;
|
||||||
i = 0;
|
previous_token = NULL;
|
||||||
while (temp)
|
while (temp)
|
||||||
{
|
{
|
||||||
token = temp->content;
|
token = temp->content;
|
||||||
if (i == 0)
|
if (!previous_token || (previous_token->type & SHELL_SEP))
|
||||||
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 ((temp = temp->next))
|
|
||||||
token = temp->content;
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
if (token->type == TK_N_WORD)
|
if (token->type == TK_N_WORD)
|
||||||
{
|
{
|
||||||
if (ft_strncmp(token->data, "while", 5) == 0)
|
if (ft_strncmp(token->data, "while", 5) == 0)
|
||||||
|
|
@ -43,8 +35,8 @@ int get_reserved_words(t_list **alst)
|
||||||
token->type = TK_DO;
|
token->type = TK_DO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
previous_token = token;
|
||||||
temp = temp->next;
|
temp = temp->next;
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/22 23:06:34 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/26 19:26:41 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,28 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/30 16:03: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"
|
#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)
|
int parse_while(t_btree **ast, t_list **start, t_list **lst)
|
||||||
{
|
{
|
||||||
t_list *temp;
|
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_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
|
||||||
ft_parse(&(*ast)->left, start);
|
ft_parse(&(*ast)->left, start);
|
||||||
|
|
||||||
(*lst) = temp;
|
delete_all_newline(start, &temp);
|
||||||
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
|
|
||||||
temp = temp->next;
|
|
||||||
(*lst) = temp;
|
(*lst) = temp;
|
||||||
*start = temp;
|
*start = temp;
|
||||||
nest = 1;
|
nest = 1;
|
||||||
|
|
@ -46,7 +61,6 @@ int parse_while(t_btree **ast, t_list **start, t_list **lst)
|
||||||
nest--;
|
nest--;
|
||||||
if (nest == 0)
|
if (nest == 0)
|
||||||
break;
|
break;
|
||||||
DG("nest : '%d'", nest);
|
|
||||||
}
|
}
|
||||||
temp = (*lst)->next;
|
temp = (*lst)->next;
|
||||||
(*lst)->next = NULL;
|
(*lst)->next = NULL;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue