diff --git a/42sh/Makefile b/42sh/Makefile index 4193e6da..c9126e3d 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -6,7 +6,7 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/02/24 18:49:55 by ariard ### ########.fr # +# Updated: 2017/02/24 20:51:33 by ariard ### ########.fr # # # # **************************************************************************** # @@ -189,6 +189,7 @@ lexer/lexer_lex.c\ lexer/lexer_newline.c\ lexer/lexer_number.c\ lexer/lexer_paren.c\ +lexer/lexer_assignement_word.c\ lexer/lexer_quote.c\ lexer/lexer_sep.c\ lexer/lexer_word.c\ diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index 61c31a2c..7602ed9f 100644 --- a/42sh/includes/lexer.h +++ b/42sh/includes/lexer.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */ -/* Updated: 2017/02/21 21:12:01 by ariard ### ########.fr */ +/* Updated: 2017/02/24 20:45:05 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,6 +40,7 @@ enum e_lexstate DQUOTE_BQUOTE, BACKSLASH, PAREN, + ASSIGNEMENT_WORD, // VAR, // SPECIAL, COMMENT, @@ -111,6 +112,7 @@ int lexer_dquote(t_list **alst, t_lexer *lexer); int lexer_bquote(t_list **alst, t_lexer *lexer); int lexer_backslash(t_list **alst, t_lexer *lexer); int lexer_paren(t_list **alst, t_lexer *lexer); +int lexer_assignement_word(t_list **alst, t_lexer *lexer); int lexer_comment(t_list **alst, t_lexer *lexer); int lexer_end(t_list **alst, t_lexer *lexer); diff --git a/42sh/sample/assignement/var_01.sh b/42sh/sample/assignement/var_01.sh new file mode 100644 index 00000000..d77e8f12 --- /dev/null +++ b/42sh/sample/assignement/var_01.sh @@ -0,0 +1 @@ +HELLO=WORLD diff --git a/42sh/sample/func/func01.sh b/42sh/sample/func/func01.sh new file mode 100644 index 00000000..579f9b0f --- /dev/null +++ b/42sh/sample/func/func01.sh @@ -0,0 +1,4 @@ +hello() { + ls | cat + pwd ; cd +} diff --git a/42sh/src/lexer/get_state_global.c b/42sh/src/lexer/get_state_global.c index 41ae160e..72886e5c 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/20 20:48:53 by ariard ### ########.fr */ +/* Updated: 2017/02/24 20:45:37 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,6 +33,8 @@ t_lexstate get_state_global(t_lexer *lexer) return (BQUOTE); else if (c == '(' || c == ')') return (PAREN); + else if (c == '=') + return (ASSIGNEMENT_WORD); else if (c == 0) return (END); return (0); diff --git a/42sh/src/lexer/get_state_redir.c b/42sh/src/lexer/get_state_redir.c index 7b6acd31..6ea22d94 100644 --- a/42sh/src/lexer/get_state_redir.c +++ b/42sh/src/lexer/get_state_redir.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 20:37:28 by jhalford #+# #+# */ -/* Updated: 2017/02/09 20:39:11 by jhalford ### ########.fr */ +/* Updated: 2017/02/24 20:44:40 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_assignement_word.c b/42sh/src/lexer/lexer_assignement_word.c new file mode 100644 index 00000000..70429bed --- /dev/null +++ b/42sh/src/lexer/lexer_assignement_word.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* lexer_assignement_word.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/02/24 20:28:13 by ariard #+# #+# */ +/* Updated: 2017/02/24 21:00:13 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "lexer.h" + +int lexer_assignement_word(t_list **alst, t_lexer *lexer) +{ + t_token *token; + char c; + + token = (*alst)->content; + if (token->type != TK_WORD && token->type != TK_ASSIGNEMENT_WORD) + { + token_append(token, lexer, 0, 0); + lexer->pos++; + return (lexer_lex(alst, lexer)); + } + token->type = TK_ASSIGNEMENT_WORD; + token_append(token, lexer, 0, 0); + lexer->pos++; + c = lexer->str[lexer->pos]; + if ((lexer->state = get_state_global(lexer))) + return (lexer_lex(alst, lexer)); + if ((lexer->state = get_state_redir(lexer))) + return (lexer_lex(alst, lexer)); + lexer->state = ft_isdigit(c) ? NUMBER : ASSIGNEMENT_WORD; + return(lexer_lex(alst, lexer)); +} diff --git a/42sh/src/lexer/lexer_default.c b/42sh/src/lexer/lexer_default.c index 200bdec0..f1781eed 100644 --- a/42sh/src/lexer/lexer_default.c +++ b/42sh/src/lexer/lexer_default.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 18:36:21 by jhalford #+# #+# */ -/* Updated: 2017/02/21 22:40:44 by ariard ### ########.fr */ +/* Updated: 2017/02/24 20:43:56 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_lex.c b/42sh/src/lexer/lexer_lex.c index 222b5616..0bb7ebca 100644 --- a/42sh/src/lexer/lexer_lex.c +++ b/42sh/src/lexer/lexer_lex.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */ -/* Updated: 2017/02/21 22:44:37 by ariard ### ########.fr */ +/* Updated: 2017/02/24 20:51:04 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,6 +31,7 @@ int (*g_lexer[])(t_list **alst, t_lexer *lexer) = &lexer_bquote, &lexer_backslash, &lexer_paren, + &lexer_assignement_word, &lexer_comment, &lexer_end, }; diff --git a/42sh/src/lexer/lexer_word.c b/42sh/src/lexer/lexer_word.c index f8c7ea6b..910be7b8 100644 --- a/42sh/src/lexer/lexer_word.c +++ b/42sh/src/lexer/lexer_word.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */ -/* Updated: 2017/02/20 20:54:32 by ariard ### ########.fr */ +/* Updated: 2017/02/24 21:00:15 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/token_append.c b/42sh/src/lexer/token_append.c index 6d83ee13..0ec12be6 100644 --- a/42sh/src/lexer/token_append.c +++ b/42sh/src/lexer/token_append.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/11 17:18:42 by jhalford #+# #+# */ -/* Updated: 2017/02/21 21:34:55 by ariard ### ########.fr */ +/* Updated: 2017/02/24 20:33:59 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/ft_putast.c b/42sh/src/main/ft_putast.c index 65e550aa..134e3370 100644 --- a/42sh/src/main/ft_putast.c +++ b/42sh/src/main/ft_putast.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 18:18:04 by jhalford #+# #+# */ -/* Updated: 2017/02/24 19:06:19 by ariard ### ########.fr */ +/* Updated: 2017/02/24 20:59:07 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,8 @@ char *ft_putast(void *nodein) { t_astnode *node; node = nodein; + if (node->type == TK_ASSIGNEMENT_WORD) + return ("ASSIGNEMENT_WORD"); if (node->type == SUBSHELL) return ("SUBSHELL"); if (node->type == TK_NAME) diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 032b4529..bfe103c2 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ -/* Updated: 2017/02/24 18:39:09 by ariard ### ########.fr */ +/* Updated: 2017/02/24 20:58:33 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_cmd.c b/42sh/src/parser/add_cmd.c index 489eb52b..b1843f82 100644 --- a/42sh/src/parser/add_cmd.c +++ b/42sh/src/parser/add_cmd.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 20:49:15 by ariard #+# #+# */ -/* Updated: 2017/02/24 19:31:18 by ariard ### ########.fr */ +/* Updated: 2017/02/24 19:40:07 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_sep.c b/42sh/src/parser/add_sep.c index 4fef29e4..5a084a01 100644 --- a/42sh/src/parser/add_sep.c +++ b/42sh/src/parser/add_sep.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 19:12:07 by ariard #+# #+# */ -/* Updated: 2017/02/24 18:54:09 by ariard ### ########.fr */ +/* Updated: 2017/02/24 19:40:12 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/build_tree.c b/42sh/src/parser/build_tree.c index 805dd403..78c77692 100644 --- a/42sh/src/parser/build_tree.c +++ b/42sh/src/parser/build_tree.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 18:32:59 by ariard #+# #+# */ -/* Updated: 2017/02/24 19:27:32 by ariard ### ########.fr */ +/* Updated: 2017/02/24 20:59:49 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,6 +38,7 @@ t_treematch g_treematch[] = {TK_PAREN_OPEN, &add_cmd}, {TK_PAREN_CLOSE, &add_cmd}, {TK_FOR, &add_cmd}, + {TK_ASSIGNEMENT_WORD, &add_cmd}, {SUBSHELL, &add_cmd}, {0, NULL}, }; diff --git a/42sh/src/parser/read_stack.c b/42sh/src/parser/read_stack.c index 3371958e..09f6ee03 100644 --- a/42sh/src/parser/read_stack.c +++ b/42sh/src/parser/read_stack.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 15:32:10 by ariard #+# #+# */ -/* Updated: 2017/02/21 20:39:13 by ariard ### ########.fr */ +/* Updated: 2017/02/24 20:57:40 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,8 @@ char *read_state(t_sym current) { + if (current == TK_ASSIGNEMENT_WORD) + return ("TK_ASSIGNEMENT_WORD"); if (current == CASE_CLAUSE) return ("CASE_CLAUSE"); if (current == CASE_LIST_NS)