aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorc+12023-05-03 14:48:45 -0400
committerc+12023-05-03 14:48:45 -0400
commit616ee4299aacea36688115c722b8a03e77f59734 (patch)
treea8ce211fc7d934796d5ceecaddd80384c810ae1d
parent0a07b51659872e4bf7f2b78fe283d7c14c46b4f2 (diff)
strings are the
-rw-r--r--src/include/token.h1
-rw-r--r--src/lexer.c16
2 files changed, 16 insertions, 1 deletions
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) {