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

18
test.ar
View File

@@ -25,5 +25,21 @@ let a,
if (x) term.log("hello world")
if (x) do
term.log("hello world")
term.log("hello world")
else term.log("bruh")