feat(lexer + grammar): inch les redirections ca marche

This commit is contained in:
matteo 2026-01-29 18:21:44 +01:00
parent 28749a2992
commit 25079bfebf
6 changed files with 77 additions and 46 deletions

View file

@ -146,6 +146,21 @@ static void set_token_word(struct token *tok, char *begin, ssize_t size)
}
}
/* @brief: Sets the token to an assignment_word
* Also allocates the data and fills it.
*/
static void set_token_assignment(struct token *tok, char *begin, ssize_t size)
{
if (tok->type == TOKEN_NULL && size != 0)
{
tok->type = TOKEN_ASSIGNMENT_WORD;
tok->data = calloc(size + 1, sizeof(char));
if (tok->data == NULL)
return;
strncpy(tok->data, begin, size);
}
}
/* @brief: Sets the token to an IO number
* Also allocates the data and fills it.
*/
@ -204,19 +219,23 @@ bool is_special_char(char *stream, ssize_t i)
return strchr(special_chars, c) != NULL;
}
struct token *new_token(char *begin, ssize_t size, bool only_digits)
struct token *new_token(char *begin, ssize_t size, struct token_info *info)
{
struct token *tok = calloc(1, sizeof(struct token));
if (tok == NULL)
return NULL;
if (only_digits)
if (info->only_digits)
set_token_ION(tok, begin, size);
set_token_operator(tok, begin, size);
set_token_spechar(tok, begin, size);
set_token_keyword(tok, begin, size);
set_token_word(tok, begin, size);
else if (info->has_equal)
set_token_assignment(tok, begin, size);
else
{
set_token_operator(tok, begin, size);
set_token_spechar(tok, begin, size);
set_token_keyword(tok, begin, size);
set_token_word(tok, begin, size);
}
return tok;
}