aboutsummaryrefslogtreecommitdiff
path: root/src/parse/parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/parse/parse.c')
-rwxr-xr-xsrc/parse/parse.c69
1 files changed, 50 insertions, 19 deletions
diff --git a/src/parse/parse.c b/src/parse/parse.c
index 198ac65..cc4d56d 100755
--- a/src/parse/parse.c
+++ b/src/parse/parse.c
@@ -6,7 +6,7 @@
/* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/17 18:09:04 by nahaddac #+# #+# */
-/* Updated: 2020/06/18 12:48:20 by nahaddac ### ########.fr */
+/* Updated: 2020/06/19 13:28:12 by nahaddac ### ########.fr */
/* */
/* ************************************************************************** */
@@ -104,27 +104,58 @@ t_ret *parse_op(t_ftlst *input)
return ret_wrap_ast(ast, right_ret->rest);
}
-t_ret *parse_expr(t_ftlst *input)
+t_ret *parse_expr(t_ftlst *input)
{
- t_ret *tmp;
- enum e_token_tag tag;
-
- tag = ((t_token*)input->data)->tag;
- if (tag == TAG_PARENT_OPEN)
- {
- tmp = parse_op(input->next);
- input = tmp->rest;
- tag = ((t_token*)input->data)->tag;
- if (tag != TAG_PARENT_CLOSE)
- return (NULL);
- input = input->next;
- tmp->rest = input;
- return tmp;
- }
- return parse_cmd(input);
+ t_ret *tmp;
+ enum e_token_tag tag;
+ tag = ((t_token*)input->data)->tag;
+ if (tag == TAG_PARENT_OPEN)
+ {
+ tmp = parse_op(input->next);
+ input = tmp->rest;
+ tag = ((t_token*)input->data)->tag;
+ if (tag != TAG_PARENT_CLOSE)
+ return (NULL);
+ input = input->next;
+ t_ast *new_ast = ast_new(AST_PARENT);
+ new_ast = tmp->ast;
+ tmp->ast = new_ast;
+ if (tag & TAG_IS_REDIR)
+ {
+ while(input != NULL)
+ {
+ push_token(&tmp->ast->redirs, input->data);
+ if (tag & TAG_IS_STR && tag & TAG_STICK)
+ input = input->next;
+ else if (tag & TAG_IS_REDIR)
+ input = input->next;
+ else
+ break;
+ tag = ((t_token *)input->data)->tag;
+ }
+ }
+ tmp->rest = input;
+ return tmp;
+ }
+ return parse_cmd(input);
}
t_ret *parse(t_ftlst *input)
{
- return parse_op(input);
+ t_ret *ret;
+ t_ftlst *in_f;
+
+ in_f = input;
+ if (input == NULL)
+ return NULL;
+ if (!(ret = malloc(sizeof(t_ret) * 1)))
+ return (NULL);
+ ret->ast = NULL;
+ ret->rest = NULL;
+ if((ret->unexpected = error_syntax_simple(input)) != NULL)
+ printf("%s\n", ret->unexpected->content);
+ ret = parse_op(in_f);
+ ast_destroy(ret->ast);
+ ft_lstdestroy(&ret->rest, (void (*)(void*))token_destroy);
+ return (NULL);
}