parsing func stable, todo parsing brace_group

This commit is contained in:
AntoHesse 2017-03-07 01:17:58 +01:00
parent f70f8bd3b5
commit bc1c16a45b
11 changed files with 49 additions and 40 deletions

View file

@ -136,6 +136,7 @@ int iscondition(t_btree **ast, t_list **lst);
int iscondition_branch(t_btree **ast, t_list **lst);
int issubshell(t_btree **ast, t_list **lst);
int isfunc(t_btree **ast, t_list **lst);
int isfunc_name(t_btree **ast, t_list **lst);
int isdir(t_btree **ast);
int iscondition(t_btree **ast, t_list **list);
int isdir_sep(t_btree **ast, t_list **list);

View file

@ -1,6 +1,3 @@
hello() {
yolo() {
echo bonjour
}
}
hello () (
echo HELLO
)

View file

@ -15,11 +15,9 @@
int iscase(t_btree **ast, t_list **lst)
{
t_astnode *node;
// t_token *token;
(void)lst;
node = NULL;
// token = (*lst)->content;
if (*ast)
{
node = (*ast)->item;
@ -80,7 +78,8 @@ int add_case_cmd(t_btree **ast, t_list **lst)
else if (token->type == TK_DSEMI && node->type == TK_PAREN_OPEN
&& node->nest == 0)
return ((node->full = 1));
else if (token->type == TK_ESAC)
else if ((token->type == TK_ESAC || token->type == TK_PAREN_CLOSE)
&& node->nest == 0)
return (0);
return (add_cmd(&(*ast)->right, lst));
}

View file

@ -26,10 +26,10 @@ t_distrostree g_distrostree[] =
{&iscase_branch, &add_branch},
{&iscase, &add_case_cmd},
{&issubshell, &add_subshell_cmd},
{&isfunc_name, &add_null},
{&isfunc, &add_func_cmd},
{&isionumber, &add_ionumber},
{&isnull, &add_null},
};
int superflous_token(t_btree **ast, t_list **lst)
@ -40,8 +40,7 @@ int superflous_token(t_btree **ast, t_list **lst)
if (*lst)
{
token = (*lst)->content;
if (token->type == TK_IN || token->type == TK_PAREN_CLOSE
|| token->type == TK_DSEMI)
if (token->type == TK_IN || token->type == TK_DSEMI)
return (1);
}
return (0);
@ -71,7 +70,6 @@ int add_cmd(t_btree **ast, t_list **lst)
int i;
i = 0;
DG("add cmd");
while (i < 14)
{
if (g_distrostree[i].test(ast, lst) == 1)

View file

@ -15,10 +15,9 @@
int iscondition(t_btree **ast, t_list **lst)
{
t_astnode *node;
// t_token *token;
(void)lst;
node = NULL;
// token = (*lst)->content;
if (*ast)
{
node = (*ast)->item;

View file

@ -12,25 +12,41 @@
#include "parser.h"
int isfunc(t_btree **ast, t_list **lst)
int isfunc_name(t_btree **ast, t_list **lst)
{
t_astnode *node;
t_token *token;
node = NULL;
token = (*lst)->content;
if (*ast)
{
node = (*ast)->item;
if (node->type == TK_WORD && token->type == CLOSE_LIST)
{
if (node->type == CMD && token->type == TK_PAREN_OPEN)
{
DG("add func name");
node->type = FNAME;
add_one_func(ast, lst);
}
return (1);
}
if (node->type == FNAME && token->type == TK_PAREN_CLOSE && node->nest == 0)
return (1);
}
return (0);
}
int isfunc(t_btree **ast, t_list **lst)
{
t_astnode *node;
(void)lst;
node = NULL;
if (*ast)
{
node = (*ast)->item;
if ((node->type == TK_NEWLINE || node->type == TK_SEMI
|| node->type == TK_AMP) && isfunc(&(*ast)->right, lst) == 1)
return (1);
if (node->type == FNAME && node->full == 0)
return (1);
if (isfunc(&(*ast)->right, lst) == 1)
return (1);
}
return (0);
}
@ -40,23 +56,25 @@ int add_func_cmd(t_btree **ast, t_list **lst)
t_astnode *node;
t_token *token;
DG("add func cmd");
token = (*lst)->content;
node = (*ast)->item;
if (token->type == CLOSE_LIST && node->nest == 0)
return (0);
if ((token->type == TK_CASE || token->type == TK_WHILE || token->type == TK_IF
|| token->type == TK_UNTIL || token->type == TK_FOR
|| token->type == SUBSHELL || token->type == TK_LBRACE)
&& node->type == FNAME)
node->nest++;
if ((token->type == TK_DONE || token->type == TK_ESAC || token->type == TK_FI
|| token->type == TK_RBRACE || token->type == TK_PAREN_OPEN)
|| token->type == TK_RBRACE || token->type == TK_PAREN_CLOSE)
&& node->type == FNAME && node->nest > 0)
node->nest--;
if ((token->type == TK_DONE || token->type == TK_ESAC || token->type == TK_FI
|| token->type == TK_RBRACE || token->type == TK_PAREN_OPEN)
|| token->type == TK_RBRACE || token->type == TK_PAREN_CLOSE)
&& node->type == FNAME && node->nest == 0)
{
node->full = 1;
add_one_func(ast, lst);
}
return (add_cmd(&(*ast)->right, lst));
}
@ -67,7 +85,11 @@ int add_func_sep(t_btree **ast, t_list **lst)
int add_one_func(t_btree **ast, t_list **lst)
{
t_btree *func_ast;
(void)lst;
ft_lsteadd(&data_singleton()->lst_func, ft_lstnew(ast, sizeof(*ast)));
func_ast = btree_map(*ast, &id);
ft_lsteadd(&data_singleton()->lst_func, ft_lstnew(&func_ast, sizeof(*ast)));
DG("arbre ajoute");
return (0);
}

