From 621887203606e2f04781a92c8a2a4f7031230cfa Mon Sep 17 00:00:00 2001 From: "meesdekker.xyz" Date: Wed, 22 Nov 2023 23:21:49 +0100 Subject: [PATCH] Changed the syntax error code and added Docs --- includes/enum.h | 4 ++-- src/checker/index.c | 33 +++++++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/includes/enum.h b/includes/enum.h index aaabfa8..6566224 100644 --- a/includes/enum.h +++ b/includes/enum.h @@ -6,7 +6,7 @@ /* By: mdekker/jde-baai +#+ */ /* +#+ */ /* Created: 2023/07/13 17:41:00 by mdekker/jde #+# #+# */ -/* Updated: 2023/11/20 20:59:54 by mdekker/jde ######## odam.nl */ +/* Updated: 2023/11/22 23:15:29 by mdekker/jde ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -72,7 +72,7 @@ typedef enum e_error COMMAND_NOT_FOUND = 127, NOT_VALID = 128, UNEXPECTED_EOF = 130, - SYNTAX_ERROR = 258, + SYNTAX_ERROR = 2, } t_error; /** diff --git a/src/checker/index.c b/src/checker/index.c index 0a917af..4f66fa8 100644 --- a/src/checker/index.c +++ b/src/checker/index.c @@ -6,12 +6,20 @@ /* By: mdekker/jde-baai +#+ */ /* +#+ */ /* Created: 2023/08/02 16:57:32 by mdekker/jde #+# #+# */ -/* Updated: 2023/11/21 14:48:16 by mdekker ######## odam.nl */ +/* Updated: 2023/11/22 23:20:04 by mdekker/jde ######## odam.nl */ /* */ /* ************************************************************************** */ #include +/** + * @brief Checks if there are two of the same operators next to each other + * + * @param found The found vector containing the found items + * @param data The shell struct containing the token vector + * @return true When there are no double operators + * @return false When there are double operators + */ static bool check_double_ops(t_vector *found, t_shell *data) { t_found *c_found; @@ -30,7 +38,7 @@ static bool check_double_ops(t_vector *found, t_shell *data) if (next_found->index - c_found->index == 1) if (c_token->type == n_token->type) return (set_err(SYNTAX, type_symbol(c_token->type), data), - false); + false); i++; } return (true); @@ -83,9 +91,9 @@ static bool check_ops(t_vector *found, t_shell *data) n_token = (t_token *)vec_get(&data->token_vec, c_found->index + 1); if (!n_token || n_token->type != STRING) return (set_err(SYNTAX, type_symbol(c_token->type), data), - false); + false); else if (!combine_tokens(&data->token_vec, c_found->index, - c_token->type)) + c_token->type)) return (false); else vec_apply(found, decrement_index); @@ -95,6 +103,14 @@ static bool check_ops(t_vector *found, t_shell *data) return (true); } +/** + * @brief Checks the first and last token to see if they are valid + * + * @param found The found vector containing the found items + * @param data The shell struct containing the token vector + * @return true When the first and last token are valid + * @return false When the first and last token are invalid + */ static bool check_bounds(t_vector *found, t_shell *data) { t_found *first; @@ -115,6 +131,15 @@ static bool check_bounds(t_vector *found, t_shell *data) return (true); } +/** + * @brief The main function that checks the token vector for syntax errors + * uses vec_find to find all the operators in the token vector and then + * proceeds to check if there are any syntax errors that can be found + * + * @param data The shell struct containing the token vector + * @return true When there are no syntax errors + * @return false When there are syntax errors + */ bool check_tokens(t_shell *data) { t_vector *found;