better historique, but do_lexer_routine no more 'a la Norme'
This commit is contained in:
parent
692323a2f9
commit
31bb8797c4
7 changed files with 74 additions and 17 deletions
|
|
@ -216,6 +216,8 @@ lexer/get_reserved_words.c\
|
||||||
lexer/get_state_global.c\
|
lexer/get_state_global.c\
|
||||||
lexer/get_state_redir.c\
|
lexer/get_state_redir.c\
|
||||||
lexer/insert_newline.c\
|
lexer/insert_newline.c\
|
||||||
|
lexer/isrw_delim.c\
|
||||||
|
lexer/keep_last_type.c\
|
||||||
lexer/lexer_backslash.c\
|
lexer/lexer_backslash.c\
|
||||||
lexer/lexer_bquote.c\
|
lexer/lexer_bquote.c\
|
||||||
lexer/lexer_curly_braces.c\
|
lexer/lexer_curly_braces.c\
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
|
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/20 15:01:01 by wescande ### ########.fr */
|
/* Updated: 2017/03/20 16:24:10 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -63,9 +63,6 @@ struct s_rvwords
|
||||||
int type;
|
int type;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* extern t_rvwords g_rvwords[]; */
|
|
||||||
/* extern int (*g_lexer[])(t_list **alst, t_lexer *lexer); */
|
|
||||||
|
|
||||||
int ft_post_tokenize(t_list **alst, char **str);
|
int ft_post_tokenize(t_list **alst, char **str);
|
||||||
|
|
||||||
t_token *token_init();
|
t_token *token_init();
|
||||||
|
|
@ -92,6 +89,8 @@ t_lexstate get_state_global(t_lexer *lexer);
|
||||||
t_lexstate get_state_redir(t_lexer *lexer);
|
t_lexstate get_state_redir(t_lexer *lexer);
|
||||||
int get_lexer_stack(t_lexer lexer);
|
int get_lexer_stack(t_lexer lexer);
|
||||||
int get_reserved_words(t_list *temp);
|
int get_reserved_words(t_list *temp);
|
||||||
|
int isrw_delim(t_type type);
|
||||||
|
int keep_last_type(t_type *type, t_list *token);
|
||||||
int insert_newline(t_list **alst);
|
int insert_newline(t_list **alst);
|
||||||
|
|
||||||
int do_lexer_routine(t_list **token, char *stream);
|
int do_lexer_routine(t_list **token, char *stream);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/19 14:24:38 by wescande #+# #+# */
|
/* Created: 2017/03/19 14:24:38 by wescande #+# #+# */
|
||||||
/* Updated: 2017/03/19 14:31:39 by wescande ### ########.fr */
|
/* Updated: 2017/03/20 16:42:26 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,15 +14,20 @@
|
||||||
|
|
||||||
int do_lexer_routine(t_list **token, char *stream)
|
int do_lexer_routine(t_list **token, char *stream)
|
||||||
{
|
{
|
||||||
t_list *ltoken;
|
t_list *ltoken;
|
||||||
t_data *data;
|
t_data *data;
|
||||||
|
static t_type last;
|
||||||
|
|
||||||
data = data_singleton();
|
data = data_singleton();
|
||||||
if (data->lexer.state == HEREDOC || data->parser.state == UNDEFINED)
|
if (data->lexer.state == HEREDOC)
|
||||||
{
|
|
||||||
ft_strappend(&data->lexer.str, (char[]){'\n', 0});
|
ft_strappend(&data->lexer.str, (char[]){'\n', 0});
|
||||||
|
if (data->parser.state == UNDEFINED && !isrw_delim(last))
|
||||||
|
ft_strappend(&data->lexer.str, (char[]){';', 0});
|
||||||
|
else if (data->parser.state == UNDEFINED && last != 0)
|
||||||
|
ft_strappend(&data->lexer.str, (char[]){' ', 0});
|
||||||
|
if (data->lexer.state == HEREDOC || (data->parser.state == UNDEFINED
|
||||||
|
&& last != 0))
|
||||||
data->lexer.pos++;
|
data->lexer.pos++;
|
||||||
}
|
|
||||||
ft_strappend(&data->lexer.str, stream);
|
ft_strappend(&data->lexer.str, stream);
|
||||||
if (get_lexer_stack(data->lexer) == BACKSLASH)
|
if (get_lexer_stack(data->lexer) == BACKSLASH)
|
||||||
pop(&data->lexer.stack);
|
pop(&data->lexer.stack);
|
||||||
|
|
@ -31,6 +36,9 @@ int do_lexer_routine(t_list **token, char *stream)
|
||||||
exit(1);
|
exit(1);
|
||||||
if (get_lexer_stack(data->lexer) > 2)
|
if (get_lexer_stack(data->lexer) > 2)
|
||||||
return (1);
|
return (1);
|
||||||
|
if (get_reserved_words(*token))
|
||||||
|
return (1);
|
||||||
|
keep_last_type(&last, *token);
|
||||||
data->lexer.state = DEFAULT;
|
data->lexer.state = DEFAULT;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,13 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/26 00:07:05 by ariard #+# #+# */
|
/* Created: 2017/01/26 00:07:05 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/17 20:19:59 by jhalford ### ########.fr */
|
/* Updated: 2017/03/20 16:01:29 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
t_rvwords g_rvwords[] =
|
static t_rvwords g_rvwords[] =
|
||||||
{
|
{
|
||||||
{"while", TK_WHILE},
|
{"while", TK_WHILE},
|
||||||
{"done", TK_DONE},
|
{"done", TK_DONE},
|
||||||
|
|
@ -37,8 +37,9 @@ static int recognization_rvwords(t_token *pv_tk, t_token *at_tk)
|
||||||
|| pv_tk->type == TK_DO || pv_tk->type == TK_IF
|
|| pv_tk->type == TK_DO || pv_tk->type == TK_IF
|
||||||
|| pv_tk->type == TK_FI || pv_tk->type == TK_THEN
|
|| pv_tk->type == TK_FI || pv_tk->type == TK_THEN
|
||||||
|| pv_tk->type == TK_ELIF || pv_tk->type == TK_ELSE
|
|| pv_tk->type == TK_ELIF || pv_tk->type == TK_ELSE
|
||||||
|| pv_tk->type == TK_DSEMI) || (pv_tk->type == TK_PAREN_CLOSE
|
|| pv_tk->type == TK_DSEMI || pv_tk->type == TK_PAREN_OPEN
|
||||||
&& at_tk->type == TK_PAREN_OPEN));
|
|| pv_tk->type == TK_LBRACE || pv_tk->type == TK_UNTIL)
|
||||||
|
|| (pv_tk->type == TK_PAREN_CLOSE && at_tk->type == TK_PAREN_OPEN));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int match_words(t_token *token)
|
static int match_words(t_token *token)
|
||||||
|
|
|
||||||
27
42sh/src/lexer/isrw_delim.c
Normal file
27
42sh/src/lexer/isrw_delim.c
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* istoken.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/20 15:54:23 by ariard #+# #+# */
|
||||||
|
/* Updated: 2017/03/20 16:38:43 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
int isrw_delim(t_type type)
|
||||||
|
{
|
||||||
|
return (type == TK_NEWLINE || type == TK_AMP
|
||||||
|
|| type == TK_SEMI || type == TK_PIPE
|
||||||
|
|| type == TK_WHILE || type == TK_UNTIL
|
||||||
|
|| type == TK_DONE || type == TK_RBRACE
|
||||||
|
|| type == TK_DO || type == TK_IF
|
||||||
|
|| type == TK_FI || type == TK_THEN
|
||||||
|
|| type == TK_ELIF || type == TK_ELSE
|
||||||
|
|| type == TK_DSEMI || type == TK_PAREN_CLOSE
|
||||||
|
|| type == TK_PAREN_OPEN || type == TK_LBRACE
|
||||||
|
|| type == 0);
|
||||||
|
}
|
||||||
22
42sh/src/lexer/keep_last_type.c
Normal file
22
42sh/src/lexer/keep_last_type.c
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* keep_last_type.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/20 16:15:34 by ariard #+# #+# */
|
||||||
|
/* Updated: 2017/03/20 16:25:06 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
int keep_last_type(t_type *last, t_list *token)
|
||||||
|
{
|
||||||
|
t_list *tmp;
|
||||||
|
|
||||||
|
if (!(tmp = ft_lstlast(token)))
|
||||||
|
return ((*last = 0));
|
||||||
|
return (*last = ((t_token *)tmp->content)->type);
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/19 14:24:14 by wescande #+# #+# */
|
/* Created: 2017/03/19 14:24:14 by wescande #+# #+# */
|
||||||
/* Updated: 2017/03/19 14:24:22 by wescande ### ########.fr */
|
/* Updated: 2017/03/20 15:47:03 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,8 +17,6 @@ int do_parser_routine(t_list **token, t_btree **ast)
|
||||||
t_data *data;
|
t_data *data;
|
||||||
|
|
||||||
data = data_singleton();
|
data = data_singleton();
|
||||||
if (get_reserved_words(*token))
|
|
||||||
return (1);
|
|
||||||
if (insert_newline(token))
|
if (insert_newline(token))
|
||||||
return (1);
|
return (1);
|
||||||
if (data->parser.state == SUCCESS && stack_init(&data->parser))
|
if (data->parser.state == SUCCESS && stack_init(&data->parser))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue