diff options
author | c+1 | 2023-05-15 16:29:32 -0400 |
---|---|---|
committer | c+1 | 2023-05-15 16:29:32 -0400 |
commit | 4548ab3ddaa82fb96373a4b70b4a390bf34b1124 (patch) | |
tree | 84a353b9b163b50065554a702703d15c85bb4954 /src | |
parent | 60fa02f768bb7cadef3a1878b11eff463cecaadf (diff) |
pretty colors
Diffstat (limited to 'src')
-rw-r--r-- | src/lexer.c | 15 | ||||
-rw-r--r-- | src/main.c | 3 | ||||
-rw-r--r-- | src/parser.c | 3 |
3 files changed, 14 insertions, 7 deletions
diff --git a/src/lexer.c b/src/lexer.c index 74cc298..5d334bd 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -1,11 +1,14 @@ -#include "include/lexer.h" -#include "include/token.h" #include <stdlib.h> #include <string.h> #include <ctype.h> #include <stdio.h> +#include "include/log.h" +#include "include/lexer.h" +#include "include/token.h" + + lexer_t* lexer_init(char* content) { lexer_t* lexer = calloc(1, sizeof(struct LEXER_STRUC)); @@ -121,7 +124,7 @@ token_t* lexer_get_next_token(lexer_t* lexer) { ); break; case '\0': return token_init(TOKEN_EOF, lexer_get_c_as_string(lexer)); break; default: - fputs("Unrecognized token.", stderr); + log_err("Unrecognized token"); exit(1); } } @@ -180,7 +183,7 @@ token_t* lexer_get_def_const(lexer_t* lexer) { lexer_next(lexer); return token_init(TOKEN_DEFINE_CONST, "=>"); } else { - fputs("Unknown variable state.", stderr); + log_err("Unknown variable state."); exit(1); } } @@ -193,7 +196,7 @@ token_t* lexer_get_def_var(lexer_t* lexer) { } else if (lexer_next(lexer), lexer->c == '-') { return lexer_get_def_mut(lexer); } else { - fputs("Unknown variable state.", stderr); + log_err("Unknown variable state."); exit(1); } } @@ -205,7 +208,7 @@ token_t* lexer_get_def_mut(lexer_t* lexer) { lexer_next(lexer); return token_init(TOKEN_DEFINE_MUT, "->"); } else { - fputs("Unknown variable state.", stderr); + log_err("Unknown variable state."); exit(1); } } @@ -1,6 +1,7 @@ #include <stdio.h> +#include "include/log.h" #include "include/lexer.h" #include "include/tree.h" @@ -49,5 +50,7 @@ int main(int argc, char* argv[]) { lexer_destroy(lexer); + log_inf("Lexer destroyed."); + return 0; } diff --git a/src/parser.c b/src/parser.c index a9ee6d5..2cc0d39 100644 --- a/src/parser.c +++ b/src/parser.c @@ -22,7 +22,7 @@ void parser_check_expect(parser_t* parser, int token_type) { if (parser->token->type == token_type) { parser->token = lexer_get_next_token(parser->lexer); } else { - printf("[ERRR] [%d]\n\tUnexpected token '%s' with type '%d'.", + fprintf(stderr, "[ERRR] [%d]\n\tUnexpected token '%s' with type '%d'.", parser->lexer->i, parser->token->value, parser->token->type); exit(1); @@ -96,6 +96,7 @@ tree_t* parser_parse_var_def(parser_t* parser) { parser_check_expect(parser, TOKEN_KEYWORD); // let char* var_name = parser->token->value; // set variable name parser_check_expect(parser, TOKEN_KEYWORD); // expect variable name & advance + if (parser->token->type == TOKEN_DEFINE_CONST) { // check either constant or mutable variable var_is_const = 1; parser_check_expect(parser, TOKEN_DEFINE_CONST); |