Added basic for i loops. Missing some breaking tests and more tests. Also want to add for each at some point and it_index.

This commit is contained in:
2025-08-30 22:58:51 +02:00
parent 14f8b20d5f
commit 94fc3a4dad
7 changed files with 116 additions and 2 deletions

View File

@@ -887,7 +887,36 @@ statement :: (parse_state : *Parse_State) -> *AST_Node {
}
return error_node(parse_state, "'else' without 'if'.");
}
}
} else if match(parse_state, .TOKEN_FOR) {
if check(parse_state, .TOKEN_IDENTIFIER) {
node := make_node(parse_state, .For);
source_location : Source_Range;
source_location.begin = parse_state.previous;
loop_iterator := parse_state.current;
node.token = loop_iterator;
advance(parse_state);
consume(parse_state, .TOKEN_COLON, "Expect ':' after for loop iterator.");
begin_iter := expression(parse_state);
add_child(node, begin_iter);
consume(parse_state, .TOKEN_DOTDOT, "Expect '..' after for loop iter left hand side.");
end_iter := expression(parse_state);
add_child(node, end_iter);
for_body := block(parse_state);
add_child(node, for_body);
// consume(parse_state, .TOKEN_RIGHTBRACE, "Expect '}' after for body.");
node.source_location = source_location;
return node;
}
} else {
return expression_statement(parse_state);
}