Skip to content

Commit

Permalink
Changed the syntax error code and added Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
LithiumOx committed Nov 22, 2023
1 parent e8d2bc0 commit 6218872
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
4 changes: 2 additions & 2 deletions includes/enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: mdekker/jde-baai <team@codam.nl> +#+ */
/* +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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;

/**
Expand Down
33 changes: 29 additions & 4 deletions src/checker/index.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@
/* By: mdekker/jde-baai <team@codam.nl> +#+ */
/* +#+ */
/* 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 <minishell.h>

/**
* @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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 6218872

Please sign in to comment.