diff options
author | c+1 | 2023-05-18 13:34:01 -0400 |
---|---|---|
committer | c+1 | 2023-05-18 13:34:01 -0400 |
commit | 9f3cfd0c976a3e33a7c51407b17967614f163f05 (patch) | |
tree | f5d3b01223f2c79e2156f74a52530db5d89c5978 /src | |
parent | ca2fbad75901c661d8d5e1dea574b8074dbc56ba (diff) |
yess
Diffstat (limited to 'src')
-rw-r--r-- | src/lexer.c | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/lexer.c b/src/lexer.c index 2b94fea..7436fdf 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -9,6 +9,11 @@ #include "include/token.h" +// TODO: +// lexer_valid(lexer) -> bool +// whether at EOF, already defined just make it cleaner + + lexer_t* lexer_init(char* content) { lexer_t* lexer = calloc(1, sizeof(struct LEXER_STRUC)); @@ -27,26 +32,16 @@ void lexer_next(lexer_t* lexer) { } void lexer_pass(lexer_t* lexer) { - while ( - lexer->c == ' ' || - lexer->c == '\t' || - lexer->c == '\n') { + while (char_can_ignore(&lexer->c)) { lexer_next(lexer); } } token_t* lexer_get_next_token(lexer_t* lexer) { while (lexer->c != '\0' && lexer->i < strlen(lexer->content)) { - if ( - lexer->c == ' ' || - lexer->c == '\t' || - lexer->c == '\n' - ) { lexer_pass(lexer); } - - if ( - isalnum(lexer->c) || - lexer->c == '_' - ) { return lexer_get_keyword(lexer); } + + if (char_can_ignore(&lexer->c)) { lexer_pass(lexer); } + if (char_could_start_keyword(&lexer->c)) { return lexer_get_keyword(lexer); } switch (lexer->c) { case '\'': |