nesting case ok
This commit is contained in:
parent
d251474db9
commit
5f596310e1
7 changed files with 37 additions and 50 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
case $rental in
|
case $rental in
|
||||||
("bus") case $rental in
|
("bus") case $rental in
|
||||||
("yolo") echo hello ;;
|
("yolo") echo bonjour
|
||||||
("bonjour") echo yolo ;;
|
esac ;;
|
||||||
esac ;;
|
|
||||||
("van") echo yolo ;;
|
("van") echo yolo ;;
|
||||||
|
("bicycle") echo hola ;;
|
||||||
esac
|
esac
|
||||||
|
|
|
||||||
|
|
@ -9,18 +9,15 @@ int iscase(t_btree **ast, t_list **lst)
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
if (*ast)
|
if (*ast)
|
||||||
{
|
{
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
if (node->type == TK_PAREN_OPEN && node->full == 0 && node->nest > 0)
|
if ((node->type == TK_CASE || node->type == TK_PAREN_OPEN)
|
||||||
return (4);
|
&& token->type == TK_WORD && node->pattern == 0)
|
||||||
if (node->type == TK_PAREN_OPEN && node->full == 0)
|
|
||||||
return (1);
|
return (1);
|
||||||
if ((node->type == TK_CASE || node->type == TK_PAREN_OPEN
|
if ((node->type == TK_PAREN_OPEN || node->type == TK_CASE)
|
||||||
|| iscase(&(*ast)->right, lst) == 1) && token->type == TK_WORD
|
&& node->nest == 0 && token->type == TK_PAREN_OPEN)
|
||||||
&& node->pattern == 0)
|
|
||||||
return (2);
|
|
||||||
if ((node->type == TK_CASE || iscase(&(*ast)->right, lst) == 1)
|
|
||||||
&& token->type == TK_PAREN_OPEN)
|
|
||||||
return (3);
|
return (3);
|
||||||
|
if (node->type == TK_CASE || node->type == TK_PAREN_OPEN)
|
||||||
|
return (2);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
@ -32,19 +29,17 @@ int add_case_cmd(t_btree **ast, t_list **lst)
|
||||||
|
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
DG("add case cmd");
|
if (token->type == TK_CASE && (node->type == TK_PAREN_OPEN
|
||||||
if (token->type == TK_CASE && node->type == TK_PAREN_OPEN)
|
|| node->type == TK_CASE))
|
||||||
{
|
|
||||||
DG("nesting");
|
|
||||||
node->nest++;
|
node->nest++;
|
||||||
}
|
if (token->type == TK_ESAC && (node->type == TK_PAREN_OPEN
|
||||||
if (token->type == TK_ESAC && node->type == TK_PAREN_OPEN && node->nest > 0)
|
|| node->type == TK_CASE) && node->nest > 0)
|
||||||
{
|
return ((node->nest--));
|
||||||
DG("nesting less");
|
else if (token->type == TK_DSEMI && node->type == TK_PAREN_OPEN
|
||||||
node->nest--;
|
&& node->nest == 0)
|
||||||
}
|
|
||||||
else if (token->type == TK_DSEMI && node->type == TK_PAREN_OPEN)
|
|
||||||
return ((node->full = 1));
|
return ((node->full = 1));
|
||||||
|
else if (token->type == TK_ESAC)
|
||||||
|
return (0);
|
||||||
return (add_cmd(&(*ast)->right, lst));
|
return (add_cmd(&(*ast)->right, lst));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/15 20:49:15 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)
|
else if (iscondition(ast, lst) == 2)
|
||||||
return (add_branch(ast, lst));
|
return (add_branch(ast, lst));
|
||||||
else if (iscase(ast, lst) == 1)
|
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));
|
return (add_pattern(ast, lst));
|
||||||
|
else if (iscase(ast, lst) == 2)
|
||||||
|
return (add_case_cmd(ast, lst));
|
||||||
else if (iscase(ast, lst) == 3)
|
else if (iscase(ast, lst) == 3)
|
||||||
{
|
|
||||||
DG("add branc");
|
|
||||||
return (add_branch(ast, lst));
|
return (add_branch(ast, lst));
|
||||||
}
|
|
||||||
else if ((node = (*ast)->item)->type != TK_DO && node->type != TK_THEN
|
else if ((node = (*ast)->item)->type != TK_DO && node->type != TK_THEN
|
||||||
&& node->type != TK_PAREN_CLOSE && node->type != TK_ESAC)
|
&& node->type != TK_PAREN_CLOSE && node->type != TK_ESAC)
|
||||||
{
|
|
||||||
DG("return cmd : %s", read_state(node->type));
|
|
||||||
return (add_cmd(&(*ast)->right, lst));
|
return (add_cmd(&(*ast)->right, lst));
|
||||||
}
|
|
||||||
my_tab = NULL;
|
my_tab = NULL;
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
node = (*ast)->item;
|
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, token->data);
|
||||||
my_tab = ft_sstradd(my_tab, (char *)token->esc);
|
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);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/19 18:12:52 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)
|
if (*ast)
|
||||||
{
|
{
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
if ((node->type == TK_CASE || node->type == TK_PAREN_OPEN)
|
if ((node->type == TK_IF || iscondition(&(*ast)->right, lst))
|
||||||
&& node->pattern = 0 && token->type == TK_WORD)
|
&& (token->type == TK_ELIF || token->type == TK_ELSE)
|
||||||
|
&& node->nest == 0)
|
||||||
return (2);
|
return (2);
|
||||||
if (node->type == TK_CASE)
|
if ((node->type == TK_IF || node->type == TK_ELIF || node->type == TK_ELSE)
|
||||||
return (3);
|
&& node->full == 0)
|
||||||
if (node->type == TK_PAREN_OPEN && nest == 0)
|
return (1);
|
||||||
return (3);
|
if ((node->type == TK_NEWLINE || node->type == TK_SEMI
|
||||||
if (node->type == TK_PAREN_OPEN && nest > 0)
|
|| node->type == TK_AMP) && iscondition(&(*ast)->right, lst) == 1)
|
||||||
return (0);
|
return (1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/17 22:17:14 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/15 19:12:07 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));
|
return (add_loop_sep(ast, lst));
|
||||||
else if (iscondition(ast, lst) == 1)
|
else if (iscondition(ast, lst) == 1)
|
||||||
return (add_condition_sep(ast, lst));
|
return (add_condition_sep(ast, lst));
|
||||||
else if (iscase(ast, lst) == 1)
|
else if (iscase(ast, lst) == 2)
|
||||||
return (add_case_sep(ast, lst));
|
return (add_case_sep(ast, lst));
|
||||||
if (!*ast)
|
if (!*ast)
|
||||||
gen_node(ast);
|
gen_node(ast);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/15 18:32:59 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue