diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index 70dacce1..1e9aa6d8 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -187,6 +187,7 @@ struct s_astnode int pattern; int nest; int full; + int cache; t_type type; t_astdata data; }; diff --git a/42sh/src/parser/add_redir.c b/42sh/src/parser/add_redir.c index 45080542..e28d0837 100644 --- a/42sh/src/parser/add_redir.c +++ b/42sh/src/parser/add_redir.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/17 16:39:05 by ariard #+# #+# */ -/* Updated: 2017/03/10 13:45:42 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 19:43:10 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,8 +21,12 @@ int isdir_sep(t_btree **ast, t_list **list) if (*ast) { node = (*ast)->item; - if ((node->type == CMD || node->type == TK_IO_NUMBER) && - (token->type == TK_LESS || token->type == TK_GREAT + if ((node->type == CMD || node->type == TK_IO_NUMBER + || node->type == TK_WHILE || node->type == TK_IF + || node->type == TK_FOR || node->type == SUBSHELL + || node->type == TK_CASE || node->type == TK_RBRACE + || node->type == TK_UNTIL) + && (token->type == TK_LESS || token->type == TK_GREAT || token->type == TK_GREATAND || token->type == TK_LESSAND || token->type == TK_DLESS || token->type == TK_DGREAT)) return (1); @@ -48,7 +52,8 @@ int isdir_word(t_btree **ast, t_list **list) node = (*ast)->item; if (token->type == TK_WORD && node->type == REDIR) { - node->type = CMD; + node->type = node->cache; + node->cache = 0; return (1); } } @@ -91,6 +96,7 @@ int add_redir_type(t_btree **ast, t_list **lst) gen_node(ast); token = (*lst)->content; node = (*ast)->item; + DG("node type is :%s", read_state(node->type)); if (!(node->type == TK_IO_NUMBER)) { redir.n = (token->type == TK_LESS || token->type == TK_DLESS @@ -112,6 +118,7 @@ int add_redir_type(t_btree **ast, t_list **lst) temp_heredoc->n = temp->n; } } + node->cache = node->type; node->type = REDIR; return (0); } diff --git a/42sh/src/parser/aggregate_sym.c b/42sh/src/parser/aggregate_sym.c index 57fd12b8..90a1236b 100644 --- a/42sh/src/parser/aggregate_sym.c +++ b/42sh/src/parser/aggregate_sym.c @@ -399,21 +399,21 @@ int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state) return (1); i = 0; head = (*stack)->content; - DG("aggregate head %s && sym %s", - read_state(*head), read_state(*new_sym)); +// DG("aggregate head %s && sym %s", +// read_state(*head), read_state(*new_sym)); while (g_aggrematch[i].top) { if (*new_sym == g_aggrematch[i].top && MATCH_STACK(*head, g_aggrematch[i].under)) { - DG("MATCH : %s", read_state(g_aggrematch[i].new_sym)); +// DG("MATCH : %s", read_state(g_aggrematch[i].new_sym)); *new_sym = g_aggrematch[i].new_sym; if (g_aggrematch[i].erase_sym) { pop_stack(stack, g_aggrematch[i].erase_sym); head = (*stack)->content; - DG("stack after pop: %s", read_state(*head)); +// DG("stack after pop: %s", read_state(*head)); } if (eval_sym(stack, *new_sym)) { diff --git a/42sh/src/parser/eval_sym.c b/42sh/src/parser/eval_sym.c index 130e15bc..746b611b 100644 --- a/42sh/src/parser/eval_sym.c +++ b/42sh/src/parser/eval_sym.c @@ -1308,7 +1308,7 @@ int eval_sym(t_list **stack, t_sym new_sym) if (!*stack) return (1); head = (*stack)->content; - DG("eval head %s && sym %s", read_state(*head), read_state(new_sym)); +// DG("eval head %s && sym %s", read_state(*head), read_state(new_sym)); i = 0; while (g_stackmatch[i].top) { diff --git a/42sh/src/parser/ft_parse.c b/42sh/src/parser/ft_parse.c index db759d57..bc53467d 100644 --- a/42sh/src/parser/ft_parse.c +++ b/42sh/src/parser/ft_parse.c @@ -55,7 +55,7 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser) else parser->state = UNDEFINED; build_tree(ast, token); -// btree_print(STDBUG, *ast, &ft_putast); + btree_print(STDBUG, *ast, &ft_putast); if ((end_instruction(&parser->stack) && !(*token)->next)) insert_linebreak(token); else