From 4c2c5a4f79db9140c4b1ac1e2a8e82a0178c137d Mon Sep 17 00:00:00 2001 From: William Bell Date: Thu, 5 Jun 2025 23:31:18 +0100 Subject: [PATCH] ignore indentation on empty lines --- src/parser/parser.c | 11 +++++++---- test.ar | 20 ++++++++++++++++++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/parser/parser.c b/src/parser/parser.c index c27e133..8c676c4 100644 --- a/src/parser/parser.c +++ b/src/parser/parser.c @@ -83,10 +83,13 @@ ParsedValue *parse_token(char *file, DArray *tokens, size_t *index, (*index)++; return NULL; case TOKEN_INDENT: - if (strlen(token->value) > 0) { - fprintf(stderr, "%s:%zu:%zu error: invalid indentation\n", file, - token->line, token->column); - exit(EXIT_FAILURE); + 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; diff --git a/test.ar b/test.ar index 9abd61f..33d3147 100644 --- a/test.ar +++ b/test.ar @@ -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") \ No newline at end of file