diff --git a/42sh/src/lexer/get_state_global.c b/42sh/src/lexer/get_state_global.c index 78530edc..bf82cf09 100644 --- a/42sh/src/lexer/get_state_global.c +++ b/42sh/src/lexer/get_state_global.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); } diff --git a/42sh/src/lexer/lexer_word.c b/42sh/src/lexer/lexer_word.c index 37d82adc..8e6dd81e 100644 --- a/42sh/src/lexer/lexer_word.c +++ b/42sh/src/lexer/lexer_word.c @@ -6,12 +6,53 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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)); } +*/ diff --git a/42sh/src/lexer/token_append.c b/42sh/src/lexer/token_append.c index 0ec12be6..75de9fb1 100644 --- a/42sh/src/lexer/token_append.c +++ b/42sh/src/lexer/token_append.c @@ -6,13 +6,12 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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) {