ignore indentation on empty lines

This commit is contained in:
2025-06-05 23:31:18 +01:00
parent 5e1cf0c8b1
commit 4c2c5a4f79
2 changed files with 25 additions and 6 deletions

View File

@@ -83,10 +83,13 @@ ParsedValue *parse_token(char *file, DArray *tokens, size_t *index,
(*index)++; (*index)++;
return NULL; return NULL;
case TOKEN_INDENT: case TOKEN_INDENT:
if (strlen(token->value) > 0) { if (strlen(token->value) > 0 && (*index + 1) < tokens->size) {
fprintf(stderr, "%s:%zu:%zu error: invalid indentation\n", file, token = darray_get(tokens, (*index) + 1);
token->line, token->column); if (token->type != TOKEN_NEW_LINE) {
exit(EXIT_FAILURE); fprintf(stderr, "%s:%zu:%zu error: invalid indentation\n", file,
token->line, token->column);
exit(EXIT_FAILURE);
}
} }
(*index)++; (*index)++;
return NULL; return NULL;

20
test.ar
View File

@@ -23,7 +23,23 @@ let a,
if (x) do
term.log("hello world")
term.log("hello world")
else term.log("bruh")
if (x) term.log("hello world")
else term.log("bruh")