diff options
author | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2022-03-24 01:04:02 +0300 |
---|---|---|
committer | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2022-03-24 01:04:02 +0300 |
commit | 5d66c96a190a396a1535c89bed4e33c2a005fe8d (patch) | |
tree | 36a681d8cf226cf30f06b2764c008077d9655dc7 /include/lexer.h | |
download | roscha-5d66c96a190a396a1535c89bed4e33c2a005fe8d.tar.gz roscha-5d66c96a190a396a1535c89bed4e33c2a005fe8d.zip |
Initial commit
Basically it works, just needs some polishing and maybe a couple of
features that I could actually use.
Also probably better docs. Not sure if it will be of use to anybody
besides me.
Diffstat (limited to 'include/lexer.h')
-rw-r--r-- | include/lexer.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/include/lexer.h b/include/lexer.h new file mode 100644 index 0000000..8491c5a --- /dev/null +++ b/include/lexer.h @@ -0,0 +1,33 @@ +#ifndef ROSCHA_LEXER_H +#define ROSCHA_LEXER_H + +#include "slice.h" +#include "token.h" + +#include <sys/types.h> +#include <stdbool.h> + +/* The lexer */ +struct lexer { + /* Source input */ + const char *input; + /* Length of input */ + size_t len; + /* The current slice of the input string that will be tokenized */ + struct slice word; + /* The current character belongs to content and should not be tokenized */ + bool in_content; + size_t line; + size_t column; +}; + +/* Allocate a new lexer with input as the source */ +struct lexer *lexer_new(const char *input); + +/* Get the next token from the lexer */ +struct token lexer_next_token(struct lexer *); + +/* Free all memory related to the lexer */ +void lexer_destroy(struct lexer *); + +#endif |