issue #52: rewrote lexer_sep entirely

This commit is contained in:
Jack Halford 2017-03-08 12:21:13 +01:00
parent 91a8e81c45
commit 8cba9bc113
11 changed files with 22 additions and 28 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
/* Updated: 2017/03/07 21:13:31 by wescande ### ########.fr */
/* Updated: 2017/03/08 12:05:37 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 11:58:44 by jhalford #+# #+# */
/* Updated: 2017/03/05 17:08:23 by ariard ### ########.fr */
/* Updated: 2017/03/08 12:09:52 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/05 16:58:24 by jhalford #+# #+# */
/* Updated: 2017/03/05 17:29:17 by jhalford ### ########.fr */
/* Updated: 2017/03/08 12:12:40 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:06:35 by jhalford #+# #+# */
/* Updated: 2017/03/05 18:20:02 by wescande ### ########.fr */
/* Updated: 2017/03/08 12:10:46 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:06:53 by jhalford #+# #+# */
/* Updated: 2017/03/05 18:19:48 by wescande ### ########.fr */
/* Updated: 2017/03/08 12:10:38 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 11:58:51 by jhalford #+# #+# */
/* Updated: 2017/03/05 18:05:39 by wescande ### ########.fr */
/* Updated: 2017/03/08 12:12:01 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/03 17:37:15 by jhalford #+# #+# */
/* Updated: 2017/03/05 16:48:06 by ariard ### ########.fr */
/* Updated: 2017/03/08 12:14:09 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,7 +18,7 @@ int lexer_paren(t_list **alst, t_lexer *lexer)
token = (*alst)->content;
if (token->type)
lexer_lex(&(*alst)->next, lexer);
return (lexer_lex(&(*alst)->next, lexer));
if (lexer->str[lexer->pos] == '(')
{
token->type = TK_PAREN_OPEN;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/30 16:29:57 by jhalford #+# #+# */
/* Updated: 2017/03/07 20:26:36 by ariard ### ########.fr */
/* Updated: 2017/03/08 12:20:30 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,26 +19,20 @@ int lexer_sep(t_list **alst, t_lexer *lexer)
char cn;
lexer->state = DEFAULT;
if (*alst)
{
token = (*alst)->content;
if (*token->data)
return (lexer_sep(&(*alst)->next, lexer));
}
else
{
token = token_init();
*alst = ft_lstnew(token, sizeof(*token));
}
token = (*alst)->content;
if (token->type)
return (lexer_lex(&(*alst)->next, lexer));
c = lexer->str[lexer->pos];
cn = lexer->str[lexer->pos + 1];
lexer->pos++;
cn = lexer->str[lexer->pos];
if (c == '&')
token->type = cn == '&' ? TK_AND_IF : TK_AMP;
else if (c == '|')
token->type = cn == '|' ? TK_OR_IF : TK_PIPE;
token->type = (c == ';') ? TK_SEMI : token->type;
token->type = (c == ';') && (cn == ';') ? TK_DSEMI : token->type;
lexer->pos += 1 + (token->type & (TK_AND_IF | TK_OR_IF | TK_DSEMI) ? 1 : 0);
else if (c == ';')
token->type = cn == ';' ? TK_DSEMI : TK_SEMI;
if (token->type == TK_AND_IF || token->type == TK_OR_IF
|| token->type == TK_DSEMI)
lexer->pos++;
return (lexer_lex(&(*alst)->next, lexer));
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */
/* Updated: 2017/03/07 21:00:18 by wescande ### ########.fr */
/* Updated: 2017/03/08 12:10:37 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:39:01 by jhalford #+# #+# */
/* Updated: 2017/03/05 16:27:58 by jhalford ### ########.fr */
/* Updated: 2017/03/08 12:14:32 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,7 +21,7 @@ void token_print(t_list *lst)
if (lst->content)
token = lst->content;
if (token->type)
DG("token : %s data [%s]\n", read_state(token->type), token->data);
DG("token : %s data [%s]", read_state(token->type), token->data);
lst = lst->next;
}
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
/* Updated: 2017/03/07 21:53:23 by ariard ### ########.fr */
/* Updated: 2017/03/08 12:20:37 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */