Merge branch 'pda' of https://github.com/jzck/42sh into pda

"syhcnrho witg wescnde"
This commit is contained in:
Antoine Riard 2017-03-03 17:19:49 +01:00
commit a78416ae40
3 changed files with 47 additions and 6 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 20:39:06 by jhalford #+# #+# */
/* Updated: 2017/02/24 21:39:47 by ariard ### ########.fr */
/* Updated: 2017/03/03 15:06:07 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -35,9 +35,9 @@ t_lexstate get_state_global(t_lexer *lexer)
return (PAREN);
else if (c == '{' || c == '}')
return (CURLY_BRACKETS);
else if (c == '=')
/* else if (c == '=')
return (ASSIGNEMENT_WORD);
else if (c == 0)
*/ else if (c == 0)
return (END);
return (0);
}

View file

@ -6,12 +6,53 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */
/* Updated: 2017/03/01 23:32:59 by ariard ### ########.fr */
/* Updated: 2017/03/03 16:00:13 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h"
static int word_is_assignment(t_token *token)
{
const int len = ft_strlen(token->data);
int pos = -1;
char c;
while (++pos < len)
{
if (is_char_esc(token->esc, token->data, token->data + pos))
return (0);
c = token->data[pos];
if (!ft_isalnum(c) && c != '_' && c != '-')
return (0);
}
return (1);
}
int lexer_word(t_list **alst, t_lexer *lexer)
{
t_token *token;
t_lexstate state;
token = (*alst)->content;
token->type = TK_WORD;
if ((state = get_state_global(lexer))
|| (state = get_state_redir(lexer)))
{
lexer->state = state;
return (lexer_lex(alst, lexer));
}
if (lexer->str[lexer->pos] == '=' && word_is_assignment(token))
{
lexer->state = ASSIGNEMENT_WORD;
return (lexer_lex(alst, lexer));
}
token_append(token, lexer, 0, 0);
lexer->pos++;
return (lexer_lex(alst, lexer));
}
/*
int lexer_word(t_list **alst, t_lexer *lexer)
{
t_token *token;
@ -33,3 +74,4 @@ int lexer_word(t_list **alst, t_lexer *lexer)
lexer->pos++;
return (lexer_lex(alst, lexer));
}
*/

View file

@ -6,13 +6,12 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/11 17:18:42 by jhalford #+# #+# */
/* Updated: 2017/02/24 20:33:59 by ariard ### ########.fr */
/* Updated: 2017/03/03 15:12:41 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h"
int token_append_char(t_token *token, char c,
short int esc, short int esc2)
{