aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authors-over-42023-06-14 09:07:59 -0400
committers-over-42023-06-14 09:07:59 -0400
commit4c41e9f95d23f9ba322b2516164cd4bab0b439fa (patch)
tree588bade07dc280469a0b163b08ffa307a895de10 /src
parent4b0d75d3dbfb85e10ee70c16000c48cf0de95740 (diff)
more util changes, the lexer is stuff fucked
Diffstat (limited to 'src')
-rw-r--r--src/lexer.c30
-rw-r--r--src/main.c2
-rw-r--r--src/util.c6
3 files changed, 10 insertions, 28 deletions
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);
-}
diff --git a/src/main.c b/src/main.c
index d98b98d..915078f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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);
}
diff --git a/src/util.c b/src/util.c
index 1a7d256..256371f 100644
--- a/src/util.c
+++ b/src/util.c
@@ -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);