From 616ee4299aacea36688115c722b8a03e77f59734 Mon Sep 17 00:00:00 2001 From: c+1 Date: Wed, 3 May 2023 14:48:45 -0400 Subject: strings are the --- src/include/token.h | 1 + src/lexer.c | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/include/token.h b/src/include/token.h index 33f28f1..b923734 100644 --- a/src/include/token.h +++ b/src/include/token.h @@ -13,6 +13,7 @@ typedef struct TOKEN_STRUC { TOKEN_RBRAK, // ']' TOKEN_POUND, // '#'' TOKEN_TILDE, // '~' + TOKEN_QUOTE, // ''' TOKEN_EOF // '\0' } type; diff --git a/src/lexer.c b/src/lexer.c index fa97f3b..1f6a9d5 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -102,7 +102,21 @@ token_T* lexer_get_next_token(lexer_T* lexer) { } token_T* lexer_get_string(lexer_T* lexer) { - // while c not ", add c to token value + lexer_next(lexer); + + char* str_so_far = calloc(1, sizeof(char)); + str_so_far[0] = '\0'; + + while (lexer->c != '"') { + char* current = lexer_get_c_as_string(lexer); + str_so_far = realloc(str_so_far, (strlen(str_so_far) + strlen(current) * sizeof(char))); // give str so far some more memory + strcat(str_so_far, current); // add current to str so far + + lexer_next(lexer); + } + + lexer_next(lexer); + return token_init(TOKEN_QUOTE, str_so_far); } token_T* lexer_get_id(lexer_T* lexer) { -- cgit v1.2.3