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
|
||||
("bus") case $rental in
|
||||
("yolo") echo hello ;;
|
||||
("bonjour") echo yolo ;;
|
||||
esac ;;
|
||||
("yolo") echo bonjour
|
||||
esac ;;
|
||||
("van") echo yolo ;;
|
||||
("bicycle") echo hola ;;
|
||||
esac
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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