summaryrefslogtreecommitdiff
path: root/src/lexer.c
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2025-09-25 20:05:19 -0400
committerLLLL Colonq <llll@colonq>2025-09-25 20:05:19 -0400
commit811f11463851a0f35835ac72ef09b65b1072de20 (patch)
tree225cee11b86af7662e6319c9864788b92be3dfb1 /src/lexer.c
parent8e79c8ac42d3fa248174120266ae0988361df212 (diff)
Add runtime freezing, add defun and defmacro
Diffstat (limited to 'src/lexer.c')
-rw-r--r--src/lexer.c16
1 files changed, 13 insertions, 3 deletions
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;
+ }
}
}