rebased lexer on dev

This commit is contained in:
matteo 2026-01-17 10:43:23 +01:00
parent ccb9438d69
commit d269e82df6
2 changed files with 82 additions and 26 deletions

View file

@ -5,12 +5,29 @@
enum token_type
{
// Special characters
TOKEN_NULL = 0,
TOKEN_EOF,
TOKEN_WORD,
TOKEN_NEWLINE,
TOKEN_QUOTE,
TOKEN_DOUBLE_QUOTE,
TOKEN_GRAVE,
TOKEN_SEMICOLON,
TOKEN_COMMENT,
TOKEN_PIPE,
TOKEN_AMPERSAND,
TOKEN_BACKSLASH,
TOKEN_DOLLAR,
TOKEN_LEFT_PAREN,
TOKEN_RIGHT_PAREN,
TOKEN_LEFT_BRACKET,
TOKEN_RIGHT_BRACKET,
TOKEN_LESS,
TOKEN_GREATER,
TOKEN_STAR,
// Keywords
TOKEN_IF,
TOKEN_THEN,
TOKEN_ELSE,
@ -28,7 +45,6 @@ struct token
* @brief: returns the next (newly allocated) token without consuming it.
* if end of input is reached, enters in EOF looping node,
* returning only the same token of type TOKEN_EOF.
*
*/
struct token *peek_token(void);
@ -36,6 +52,7 @@ struct token *peek_token(void);
* @brief: returns the next (newly allocated) token and consumes it.
* if end of input is reached, returns a token of type TOKEN_EOF.
* It also frees the last token created if there was one.
*
* @warning: if the last returned token was a token EOF, it frees it
* and returns NULL. This means that after peeking a token EOF
* in the parser, there must be EXACTLY ONE call to pop_token().
@ -43,10 +60,9 @@ struct token *peek_token(void);
*/
struct token *pop_token(void);
/*
* @warning: NOT IMPLEMENTED.
/* @note: maybe usefull for subshells.
*
* @note: maybe usefull for subshells.
* @warning: NOT IMPLEMENTED.
*/
struct token *get_token_str(void);
@ -56,12 +72,10 @@ struct token *get_token_str(void);
* The data contains [size] char, starting from [begin].
*
* @return: NULL on error, a token otherwise.
*
*/
struct token *new_token(char *begin, ssize_t size);
/* @brief: frees the token given in argument
*
*/
void free_token(struct token **tok);