refactor(lexer): now use struct instead of static var
This commit is contained in:
parent
f38e828c0a
commit
bbb69fddca
2 changed files with 43 additions and 39 deletions
|
|
@ -3,6 +3,15 @@
|
|||
|
||||
#include <sys/types.h>
|
||||
|
||||
struct lexer_context
|
||||
{
|
||||
char *end_last_token;
|
||||
ssize_t remaining_chars;
|
||||
|
||||
struct token *last_token;
|
||||
struct token *current_token;
|
||||
};
|
||||
|
||||
enum lexing_mode
|
||||
{
|
||||
LEXER_NORMAL,
|
||||
|
|
@ -55,7 +64,7 @@ struct token
|
|||
* @brief: returns the next (newly allocated) token without consuming it.
|
||||
* if end of input is reached, returns a token of type TOKEN_EOF.
|
||||
*/
|
||||
struct token *peek_token(void);
|
||||
struct token *peek_token(struct lexer_context *ctx);
|
||||
|
||||
/*
|
||||
* @brief: returns the next (newly allocated) token and consumes it.
|
||||
|
|
@ -66,7 +75,7 @@ struct token *peek_token(void);
|
|||
* and returns NULL. This means that after peeking a token EOF
|
||||
* in the parser, there must be EXACTLY ONE call to pop_token().
|
||||
*/
|
||||
struct token *pop_token(void);
|
||||
struct token *pop_token(struct lexer_context *ctx);
|
||||
|
||||
/* @note: maybe usefull for subshells.
|
||||
*
|
||||
|
|
@ -96,6 +105,6 @@ void free_token(struct token **tok);
|
|||
*
|
||||
* @return: char* stream from which we tokenise.
|
||||
*/
|
||||
char *stream_init(void);
|
||||
char *stream_init(struct lexer_context *ctx);
|
||||
|
||||
#endif /* ! LEXER_H */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue