diff --git a/42sh/sample/case/case.sh b/42sh/sample/case/case.sh index 90d45405..3642f40b 100644 --- a/42sh/sample/case/case.sh +++ b/42sh/sample/case/case.sh @@ -1,7 +1,7 @@ case $rental in ("bus") case $rental in - ("yolo") echo hello ;; - ("bonjour") echo yolo ;; - esac ;; + ("yolo") echo bonjour + esac ;; ("van") echo yolo ;; + ("bicycle") echo hola ;; esac diff --git a/42sh/src/parser/add_case.c b/42sh/src/parser/add_case.c index 234fd46f..ff0d1532 100644 --- a/42sh/src/parser/add_case.c +++ b/42sh/src/parser/add_case.c @@ -9,18 +9,15 @@ int iscase(t_btree **ast, t_list **lst) token = (*lst)->content; if (*ast) { - node = (*ast)->item; - if (node->type == TK_PAREN_OPEN && node->full == 0 && node->nest > 0) - return (4); - if (node->type == TK_PAREN_OPEN && node->full == 0) + node = (*ast)->item; + if ((node->type == TK_CASE || node->type == TK_PAREN_OPEN) + && token->type == TK_WORD && node->pattern == 0) return (1); - if ((node->type == TK_CASE || node->type == TK_PAREN_OPEN - || iscase(&(*ast)->right, lst) == 1) && token->type == TK_WORD - && node->pattern == 0) - return (2); - if ((node->type == TK_CASE || iscase(&(*ast)->right, lst) == 1) - && token->type == TK_PAREN_OPEN) + if ((node->type == TK_PAREN_OPEN || node->type == TK_CASE) + && node->nest == 0 && token->type == TK_PAREN_OPEN) return (3); + if (node->type == TK_CASE || node->type == TK_PAREN_OPEN) + return (2); } return (0); } @@ -32,19 +29,17 @@ int add_case_cmd(t_btree **ast, t_list **lst) token = (*lst)->content; node = (*ast)->item; - DG("add case cmd"); - if (token->type == TK_CASE && node->type == TK_PAREN_OPEN) - { - DG("nesting"); + if (token->type == TK_CASE && (node->type == TK_PAREN_OPEN + || node->type == TK_CASE)) node->nest++; - } - if (token->type == TK_ESAC && node->type == TK_PAREN_OPEN && node->nest > 0) - { - DG("nesting less"); - node->nest--; - } - else if (token->type == TK_DSEMI && node->type == TK_PAREN_OPEN) + if (token->type == TK_ESAC && (node->type == TK_PAREN_OPEN + || node->type == TK_CASE) && node->nest > 0) + return ((node->nest--)); + else if (token->type == TK_DSEMI && node->type == TK_PAREN_OPEN + && node->nest == 0) return ((node->full = 1)); + else if (token->type == TK_ESAC) + return (0); return (add_cmd(&(*ast)->right, lst)); } diff --git a/42sh/src/parser/add_cmd.c b/42sh/src/parser/add_cmd.c index 38565bea..40da190d 100644 --- a/42sh/src/parser/add_cmd.c +++ b/42sh/src/parser/add_cmd.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 20:49:15 by ariard #+# #+# */ -/* Updated: 2017/02/24 14:51:47 by ariard ### ########.fr */ +/* Updated: 2017/02/24 15:30:23 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,23 +30,14 @@ int add_cmd(t_btree **ast, t_list **lst) else if (iscondition(ast, lst) == 2) return (add_branch(ast, lst)); else if (iscase(ast, lst) == 1) - { - DG("go add cmd"); - return (add_case_cmd(ast, lst)); - } - else if (iscase(ast, lst) == 2) return (add_pattern(ast, lst)); + else if (iscase(ast, lst) == 2) + return (add_case_cmd(ast, lst)); else if (iscase(ast, lst) == 3) - { - DG("add branc"); return (add_branch(ast, lst)); - } else if ((node = (*ast)->item)->type != TK_DO && node->type != TK_THEN && node->type != TK_PAREN_CLOSE && node->type != TK_ESAC) - { - DG("return cmd : %s", read_state(node->type)); return (add_cmd(&(*ast)->right, lst)); - } my_tab = NULL; token = (*lst)->content; node = (*ast)->item; @@ -55,7 +46,7 @@ int add_cmd(t_btree **ast, t_list **lst) { my_tab = ft_sstradd(my_tab, token->data); my_tab = ft_sstradd(my_tab, (char *)token->esc); -// ft_ld_pushback(&node->data.token, my_tab); + ft_ld_pushback(&node->data.token, my_tab); } return (0); } diff --git a/42sh/src/parser/add_condition.c b/42sh/src/parser/add_condition.c index 769f4425..4c2af18c 100644 --- a/42sh/src/parser/add_condition.c +++ b/42sh/src/parser/add_condition.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/19 18:12:52 by ariard #+# #+# */ -/* Updated: 2017/02/24 14:51:05 by ariard ### ########.fr */ +/* Updated: 2017/02/24 14:53:49 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,15 +22,16 @@ int iscondition(t_btree **ast, t_list **lst) if (*ast) { node = (*ast)->item; - if ((node->type == TK_CASE || node->type == TK_PAREN_OPEN) - && node->pattern = 0 && token->type == TK_WORD) + if ((node->type == TK_IF || iscondition(&(*ast)->right, lst)) + && (token->type == TK_ELIF || token->type == TK_ELSE) + && node->nest == 0) return (2); - if (node->type == TK_CASE) - return (3); - if (node->type == TK_PAREN_OPEN && nest == 0) - return (3); - if (node->type == TK_PAREN_OPEN && nest > 0) - return (0); + if ((node->type == TK_IF || node->type == TK_ELIF || node->type == TK_ELSE) + && node->full == 0) + return (1); + if ((node->type == TK_NEWLINE || node->type == TK_SEMI + || node->type == TK_AMP) && iscondition(&(*ast)->right, lst) == 1) + return (1); } return (0); } diff --git a/42sh/src/parser/add_loop.c b/42sh/src/parser/add_loop.c index 9d892675..c830f5b4 100644 --- a/42sh/src/parser/add_loop.c +++ b/42sh/src/parser/add_loop.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/17 22:17:14 by ariard #+# #+# */ -/* Updated: 2017/02/24 14:41:20 by ariard ### ########.fr */ +/* Updated: 2017/02/24 15:08:08 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_sep.c b/42sh/src/parser/add_sep.c index faa49b14..a30ccb71 100644 --- a/42sh/src/parser/add_sep.c +++ b/42sh/src/parser/add_sep.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 19:12:07 by ariard #+# #+# */ -/* Updated: 2017/02/23 18:04:24 by ariard ### ########.fr */ +/* Updated: 2017/02/24 15:15:33 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,7 +23,7 @@ int add_sep(t_btree **ast, t_list **lst) return (add_loop_sep(ast, lst)); else if (iscondition(ast, lst) == 1) return (add_condition_sep(ast, lst)); - else if (iscase(ast, lst) == 1) + else if (iscase(ast, lst) == 2) return (add_case_sep(ast, lst)); if (!*ast) gen_node(ast); diff --git a/42sh/src/parser/build_tree.c b/42sh/src/parser/build_tree.c index 05ab6407..a0c573a7 100644 --- a/42sh/src/parser/build_tree.c +++ b/42sh/src/parser/build_tree.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 18:32:59 by ariard #+# #+# */ -/* Updated: 2017/02/23 18:03:35 by ariard ### ########.fr */ +/* Updated: 2017/02/24 15:21:16 by ariard ### ########.fr */ /* */ /* ************************************************************************** */