Skip to content

Commit

Permalink
style<clang>: clang
Browse files Browse the repository at this point in the history
  • Loading branch information
ErwannLesech committed Jan 20, 2024
1 parent b8c4024 commit 4583ea9
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 59 deletions.
9 changes: 4 additions & 5 deletions src/lexer/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,11 @@ struct token parse_input_for_tok(struct lexer *lexer)
{
if (fnmatch(lex_match[i].str, word, 0) == 0 && !is_diactivated)
{
if (lex_match[i].type == TOKEN_EOF && (
lexer->curr_tok.type == TOKEN_DOUBLE_QUOTE ||
lexer->curr_tok.type == TOKEN_WORD_DOUBLE_QUOTE ||
lexer->curr_tok.type == TOKEN_VARIABLE_AND_DOUBLE_QUOTE))
if (lex_match[i].type == TOKEN_EOF
&& (lexer->curr_tok.type == TOKEN_DOUBLE_QUOTE
|| lexer->curr_tok.type == TOKEN_WORD_DOUBLE_QUOTE
|| lexer->curr_tok.type == TOKEN_VARIABLE_AND_DOUBLE_QUOTE))
{

token.type = TOKEN_ERROR;
token.data = "parse_input_for_tok - Missing closing quote.";
return token;
Expand Down
9 changes: 4 additions & 5 deletions src/lexer/lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void token_free(struct token token);
/**
* \brief Print the given token.
* \param token The token to print.
*/
*/
void print_token(struct token token);

/**
Expand Down Expand Up @@ -133,19 +133,18 @@ bool check_variable_name(struct lexer *lexer, char **word, unsigned *word_index,
* \param data The word to check
* \param index The index of the data to check
* \return true if it's a valid variable name, false otherwise
*/
*/
bool check_variable_name_simulated(const char *data, int index);

/**
* \brief Handle the backslash character in a double quote.
* \param lexer The lexer.
* \param word The word.
* \param word_index The index of the word.
*/

*/

void handle_back_slash_in_double_quote(struct lexer *lexer, char *word,
unsigned *word_index);
unsigned *word_index);

/**
* \brief Handle the dollar character.
Expand Down
3 changes: 2 additions & 1 deletion src/lexer/lexer_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ bool check_variable_name(struct lexer *lexer, char **word, unsigned *word_index,
char *curr_word = *word;
*is_in_braces = false;
// Handle variable in double quote
if (lexer->curr_tok.type == TOKEN_DOUBLE_QUOTE || lexer->curr_tok.type == TOKEN_VARIABLE_AND_DOUBLE_QUOTE)
if (lexer->curr_tok.type == TOKEN_DOUBLE_QUOTE
|| lexer->curr_tok.type == TOKEN_VARIABLE_AND_DOUBLE_QUOTE)
{
lexer->curr_tok.type = TOKEN_VARIABLE_AND_DOUBLE_QUOTE;
}
Expand Down
87 changes: 39 additions & 48 deletions src/lexer/lexer_utils2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,34 @@

void print_token(struct token token)
{
char *tokens[] = {
// Step1
[TOKEN_IF] = "TOKEN_IF",
[TOKEN_THEN] = "TOKEN_THEN",
[TOKEN_ELIF] = "TOKEN_ELIF",
[TOKEN_ELSE] = "TOKEN_ELSE",
[TOKEN_FI] = "TOKEN_FI",
[TOKEN_SEMICOLON] = "TOKEN_SEMICOLON",
[TOKEN_WORD] = "TOKEN_WORD",
[TOKEN_EOL] = "TOKEN_EOL",
[TOKEN_EOF] = "TOKEN_EOF",
[TOKEN_ERROR] = "TOKEN_ERROR",
// Step 2
[TOKEN_DONE] = "TOKEN_DONE",
[TOKEN_AND] = "TOKEN_AND",
[TOKEN_OR] = "TOKEN_OR",
[TOKEN_PIPE] = "TOKEN_PIPE",
[TOKEN_NEGATE] = "TOKEN_NEGATE",
[TOKEN_IONUMBER] = "TOKEN_IONUMBER",
[TOKEN_REDIR] = "TOKEN_REDIR",
[TOKEN_DOUBLE_QUOTE] = "TOKEN_DOUBLE_QUOTE",
[TOKEN_WORD_DOUBLE_QUOTE] = "TOKEN_WORD_DOUBLE_QUOTE",
[TOKEN_WORD_ASSIGNMENT] = "TOKEN_WORD_ASSIGNMENT",
[TOKEN_VARIABLE] = "TOKEN_VARIABLE",
char *tokens[] = { // Step1
[TOKEN_IF] = "TOKEN_IF",
[TOKEN_THEN] = "TOKEN_THEN",
[TOKEN_ELIF] = "TOKEN_ELIF",
[TOKEN_ELSE] = "TOKEN_ELSE",
[TOKEN_FI] = "TOKEN_FI",
[TOKEN_SEMICOLON] = "TOKEN_SEMICOLON",
[TOKEN_WORD] = "TOKEN_WORD",
[TOKEN_EOL] = "TOKEN_EOL",
[TOKEN_EOF] = "TOKEN_EOF",
[TOKEN_ERROR] = "TOKEN_ERROR",
// Step 2
[TOKEN_DONE] = "TOKEN_DONE",
[TOKEN_AND] = "TOKEN_AND",
[TOKEN_OR] = "TOKEN_OR",
[TOKEN_PIPE] = "TOKEN_PIPE",
[TOKEN_NEGATE] = "TOKEN_NEGATE",
[TOKEN_IONUMBER] = "TOKEN_IONUMBER",
[TOKEN_REDIR] = "TOKEN_REDIR",
[TOKEN_DOUBLE_QUOTE] = "TOKEN_DOUBLE_QUOTE",
[TOKEN_WORD_DOUBLE_QUOTE] = "TOKEN_WORD_DOUBLE_QUOTE",
[TOKEN_WORD_ASSIGNMENT] = "TOKEN_WORD_ASSIGNMENT",
[TOKEN_VARIABLE] = "TOKEN_VARIABLE",

// Internal values for lexer
[TOKEN_VARIABLE_VALUE] = "TOKEN_VARIABLE_VALUE",
[TOKEN_VARIABLE_AND_DOUBLE_QUOTE] = "TOKEN_VARIABLE_AND_DOUBLE_QUOTE"
// Internal values for lexer
[TOKEN_VARIABLE_VALUE] = "TOKEN_VARIABLE_VALUE",
[TOKEN_VARIABLE_AND_DOUBLE_QUOTE] =
"TOKEN_VARIABLE_AND_DOUBLE_QUOTE"
};
printf("Token: %s\n", tokens[token.type]);
}
Expand All @@ -41,16 +41,14 @@ bool check_variable_name_simulated(const char *data, int index)
index += 1;

// Check if it's a special variable (like $?, $*, $@, $# or $$)
if (data[index] == '?' || data[index] == '*'
|| data[index] == '@' || data[index] == '#'
|| data[index] == '$')
if (data[index] == '?' || data[index] == '*' || data[index] == '@'
|| data[index] == '#' || data[index] == '$')
{
return true;
}

// Chech if it's a special variable (like $n)
else if (data[index] >= '0'
&& data[index] <= '9')
else if (data[index] >= '0' && data[index] <= '9')
{
return true;
}
Expand All @@ -62,12 +60,9 @@ bool check_variable_name_simulated(const char *data, int index)
}

// Classic variable name
else if (data[index] == '_'
|| data[index] == '-'
|| (data[index] >= 'a'
&& data[index] <= 'z')
|| (data[index] >= 'A'
&& data[index] <= 'Z'))
else if (data[index] == '_' || data[index] == '-'
|| (data[index] >= 'a' && data[index] <= 'z')
|| (data[index] >= 'A' && data[index] <= 'Z'))
{
index += 1;
}
Expand All @@ -79,15 +74,12 @@ bool check_variable_name_simulated(const char *data, int index)

// Check the rest of the variable name break
while (data[index] == '_' || data[index] == '-'
|| (data[index] >= 'a'
&& data[index] <= 'z')
|| (data[index] >= 'A'
&& data[index] <= 'Z')
|| (data[index] >= '0'
&& data[index] <= '9'))
|| (data[index] >= 'a' && data[index] <= 'z')
|| (data[index] >= 'A' && data[index] <= 'Z')
|| (data[index] >= '0' && data[index] <= '9'))
{
index += 1;
}
}

if (is_in_braces)
{
Expand All @@ -106,10 +98,9 @@ bool check_variable_name_simulated(const char *data, int index)
}

void handle_back_slash_in_double_quote(struct lexer *lexer, char *word,
unsigned *word_index)
unsigned *word_index)
{
if (lexer->data[lexer->index] == '\"'
|| lexer->data[lexer->index] == '$'
if (lexer->data[lexer->index] == '\"' || lexer->data[lexer->index] == '$'
|| lexer->data[lexer->index] == '\\'
|| lexer->data[lexer->index] == '\n'
|| lexer->data[lexer->index] == '`')
Expand Down

0 comments on commit 4583ea9

Please sign in to comment.