View file

@ -15,11 +15,9 @@
int isloop(t_btree **ast, t_list **lst)
{
t_astnode *node;
// t_token *token;
(void)lst;
node = NULL;
// token = (*lst)->content;
DG("isloop");
if (*ast)
{
node = (*ast)->item;

View file

@ -15,18 +15,14 @@
int issubshell(t_btree **ast, t_list **lst)
{
t_astnode *node;
// t_token *token;
(void)lst;
node = NULL;
// token = (*lst)->content;
if (*ast)
{
node = (*ast)->item;
if (node->type == SUBSHELL && node->full == 0)
return (1);
if (node->type == TK_LBRACE && node->full == 0)
return (1);
}
return (0);
}

View file

@ -61,7 +61,6 @@ t_aggrematch g_aggrematch[] =
//to abstract TK_ESAC
{LINEBREAK, TK_PAREN_CLOSE, FUNC, FNAME},
//paren open
{LINEBREAK, COMPLETE_COMMANDS, PROGRAM, LINEBREAK},
{LINEBREAK, CMD_SUPERIOR, SEPARATOR_OP, 0},
{LINEBREAK, PIPE_SEMI_SEQUENCE, PIPE_SEQUENCE, PIPE_SEMI_SEQUENCE},
@ -72,6 +71,7 @@ t_aggrematch g_aggrematch[] =
{NEWLINE_LIST, SEQUENTIAL_SEP, SEQUENTIAL_SEP, SEQUENTIAL_SEP},
{NEWLINE_LIST, TK_DO, TK_DO, TK_DO},
{NEWLINE_LIST, TK_PAREN_CLOSE, TK_PAREN_CLOSE, TK_PAREN_CLOSE},
{NEWLINE_LIST, TK_PAREN_OPEN, TK_PAREN_OPEN, TK_PAREN_OPEN},
{NEWLINE_LIST, TK_IN, TK_IN, TK_IN},
{NEWLINE_LIST, TK_THEN, TK_THEN, TK_THEN},
{NEWLINE_LIST, TK_IF, TK_IF, TK_IF},
@ -329,7 +329,7 @@ int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state)
if (g_aggrematch[i].erase_sym)
{
if (pop_stack(stack, g_aggrematch[i].erase_sym))
return (1);
return (1);
head = (*stack)->content;
DG("stack after pop: %s", read_state(*head));
}

View file

@ -70,12 +70,9 @@ int build_tree(t_btree **ast, t_list **lst)
i = 0;
token = (*lst)->content;
//check bug de cache case ?
// cache = token->type;
if (token->type == TK_PAREN_OPEN && cache != TK_IN && cache != TK_DSEMI
&& cache != TK_WORD)
token->type = SUBSHELL;
if (token->type == TK_PAREN_CLOSE && cache == TK_PAREN_OPEN)
token->type = CLOSE_LIST;
while (g_treematch[i].type)
{
if ((isseparator(token, cache) && g_treematch[i].type == token->type))

View file

@ -14,6 +14,8 @@
char *read_state(t_sym current)
{
if (current == TERMINUS)
return ("TERMINUS");
if (current == SEQUENCE)
return ("SEQUENCE");
if (current == LINEBREAK)