diff options
Diffstat (limited to 'src/lexer.c')
-rw-r--r-- | src/lexer.c | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/src/lexer.c b/src/lexer.c index d24b972..71eed79 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -15,7 +15,8 @@ static int save_empty_token(lexer_t lexer, enum token_enum type); // returns 0 on success static int save_current_identifier(lexer_t lexer); -// used for tokens that separate things, type is optional (TOKEN_TOKENS for default) +// used for tokens that separate things +// if type is TOKEN_TOKENS, then no empty token will be saved // returns 0 on success, < 0 on fail, and > 0 to skip the token (add it in iden) static int on_generic_separator(lexer_t lexer, enum token_enum type); static int on_quote(lexer_t lexer); @@ -37,12 +38,6 @@ static int try_symbol(lexer_t lexer); X(EQ('"'), on_quote(lexer)) \ X(FN(isspace), on_generic_separator(lexer, TOKEN_TOKENS)) -#define IDENTIFY_IDENTIFIER_LIST(X) \ - X(try_str) \ - X(try_int) \ - X(try_float) \ - X(try_symbol) - // X(token type, what to free, how to print on screen) #define TOKEN_TYPES_INFO(X, token) \ X(TOKEN_PARENTHS_OPEN, NULL, "(") \ @@ -54,13 +49,19 @@ static int try_symbol(lexer_t lexer); X(TOKEN_LITERAL_NUM_FLOAT, NULL, "'%f'", token->num_float) \ X(TOKEN_SYMBOL, token->symbol, "'%s'", token->symbol) +#define IDENTIFY_IDENTIFIER_LIST(X) \ + X(try_str) \ + X(try_int) \ + X(try_float) \ + X(try_symbol) + #define EQ(ch) ch == #define FN(f) f // makes an if-else chain to test the character // agains the seperator callback table #define CHECK_SEPERATOR_AND_CALLBACK(test_func, callback) \ - if(test_func(str[i])) { \ + if(test_func(str[i])) { \ callback_ret = callback; \ if(callback_ret == 0) { \ continue; \ @@ -148,15 +149,18 @@ void lexer_destroy(lexer_t lexer) static int on_quote(lexer_t lexer) { int ret = on_generic_separator(lexer, TOKEN_TOKENS); - if(ret == 0) { + if(ret <= 0) { // it either failed or worked, both not inside a string lexer->inside_string = 1; return ret; - } else if(ret > 0) { - lexer->inside_string = 0; - return 0; } - return ret; + if(save_current_identifier(lexer)) { + err("save_current_identifier: failed"); + return -1; + } + + lexer->inside_string = 0; + return 0; } static int on_dot(lexer_t lexer) |