From c837b2bb4ea71cedb434260b11c9f356e8b34e2d Mon Sep 17 00:00:00 2001 From: kartofen Date: Tue, 2 Jan 2024 16:06:45 +0200 Subject: things --- src/lexer.h | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'src/lexer.h') diff --git a/src/lexer.h b/src/lexer.h index fc13f24..e928430 100644 --- a/src/lexer.h +++ b/src/lexer.h @@ -6,8 +6,12 @@ #ifndef LEXER_IDEN_CAP #define LEXER_IDEN_CAP 512 #endif +#ifndef LEXER_TOK_CAP +#define LEXER_TOK_CAP 8192 +#endif typedef struct lexer *lexer_t; +typedef struct toklist toklist_t; struct token { enum token_enum { @@ -19,38 +23,39 @@ struct token { value_t value; }; -struct lexer { - struct token *tokens; - size_t tokens_cap; +struct toklist { + struct token tokens[LEXER_TOK_CAP]; size_t ntokens; +}; - // identifier - char iden[LEXER_IDEN_CAP]; +struct lexer { + char iden[LEXER_IDEN_CAP]; // identifier size_t iden_sz; - int inside_string; + bool inside_string; + int scope_depth; }; -// allocate a lexer with a maximum number of tokens_cap tokens // returns a lexer on success and NULL on fail -lexer_t lexer_create(size_t tokens_cap); +lexer_t lexer_create(); // deallocate a lexer void lexer_destroy(lexer_t lexer); -// reset a lexer to its default state without destroying it (faster) +// reset to its default state without destroying it void lexer_reset(lexer_t lexer); +void toklist_reset(toklist_t *toklist); // self explanatory -void lexer_print_tokens(lexer_t lexer); +void toklist_print(toklist_t *toklist); // turn the given non-null-terminated string str of lenght len // into into tokens // returns 0 on success -int lexer_tokenize(lexer_t lexer, char *str, size_t len); +int lexer_tokenize(lexer_t lexer, toklist_t *toklist, char *str, size_t len); // checks whether the lexer has finished (temp buffers like iden are empty) // returns 1 on finished, 0 on not finished -int lexer_has_finished(lexer_t lexer); +bool lexer_has_finished(lexer_t lexer); #endif -- cgit v1.2.3