parsing redir + struct control doing
This commit is contained in:
parent
488d7bf800
commit
58c6491d23
5 changed files with 18 additions and 10 deletions
|
|
@ -187,6 +187,7 @@ struct s_astnode
|
||||||
int pattern;
|
int pattern;
|
||||||
int nest;
|
int nest;
|
||||||
int full;
|
int full;
|
||||||
|
int cache;
|
||||||
t_type type;
|
t_type type;
|
||||||
t_astdata data;
|
t_astdata data;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/17 16:39:05 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)
|
if (*ast)
|
||||||
{
|
{
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
if ((node->type == CMD || node->type == TK_IO_NUMBER) &&
|
if ((node->type == CMD || node->type == TK_IO_NUMBER
|
||||||
(token->type == TK_LESS || token->type == TK_GREAT
|
|| 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_GREATAND || token->type == TK_LESSAND
|
||||||
|| token->type == TK_DLESS || token->type == TK_DGREAT))
|
|| token->type == TK_DLESS || token->type == TK_DGREAT))
|
||||||
return (1);
|
return (1);
|
||||||
|
|
@ -48,7 +52,8 @@ int isdir_word(t_btree **ast, t_list **list)
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
if (token->type == TK_WORD && node->type == REDIR)
|
if (token->type == TK_WORD && node->type == REDIR)
|
||||||
{
|
{
|
||||||
node->type = CMD;
|
node->type = node->cache;
|
||||||
|
node->cache = 0;
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -91,6 +96,7 @@ int add_redir_type(t_btree **ast, t_list **lst)
|
||||||
gen_node(ast);
|
gen_node(ast);
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
|
DG("node type is :%s", read_state(node->type));
|
||||||
if (!(node->type == TK_IO_NUMBER))
|
if (!(node->type == TK_IO_NUMBER))
|
||||||
{
|
{
|
||||||
redir.n = (token->type == TK_LESS || token->type == TK_DLESS
|
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;
|
temp_heredoc->n = temp->n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
node->cache = node->type;
|
||||||
node->type = REDIR;
|
node->type = REDIR;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -399,21 +399,21 @@ int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state)
|
||||||
return (1);
|
return (1);
|
||||||
i = 0;
|
i = 0;
|
||||||
head = (*stack)->content;
|
head = (*stack)->content;
|
||||||
DG("aggregate head %s && sym %s",
|
// DG("aggregate head %s && sym %s",
|
||||||
read_state(*head), read_state(*new_sym));
|
// read_state(*head), read_state(*new_sym));
|
||||||
while (g_aggrematch[i].top)
|
while (g_aggrematch[i].top)
|
||||||
{
|
{
|
||||||
if (*new_sym == g_aggrematch[i].top
|
if (*new_sym == g_aggrematch[i].top
|
||||||
&& MATCH_STACK(*head, g_aggrematch[i].under))
|
&& 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;
|
*new_sym = g_aggrematch[i].new_sym;
|
||||||
if (g_aggrematch[i].erase_sym)
|
if (g_aggrematch[i].erase_sym)
|
||||||
{
|
{
|
||||||
pop_stack(stack, g_aggrematch[i].erase_sym);
|
pop_stack(stack, g_aggrematch[i].erase_sym);
|
||||||
head = (*stack)->content;
|
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))
|
if (eval_sym(stack, *new_sym))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1308,7 +1308,7 @@ int eval_sym(t_list **stack, t_sym new_sym)
|
||||||
if (!*stack)
|
if (!*stack)
|
||||||
return (1);
|
return (1);
|
||||||
head = (*stack)->content;
|
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;
|
i = 0;
|
||||||
while (g_stackmatch[i].top)
|
while (g_stackmatch[i].top)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser)
|
||||||
else
|
else
|
||||||
parser->state = UNDEFINED;
|
parser->state = UNDEFINED;
|
||||||
build_tree(ast, token);
|
build_tree(ast, token);
|
||||||
// btree_print(STDBUG, *ast, &ft_putast);
|
btree_print(STDBUG, *ast, &ft_putast);
|
||||||
if ((end_instruction(&parser->stack) && !(*token)->next))
|
if ((end_instruction(&parser->stack) && !(*token)->next))
|
||||||
insert_linebreak(token);
|
insert_linebreak(token);
|
||||||
else
|
else
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue