feat(lexer): operators done
This commit is contained in:
parent
3cdba0ad9c
commit
1e5593fc8e
3 changed files with 111 additions and 43 deletions
|
|
@ -53,11 +53,16 @@ enum token_type
|
|||
TOKEN_RIGHT_BRACKET,
|
||||
|
||||
// redirections
|
||||
TOKEN_LESS,
|
||||
TOKEN_GREATER,
|
||||
TOKEN_PIPE,
|
||||
TOKEN_AMPERSAND,
|
||||
TOKEN_REDIR_LEFT,
|
||||
TOKEN_REDIR_RIGHT,
|
||||
TOKEN_REDIR_LEFT_RIGHT,
|
||||
TOKEN_REDIR_DOUBLE_RIGHT,
|
||||
TOKEN_REDIR_LEFT_AMP,
|
||||
TOKEN_REDIR_RIGHT_AMP,
|
||||
TOKEN_REDIR_RIGHT_PIPE,
|
||||
|
||||
TOKEN_IONUMBER,
|
||||
TOKEN_PIPE,
|
||||
|
||||
// Keywords
|
||||
TOKEN_IF,
|
||||
|
|
@ -75,8 +80,12 @@ struct token
|
|||
char *data;
|
||||
};
|
||||
|
||||
/*
|
||||
* @brief: return a newly allocated token, with the corresponding type.
|
||||
/* @return: true if a special character from the grammar was found,
|
||||
* false otherwise.
|
||||
*/
|
||||
bool is_special_char(char c);
|
||||
|
||||
/* @brief: return a newly allocated token, with the corresponding type.
|
||||
* The data contains [size] char, starting from [begin].
|
||||
*
|
||||
* @return: NULL on error, a token otherwise.
|
||||
|
|
@ -99,13 +108,22 @@ void free_token(struct token **tok);
|
|||
void stream_init(struct lexer_context *ctx);
|
||||
|
||||
/* @brief: finds the next '\n' or EOF character,
|
||||
* starting at [ctx->end_previous_token],
|
||||
* and updates the stream and remaining_chars accordingly.
|
||||
* starting at [ctx->end_previous_token],
|
||||
* and updates the stream and remaining_chars accordingly.
|
||||
*
|
||||
* @note: Daft Punk. bang.
|
||||
*/
|
||||
void go_end_of_line(struct lexer_context *ctx);
|
||||
|
||||
/*
|
||||
* @brief: drops the current stream and asks IOB for a new one
|
||||
/* @brief: this function is called when we found a special character
|
||||
* in the stream. This can either be an operator (ig '>>' or '<&' etc),
|
||||
* or a special char (ig '\' or '#' etc).
|
||||
* @return: the length of the operator/special char found (can be 1, 2 or 3).
|
||||
* -1 on error.
|
||||
*/
|
||||
ssize_t len_op_sepchar(char *stream, ssize_t i);
|
||||
|
||||
/* @brief: drops the current stream and asks IOB for a new one
|
||||
*/
|
||||
void get_next_stream(struct lexer_context *ctx);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue