From 811f11463851a0f35835ac72ef09b65b1072de20 Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Thu, 25 Sep 2025 20:05:19 -0400 Subject: Add runtime freezing, add defun and defmacro --- src/lexer.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/lexer.c') diff --git a/src/lexer.c b/src/lexer.c index 159f73b..16f8aee 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -49,12 +49,16 @@ static bool match(pit_lexer *st, int (*f)(int)) { pit_lexer *pit_lex_file(char *path) { pit_lexer *ret = malloc(sizeof(*ret)); FILE *f = fopen(path, "r"); - if (!f) pit_panic("failed to open file for lexing: %s", path); + if (f == NULL) { + pit_panic("failed to open file for lexing: %s", path); + return NULL; + } fseek(f, 0, SEEK_END); ret->len = ftell(f); fseek(f, 0, SEEK_SET); ret->input = calloc(ret->len, sizeof(char)); fread(ret->input, sizeof(char), ret->len, f); + fclose(f); ret->start = 0; ret->end = 0; return ret; @@ -80,7 +84,13 @@ restart: return PIT_LEX_TOKEN_STRING_LITERAL; default: if (isspace(c)) goto restart; - if (isdigit(c)) { while (match(st, isdigit)); return PIT_LEX_TOKEN_INTEGER_LITERAL; } - else { while (match(st, is_symchar)); return PIT_LEX_TOKEN_SYMBOL; } + if (isdigit(c)) { + while (match(st, isdigit)) {} + return PIT_LEX_TOKEN_INTEGER_LITERAL; + } + else { + while (match(st, is_symchar)) {} + return PIT_LEX_TOKEN_SYMBOL; + } } } -- cgit v1.2.3