diff options
-rw-r--r-- | examples/simple.halk | 3 | ||||
-rw-r--r-- | src/lexer.c | 30 | ||||
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/util.c | 6 |
4 files changed, 12 insertions, 29 deletions
diff --git a/examples/simple.halk b/examples/simple.halk index e424ad8..5a651e1 100644 --- a/examples/simple.halk +++ b/examples/simple.halk @@ -1 +1,2 @@ -:str:var = 'Hello'; +:str:mut:var = 'Hello'; +io/fprint.stdio, var; diff --git a/src/lexer.c b/src/lexer.c index 08105dc..1f647f5 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -40,7 +40,7 @@ token_t* lexer_get_next_token(lexer_t* lexer) { if (char_can_ignore(&lexer->c)) { lexer_pass(lexer); } if (char_could_start_int(&lexer->c)) { return lexer_next_token(lexer, TOKEN_PRIM_INT); } - if (char_could_start_keyword(&lexer->c)) { return lexer_collect(lexer, token_char_kywrd, 0, 1, TOKEN_KEYWORD); } + if (char_could_start_keyword(&lexer->c)) { return lexer_collect(lexer, token_char_kywrd, 0, 0, TOKEN_KEYWORD); } switch (lexer->c) { case '\'': @@ -70,8 +70,8 @@ token_t* lexer_get_next_token(lexer_t* lexer) { case ',': return lexer_next_token(lexer, TOKEN_LIST_DELIM); break; - case ':': - return lexer_collect(lexer, token_char_colon, 1, 1, TOKEN_DEF_TAG); + case ':': + return lexer_collect(lexer, token_char_kywrd, 1, 0, TOKEN_DEF_TAG); break; case '/': return lexer_next_token(lexer, TOKEN_NAMESPACE_DELIM); @@ -118,7 +118,7 @@ char* lexer_get_c_as_string(lexer_t* lexer) { token_t* lexer_collect(lexer_t* lexer, int (*end_char)(char), int fskip, int lskip, int type) { if (fskip) { lexer_next(lexer); } - size_t len = 0; // length of collected token so far + size_t len = 0; // length of collected token so far char* token = calloc(len, sizeof(char)); token[0] = '\0'; @@ -136,27 +136,9 @@ token_t* lexer_collect(lexer_t* lexer, int (*end_char)(char), int fskip, int lsk } if (lskip) { lexer_next(lexer); } - token[len] = '\0'; // null terminate + + token[len] = '\0'; // null terminate return token_init(type, token); } -token_t* lexer_get_keyword(lexer_t* lexer) { - size_t len = 0; - char* keyword = calloc(len, sizeof(char)); - keyword[0] = '\0'; - while (char_could_split_keyword(&lexer->c)) { - char* current = lexer_get_c_as_string(lexer); - keyword = realloc( - keyword, - (len + strlen(current) * sizeof(char)) - ); - - memcpy(keyword + len, current, strlen(current) * sizeof(char)); - len += strlen(current) * sizeof(char); - free(current); - lexer_next(lexer); - } - - return token_init(TOKEN_KEYWORD, keyword); -} @@ -45,7 +45,7 @@ int main(int argc, char* argv[]) { token_t* token = NULL; while ((token = lexer_get_next_token(lexer)) != NULL) { - log_inf("token type: [%s]\ttoken value: [%s]", token_get_type(token->type), token->value); + log_inf("token type: [%s]\t\ttoken value: [%s]", token_get_type(token->type), token->value); free(token); } @@ -3,7 +3,7 @@ void die(const char* fmt, ...) { va_list ap; - fprintf(stderr, "== ERROR ==\n"); + fprintf(stderr, "[\e[31m==\e[0m] ERROR "); va_start(ap, fmt); vfprintf(stderr, fmt, ap); @@ -24,7 +24,7 @@ void die(const char* fmt, ...) { void log_inf(const char* fmt, ...) { va_list ap; - fprintf(stderr, "== "); + fprintf(stderr, "[\e[34m==\e[0m] "); va_start(ap, fmt); vfprintf(stderr, fmt, ap); @@ -43,7 +43,7 @@ void log_raw(const char* fmt, ...) { void log_war(const char* fmt, ...) { va_list ap; - fprintf(stderr, "== WARNING ==\n"); + fprintf(stderr, "[\e[33m==\e[0m] WARNING"); va_start(ap, fmt); vfprintf(stderr, fmt, ap); |