aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2023-06-18 00:10:39 +0300
committerkartofen <mladenovnasko0@gmail.com>2023-06-18 00:10:39 +0300
commitf83187a830deff27ce0cdd4c175ffe2785461685 (patch)
tree2ab2b6801ce6d8f3647b7ee8b4614b7c0aeac8bb
parent1eae1ba1022059d58b7b04b0f6fa719b33b18803 (diff)
now strings properly work
-rw-r--r--files/test1.lisp1
-rw-r--r--src/lexer.c30
2 files changed, 18 insertions, 13 deletions
diff --git a/files/test1.lisp b/files/test1.lisp
index f0d6ffe..3a44599 100644
--- a/files/test1.lisp
+++ b/files/test1.lisp
@@ -1,3 +1,4 @@
(define 'a 1)
(+ a 1)
(+ a 0.1)
+"string test () . '"
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)