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

@ -10,13 +10,6 @@ struct lexer_context
char *end_previous_token;
ssize_t remaining_chars;
// usefull to detect IO numbers.
// tells us if we only lexed digits in current token.
bool only_digits;
// usefull to detect assignments, and syntax errors with '='.
int equal_count;
struct token *previous_token;
struct token *current_token;
};
@ -57,10 +50,6 @@ enum token_type
TOKEN_PIPE,
TOKEN_NEGATION,
// TODO merge into one and use the data field
// (Too difficult to handle in the parser because of firsts)
// TOKEN_REDIRECTION
//
// Redirections
TOKEN_REDIR_LEFT,
TOKEN_REDIR_RIGHT,
@ -88,18 +77,29 @@ struct token
char *data;
};
// used to give info from lexing when creating a new token.
struct token_info
{
// usefull to detect IO numbers.
// tells us if we only lexed digits in current token.
bool only_digits;
// usefull to detect assignments, and syntax errors with '='.
bool has_equal;
};
/* @return: true if a special character from the grammar was found at stream[i],
* false otherwise.
*/
bool is_special_char(char *stream, ssize_t i);
/* @brief: return a newly allocated token, with the type corresponding
* to the context given in arguments.
* to the info given in arguments.
* The data contains [size] char, starting from [begin].
*
* @return: NULL on error, a token otherwise.
*/
struct token *new_token(char *begin, ssize_t size, bool only_digits, int equal_count);
struct token *new_token(char *begin, ssize_t size, struct token_info *info);
/* @brief: frees the token given in argument
*/