summaryrefslogtreecommitdiff
path: root/src/parser/parser_stmt.c
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-18 01:54:52 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-18 01:54:52 +0000
commit1eed9181e082883987116224a5043b8b64a0ec95 (patch)
tree75b57956dd7c565886c613ae49e1b181caa6b661 /src/parser/parser_stmt.c
parentefb6cda22ec9ca124c22b40d1b0049c3992bbf32 (diff)
Support for '..='
Diffstat (limited to 'src/parser/parser_stmt.c')
-rw-r--r--src/parser/parser_stmt.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/parser/parser_stmt.c b/src/parser/parser_stmt.c
index ca8cd8f..bfb45d8 100644
--- a/src/parser/parser_stmt.c
+++ b/src/parser/parser_stmt.c
@@ -1555,9 +1555,20 @@ ASTNode *parse_for(ParserContext *ctx, Lexer *l)
if (in_tok.type == TOK_IDENT && strncmp(in_tok.start, "in", 2) == 0)
{
ASTNode *start_expr = parse_expression(ctx, l);
+ int is_inclusive = 0;
if (lexer_peek(l).type == TOK_DOTDOT)
{
lexer_next(l); // consume ..
+ }
+
+ else if (lexer_peek(l).type == TOK_DOTDOT_EQ)
+ {
+ is_inclusive = 1;
+ lexer_next(l); // consume ..=
+ }
+
+ if (1) // Block to keep scope for variables
+ {
ASTNode *end_expr = parse_expression(ctx, l);
ASTNode *n = ast_create(NODE_FOR_RANGE);
@@ -1566,6 +1577,7 @@ ASTNode *parse_for(ParserContext *ctx, Lexer *l)
n->for_range.var_name[var.len] = 0;
n->for_range.start = start_expr;
n->for_range.end = end_expr;
+ n->for_range.is_inclusive = is_inclusive;
if (lexer_peek(l).type == TOK_IDENT && strncmp(lexer_peek(l).start, "step", 4) == 0)
{