removed lexer_lessand/greatand, some lexer norm
This commit is contained in:
parent
f65f23b10f
commit
2671bba0a4
11 changed files with 27 additions and 112 deletions
|
|
@ -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/08 23:20:20 by ariard ### ########.fr */
|
/* Updated: 2017/03/16 19:07:42 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,13 +17,11 @@
|
||||||
# include "libft.h"
|
# include "libft.h"
|
||||||
# include "types.h"
|
# include "types.h"
|
||||||
|
|
||||||
//# define TK_REDIR (0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20)
|
|
||||||
# define TK_NON_FREEABLE (TK_PAREN_OPEN | TK_PAREN_CLOSE | TK_BQUOTE)
|
|
||||||
# define RW_SEP (TK_NEWLINE | TK_AMP | TK_SEMI | TK_WHILE | TK_DONE\
|
# define RW_SEP (TK_NEWLINE | TK_AMP | TK_SEMI | TK_WHILE | TK_DONE\
|
||||||
| TK_DO | TK_IF | TK_FI | TK_THEN | TK_ELIF | TK_ELSE)
|
| TK_DO | TK_IF | TK_FI | TK_THEN | TK_ELIF | TK_ELSE)
|
||||||
enum e_lexstate
|
enum e_lexstate
|
||||||
{
|
{
|
||||||
DEFAULT, //#define DEFAULT 0
|
DEFAULT,
|
||||||
PAREN,
|
PAREN,
|
||||||
HEREDOC,
|
HEREDOC,
|
||||||
NEWLINE,
|
NEWLINE,
|
||||||
|
|
@ -33,8 +31,6 @@ enum e_lexstate
|
||||||
NUMBER,
|
NUMBER,
|
||||||
LESS,
|
LESS,
|
||||||
GREAT,
|
GREAT,
|
||||||
LESSAND,
|
|
||||||
GREATAND,
|
|
||||||
QUOTE,
|
QUOTE,
|
||||||
DQUOTE,
|
DQUOTE,
|
||||||
BQUOTE,
|
BQUOTE,
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */
|
/* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/16 18:45:51 by jhalford ### ########.fr */
|
/* Updated: 2017/03/16 18:51:31 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */
|
/* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/15 18:06:06 by jhalford ### ########.fr */
|
/* Updated: 2017/03/16 19:06:25 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -35,11 +35,6 @@ int process_redirect(t_process *p)
|
||||||
while (redirs)
|
while (redirs)
|
||||||
{
|
{
|
||||||
redir = redirs->content;
|
redir = redirs->content;
|
||||||
/* DG("redirs content : %p", redirs->content); */
|
|
||||||
DG("redir @ %p", redir);
|
|
||||||
DG("redir.type [%li]", redir->type);
|
|
||||||
DG("redir.word [%s]", redir->word);
|
|
||||||
DG("redir.n [%i]", redir->n);
|
|
||||||
if (redir->n > 9)
|
if (redir->n > 9)
|
||||||
return (bad_fd(redir->n));
|
return (bad_fd(redir->n));
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
@ -55,7 +50,6 @@ int process_redirect(t_process *p)
|
||||||
}
|
}
|
||||||
redirs = redirs->next;
|
redirs = redirs->next;
|
||||||
}
|
}
|
||||||
/* DG("redirecting [%i:%i] [%i]", p->fdin, p->fdout, p->to_close); */
|
|
||||||
if (p->fdin != STDIN)
|
if (p->fdin != STDIN)
|
||||||
dup2_close(p->fdin, STDIN);
|
dup2_close(p->fdin, STDIN);
|
||||||
if (p->fdout != STDOUT)
|
if (p->fdout != STDOUT)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/06 22:12:31 by jhalford #+# #+# */
|
/* Created: 2017/02/06 22:12:31 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/15 17:49:18 by jhalford ### ########.fr */
|
/* Updated: 2017/03/16 19:07:41 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/03 12:06:35 by jhalford #+# #+# */
|
/* Created: 2016/12/03 12:06:35 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/10 13:11:30 by jhalford ### ########.fr */
|
/* Updated: 2017/03/16 19:01:02 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -19,21 +19,17 @@ int lexer_great(t_list **alst, t_lexer *lexer)
|
||||||
token = (*alst)->content;
|
token = (*alst)->content;
|
||||||
if (token->type)
|
if (token->type)
|
||||||
return (lexer_lex(&(*alst)->next, lexer));
|
return (lexer_lex(&(*alst)->next, lexer));
|
||||||
token_append(token, lexer, 0, 0);
|
|
||||||
lexer->pos++;
|
lexer->pos++;
|
||||||
if (lexer->str[lexer->pos] == '&')
|
if (lexer->str[lexer->pos] == '&')
|
||||||
{
|
{
|
||||||
DG("lex greatand");
|
|
||||||
token->type = TK_GREATAND;
|
token->type = TK_GREATAND;
|
||||||
token_append(token, lexer, 0, 0);
|
|
||||||
lexer->pos++;
|
lexer->pos++;
|
||||||
return (lexer_greatand(alst, lexer));
|
lexer->state = DEFAULT;
|
||||||
|
return (lexer_lex(&(*alst)->next, lexer));
|
||||||
}
|
}
|
||||||
if (lexer->str[lexer->pos] == '>')
|
if (lexer->str[lexer->pos] == '>')
|
||||||
{
|
{
|
||||||
DG("lex great");
|
|
||||||
token->type = TK_DGREAT;
|
token->type = TK_DGREAT;
|
||||||
token_append(token, lexer, 0, 0);
|
|
||||||
lexer->pos++;
|
lexer->pos++;
|
||||||
lexer->state = DEFAULT;
|
lexer->state = DEFAULT;
|
||||||
return (lexer_lex(&(*alst)->next, lexer));
|
return (lexer_lex(&(*alst)->next, lexer));
|
||||||
|
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* lexer_greatand.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/12/03 11:56:58 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2017/03/10 13:45:47 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "minishell.h"
|
|
||||||
|
|
||||||
int lexer_greatand(t_list **alst, t_lexer *lexer)
|
|
||||||
{
|
|
||||||
t_token *token;
|
|
||||||
|
|
||||||
token = (*alst)->content;
|
|
||||||
token->type = TK_GREATAND;
|
|
||||||
lexer->state = DEFAULT;
|
|
||||||
return (lexer_lex(&(*alst)->next, lexer));
|
|
||||||
}
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/03 12:06:53 by jhalford #+# #+# */
|
/* Created: 2016/12/03 12:06:53 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/10 13:11:27 by jhalford ### ########.fr */
|
/* Updated: 2017/03/16 19:00:51 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -24,7 +24,8 @@ int lexer_less(t_list **alst, t_lexer *lexer)
|
||||||
{
|
{
|
||||||
token->type = TK_LESSAND;
|
token->type = TK_LESSAND;
|
||||||
lexer->pos++;
|
lexer->pos++;
|
||||||
return (lexer_lessand(alst, lexer));
|
lexer->state = DEFAULT;
|
||||||
|
return (lexer_lex(&(*alst)->next, lexer));
|
||||||
}
|
}
|
||||||
if (lexer->str[lexer->pos] == '<')
|
if (lexer->str[lexer->pos] == '<')
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* lexer_lessand.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/12/03 11:58:51 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2017/03/15 17:48:34 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "minishell.h"
|
|
||||||
|
|
||||||
int lexer_lessand(t_list **alst, t_lexer *lexer)
|
|
||||||
{
|
|
||||||
t_token *token;
|
|
||||||
|
|
||||||
token = (*alst)->content;
|
|
||||||
token->type = TK_LESSAND;
|
|
||||||
lexer->state = DEFAULT;
|
|
||||||
return (lexer_lex(&(*alst)->next, lexer));
|
|
||||||
/* if (ft_isdigit(lexer->str[lexer->pos]))
|
|
||||||
{
|
|
||||||
token_append(token, lexer, 0, 0);
|
|
||||||
lexer->pos++;
|
|
||||||
lexer->state = DEFAULT;
|
|
||||||
return (lexer_lex(&(*alst)->next, lexer));
|
|
||||||
}
|
|
||||||
else if (lexer->str[lexer->pos] == '-')
|
|
||||||
{
|
|
||||||
token_append(token, lexer, 0, 0);
|
|
||||||
lexer->pos++;
|
|
||||||
lexer->state = DEFAULT;
|
|
||||||
return (lexer_lex(&(*alst)->next, lexer));
|
|
||||||
}
|
|
||||||
lexer->state = DEFAULT;
|
|
||||||
return (lexer_lex(alst, lexer));*/
|
|
||||||
}
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */
|
/* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/13 15:41:30 by jhalford ### ########.fr */
|
/* Updated: 2017/03/16 19:07:45 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -24,8 +24,6 @@ int (*g_lexer[])(t_list **alst, t_lexer *lexer) =
|
||||||
&lexer_number,
|
&lexer_number,
|
||||||
&lexer_less,
|
&lexer_less,
|
||||||
&lexer_great,
|
&lexer_great,
|
||||||
&lexer_lessand,
|
|
||||||
&lexer_greatand,
|
|
||||||
&lexer_quote,
|
&lexer_quote,
|
||||||
&lexer_dquote,
|
&lexer_dquote,
|
||||||
&lexer_bquote,
|
&lexer_bquote,
|
||||||
|
|
@ -57,8 +55,9 @@ int lexer_lex(t_list **alst, t_lexer *lexer)
|
||||||
return (lexer_end(alst, lexer));
|
return (lexer_end(alst, lexer));
|
||||||
if (!*alst)
|
if (!*alst)
|
||||||
{
|
{
|
||||||
token = token_init();
|
if (!(token = token_init())
|
||||||
*alst = ft_lstnew(token, sizeof(*token));
|
|| !(*alst = ft_lstnew(token, sizeof(*token))))
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
return ((*g_lexer[lexer->state])(alst, lexer));
|
return ((*g_lexer[lexer->state])(alst, lexer));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/03 12:06:45 by jhalford #+# #+# */
|
/* Created: 2016/12/03 12:06:45 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/11 20:48:19 by ariard ### ########.fr */
|
/* Updated: 2017/03/16 18:54:46 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -26,26 +26,17 @@ int lexer_number(t_list **alst, t_lexer *lexer)
|
||||||
return (lexer_lex(alst, lexer));
|
return (lexer_lex(alst, lexer));
|
||||||
}
|
}
|
||||||
else if (ft_isdigit(lexer->str[lexer->pos])
|
else if (ft_isdigit(lexer->str[lexer->pos])
|
||||||
&& ft_isdigit(lexer->str[lexer->pos + 1]))
|
&& (ft_isdigit(lexer->str[lexer->pos + 1])
|
||||||
|
|| (lexer->str[lexer->pos + 1] == '>'
|
||||||
|
|| lexer->str[lexer->pos + 1] == '<')))
|
||||||
{
|
{
|
||||||
token_append(token, lexer, 0, 0);
|
token_append(token, lexer, 0, 0);
|
||||||
lexer->pos++;
|
lexer->pos++;
|
||||||
return (lexer_number(alst, lexer));
|
return (lexer_number(alst, lexer));
|
||||||
}
|
}
|
||||||
else if (ft_isdigit(lexer->str[lexer->pos])
|
|
||||||
&& (lexer->str[lexer->pos + 1] == '>'
|
|
||||||
|| lexer->str[lexer->pos + 1] == '<'))
|
|
||||||
{
|
|
||||||
token_append(token, lexer, 0, 0);
|
|
||||||
lexer->pos++;
|
|
||||||
return (lexer_lex(alst, lexer));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
token->type = TK_WORD;
|
token->type = TK_WORD;
|
||||||
lexer->state = DEFAULT;
|
lexer->state = DEFAULT;
|
||||||
token_append(token, lexer, 0, 0);
|
token_append(token, lexer, 0, 0);
|
||||||
lexer->pos++;
|
lexer->pos++;
|
||||||
return (lexer_lex(alst, lexer));
|
return (lexer_lex(alst, lexer));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/10 15:30:25 by jhalford #+# #+# */
|
/* Created: 2016/11/10 15:30:25 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/13 15:41:35 by jhalford ### ########.fr */
|
/* Updated: 2017/03/16 19:07:52 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -16,8 +16,8 @@ t_token *token_init(void)
|
||||||
{
|
{
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
|
||||||
token = (t_token *)malloc(sizeof(t_token));
|
if (!(token = (t_token *)malloc(sizeof(t_token))))
|
||||||
//non protege
|
return (NULL);
|
||||||
token->type = 0;
|
token->type = 0;
|
||||||
token->size = 8;
|
token->size = 8;
|
||||||
token->data = ft_strnew(token->size + 1);
|
token->data = ft_strnew(token->size + 1);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue