feat(lexer): comments done + operator WIP
This commit is contained in:
parent
82f35cfa08
commit
3cdba0ad9c
3 changed files with 60 additions and 9 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef LEXER_UTILS_H
|
||||
#define LEXER_UTILS_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
|
|
@ -9,6 +10,10 @@ 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;
|
||||
|
||||
struct token *previous_token;
|
||||
struct token *current_token;
|
||||
};
|
||||
|
|
@ -39,17 +44,20 @@ enum token_type
|
|||
TOKEN_GRAVE,
|
||||
TOKEN_SEMICOLON,
|
||||
TOKEN_COMMENT,
|
||||
TOKEN_PIPE,
|
||||
TOKEN_AMPERSAND,
|
||||
TOKEN_STAR,
|
||||
TOKEN_BACKSLASH,
|
||||
TOKEN_DOLLAR,
|
||||
TOKEN_LEFT_PAREN,
|
||||
TOKEN_RIGHT_PAREN,
|
||||
TOKEN_LEFT_BRACKET,
|
||||
TOKEN_RIGHT_BRACKET,
|
||||
|
||||
// redirections
|
||||
TOKEN_LESS,
|
||||
TOKEN_GREATER,
|
||||
TOKEN_STAR,
|
||||
TOKEN_PIPE,
|
||||
TOKEN_AMPERSAND,
|
||||
TOKEN_IONUMBER,
|
||||
|
||||
// Keywords
|
||||
TOKEN_IF,
|
||||
|
|
@ -73,7 +81,7 @@ struct token
|
|||
*
|
||||
* @return: NULL on error, a token otherwise.
|
||||
*/
|
||||
struct token *new_token(char *begin, ssize_t size);
|
||||
struct token *new_token(char *begin, ssize_t size, bool only_digits);
|
||||
|
||||
/* @brief: frees the token given in argument
|
||||
*/
|
||||
|
|
@ -90,6 +98,12 @@ 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.
|
||||
*/
|
||||
void go_end_of_line(struct lexer_context *ctx);
|
||||
|
||||
/*
|
||||
* @brief: drops the current stream and asks IOB for a new one
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue