parsing func stable, todo parsing brace_group
This commit is contained in:
parent
f70f8bd3b5
commit
bc1c16a45b
11 changed files with 49 additions and 40 deletions
|
|
@ -136,6 +136,7 @@ int iscondition(t_btree **ast, t_list **lst);
|
||||||
int iscondition_branch(t_btree **ast, t_list **lst);
|
int iscondition_branch(t_btree **ast, t_list **lst);
|
||||||
int issubshell(t_btree **ast, t_list **lst);
|
int issubshell(t_btree **ast, t_list **lst);
|
||||||
int isfunc(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 isdir(t_btree **ast);
|
||||||
int iscondition(t_btree **ast, t_list **list);
|
int iscondition(t_btree **ast, t_list **list);
|
||||||
int isdir_sep(t_btree **ast, t_list **list);
|
int isdir_sep(t_btree **ast, t_list **list);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,3 @@
|
||||||
hello() {
|
hello () (
|
||||||
yolo() {
|
echo HELLO
|
||||||
echo bonjour
|
)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,9 @@
|
||||||
int iscase(t_btree **ast, t_list **lst)
|
int iscase(t_btree **ast, t_list **lst)
|
||||||
{
|
{
|
||||||
t_astnode *node;
|
t_astnode *node;
|
||||||
// t_token *token;
|
|
||||||
|
|
||||||
(void)lst;
|
(void)lst;
|
||||||
node = NULL;
|
node = NULL;
|
||||||
// token = (*lst)->content;
|
|
||||||
if (*ast)
|
if (*ast)
|
||||||
{
|
{
|
||||||
node = (*ast)->item;
|
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
|
else if (token->type == TK_DSEMI && node->type == TK_PAREN_OPEN
|
||||||
&& node->nest == 0)
|
&& node->nest == 0)
|
||||||
return ((node->full = 1));
|
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 (0);
|
||||||
return (add_cmd(&(*ast)->right, lst));
|
return (add_cmd(&(*ast)->right, lst));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,10 @@ t_distrostree g_distrostree[] =
|
||||||
{&iscase_branch, &add_branch},
|
{&iscase_branch, &add_branch},
|
||||||
{&iscase, &add_case_cmd},
|
{&iscase, &add_case_cmd},
|
||||||
{&issubshell, &add_subshell_cmd},
|
{&issubshell, &add_subshell_cmd},
|
||||||
|
{&isfunc_name, &add_null},
|
||||||
{&isfunc, &add_func_cmd},
|
{&isfunc, &add_func_cmd},
|
||||||
{&isionumber, &add_ionumber},
|
{&isionumber, &add_ionumber},
|
||||||
{&isnull, &add_null},
|
{&isnull, &add_null},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int superflous_token(t_btree **ast, t_list **lst)
|
int superflous_token(t_btree **ast, t_list **lst)
|
||||||
|
|
@ -40,8 +40,7 @@ int superflous_token(t_btree **ast, t_list **lst)
|
||||||
if (*lst)
|
if (*lst)
|
||||||
{
|
{
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
if (token->type == TK_IN || token->type == TK_PAREN_CLOSE
|
if (token->type == TK_IN || token->type == TK_DSEMI)
|
||||||
|| token->type == TK_DSEMI)
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
|
@ -71,7 +70,6 @@ int add_cmd(t_btree **ast, t_list **lst)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
DG("add cmd");
|
|
||||||
while (i < 14)
|
while (i < 14)
|
||||||
{
|
{
|
||||||
if (g_distrostree[i].test(ast, lst) == 1)
|
if (g_distrostree[i].test(ast, lst) == 1)
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,9 @@
|
||||||
int iscondition(t_btree **ast, t_list **lst)
|
int iscondition(t_btree **ast, t_list **lst)
|
||||||
{
|
{
|
||||||
t_astnode *node;
|
t_astnode *node;
|
||||||
// t_token *token;
|
|
||||||
|
|
||||||
|
(void)lst;
|
||||||
node = NULL;
|
node = NULL;
|
||||||
// token = (*lst)->content;
|
|
||||||
if (*ast)
|
if (*ast)
|
||||||
{
|
{
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
|
|
|
||||||
|
|
@ -12,24 +12,40 @@
|
||||||
|
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
|
|
||||||
int isfunc(t_btree **ast, t_list **lst)
|
int isfunc_name(t_btree **ast, t_list **lst)
|
||||||
{
|
{
|
||||||
t_astnode *node;
|
t_astnode *node;
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
|
||||||
node = NULL;
|
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
if (*ast)
|
if (*ast)
|
||||||
{
|
{
|
||||||
node = (*ast)->item;
|
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;
|
node->type = FNAME;
|
||||||
add_one_func(ast, lst);
|
|
||||||
}
|
|
||||||
if (node->type == FNAME && node->full == 0)
|
|
||||||
return (1);
|
return (1);
|
||||||
if (isfunc(&(*ast)->right, lst) == 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);
|
return (1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
|
@ -40,23 +56,25 @@ int add_func_cmd(t_btree **ast, t_list **lst)
|
||||||
t_astnode *node;
|
t_astnode *node;
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
|
||||||
|
DG("add func cmd");
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
node = (*ast)->item;
|
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
|
if ((token->type == TK_CASE || token->type == TK_WHILE || token->type == TK_IF
|
||||||
|| token->type == TK_UNTIL || token->type == TK_FOR
|
|| token->type == TK_UNTIL || token->type == TK_FOR
|
||||||
|| token->type == SUBSHELL || token->type == TK_LBRACE)
|
|| token->type == SUBSHELL || token->type == TK_LBRACE)
|
||||||
&& node->type == FNAME)
|
&& node->type == FNAME)
|
||||||
node->nest++;
|
node->nest++;
|
||||||
if ((token->type == TK_DONE || token->type == TK_ESAC || token->type == TK_FI
|
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->type == FNAME && node->nest > 0)
|
||||||
node->nest--;
|
node->nest--;
|
||||||
if ((token->type == TK_DONE || token->type == TK_ESAC || token->type == TK_FI
|
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->type == FNAME && node->nest == 0)
|
||||||
|
{
|
||||||
node->full = 1;
|
node->full = 1;
|
||||||
|
add_one_func(ast, lst);
|
||||||
|
}
|
||||||
return (add_cmd(&(*ast)->right, 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)
|
int add_one_func(t_btree **ast, t_list **lst)
|
||||||
{
|
{
|
||||||
|
t_btree *func_ast;
|
||||||
|
|
||||||
(void)lst;
|
(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);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,9 @@
|
||||||
int isloop(t_btree **ast, t_list **lst)
|
int isloop(t_btree **ast, t_list **lst)
|
||||||
{
|
{
|
||||||
t_astnode *node;
|
t_astnode *node;
|
||||||
// t_token *token;
|
|
||||||
|
|
||||||
|
(void)lst;
|
||||||
node = NULL;
|
node = NULL;
|
||||||
// token = (*lst)->content;
|
|
||||||
DG("isloop");
|
|
||||||
if (*ast)
|
if (*ast)
|
||||||
{
|
{
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
|
|
|
||||||
|
|
@ -15,18 +15,14 @@
|
||||||
int issubshell(t_btree **ast, t_list **lst)
|
int issubshell(t_btree **ast, t_list **lst)
|
||||||
{
|
{
|
||||||
t_astnode *node;
|
t_astnode *node;
|
||||||
// t_token *token;
|
|
||||||
|
|
||||||
(void)lst;
|
(void)lst;
|
||||||
node = NULL;
|
node = NULL;
|
||||||
// token = (*lst)->content;
|
|
||||||
if (*ast)
|
if (*ast)
|
||||||
{
|
{
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
if (node->type == SUBSHELL && node->full == 0)
|
if (node->type == SUBSHELL && node->full == 0)
|
||||||
return (1);
|
return (1);
|
||||||
if (node->type == TK_LBRACE && node->full == 0)
|
|
||||||
return (1);
|
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,6 @@ t_aggrematch g_aggrematch[] =
|
||||||
|
|
||||||
//to abstract TK_ESAC
|
//to abstract TK_ESAC
|
||||||
{LINEBREAK, TK_PAREN_CLOSE, FUNC, FNAME},
|
{LINEBREAK, TK_PAREN_CLOSE, FUNC, FNAME},
|
||||||
//paren open
|
|
||||||
{LINEBREAK, COMPLETE_COMMANDS, PROGRAM, LINEBREAK},
|
{LINEBREAK, COMPLETE_COMMANDS, PROGRAM, LINEBREAK},
|
||||||
{LINEBREAK, CMD_SUPERIOR, SEPARATOR_OP, 0},
|
{LINEBREAK, CMD_SUPERIOR, SEPARATOR_OP, 0},
|
||||||
{LINEBREAK, PIPE_SEMI_SEQUENCE, PIPE_SEQUENCE, PIPE_SEMI_SEQUENCE},
|
{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, SEQUENTIAL_SEP, SEQUENTIAL_SEP, SEQUENTIAL_SEP},
|
||||||
{NEWLINE_LIST, TK_DO, TK_DO, TK_DO},
|
{NEWLINE_LIST, TK_DO, TK_DO, TK_DO},
|
||||||
{NEWLINE_LIST, TK_PAREN_CLOSE, TK_PAREN_CLOSE, TK_PAREN_CLOSE},
|
{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_IN, TK_IN, TK_IN},
|
||||||
{NEWLINE_LIST, TK_THEN, TK_THEN, TK_THEN},
|
{NEWLINE_LIST, TK_THEN, TK_THEN, TK_THEN},
|
||||||
{NEWLINE_LIST, TK_IF, TK_IF, TK_IF},
|
{NEWLINE_LIST, TK_IF, TK_IF, TK_IF},
|
||||||
|
|
|
||||||
|
|
@ -70,12 +70,9 @@ int build_tree(t_btree **ast, t_list **lst)
|
||||||
i = 0;
|
i = 0;
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
//check bug de cache case ?
|
//check bug de cache case ?
|
||||||
// cache = token->type;
|
|
||||||
if (token->type == TK_PAREN_OPEN && cache != TK_IN && cache != TK_DSEMI
|
if (token->type == TK_PAREN_OPEN && cache != TK_IN && cache != TK_DSEMI
|
||||||
&& cache != TK_WORD)
|
&& cache != TK_WORD)
|
||||||
token->type = SUBSHELL;
|
token->type = SUBSHELL;
|
||||||
if (token->type == TK_PAREN_CLOSE && cache == TK_PAREN_OPEN)
|
|
||||||
token->type = CLOSE_LIST;
|
|
||||||
while (g_treematch[i].type)
|
while (g_treematch[i].type)
|
||||||
{
|
{
|
||||||
if ((isseparator(token, cache) && g_treematch[i].type == token->type))
|
if ((isseparator(token, cache) && g_treematch[i].type == token->type))
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@
|
||||||
|
|
||||||
char *read_state(t_sym current)
|
char *read_state(t_sym current)
|
||||||
{
|
{
|
||||||
|
if (current == TERMINUS)
|
||||||
|
return ("TERMINUS");
|
||||||
if (current == SEQUENCE)
|
if (current == SEQUENCE)
|
||||||
return ("SEQUENCE");
|
return ("SEQUENCE");
|
||||||
if (current == LINEBREAK)
|
if (current == LINEBREAK)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue