Iterator grammar

This commit is contained in:
2026-05-05 17:55:37 +02:00
parent eb4cec50aa
commit ccb6654127
2 changed files with 8 additions and 1 deletions
+5
View File
@@ -68,6 +68,7 @@ statement = _{
| if_stmt | if_stmt
| while_stmt | while_stmt
| c_for_stmt | c_for_stmt
| for_stmt
| return_stmt | return_stmt
| break_stmt | break_stmt
| continue_stmt | continue_stmt
@@ -104,6 +105,10 @@ c_for_stmt = {
"for" ~ "(" ~ statement ~ expr ~ semicolon ~ statement ~ ")" ~ statement "for" ~ "(" ~ statement ~ expr ~ semicolon ~ statement ~ ")" ~ statement
} }
for_stmt = {
"for" ~ "(" ~ identifier ~ "in" ~ expr ~ ")" ~ statement
}
// ================= EXPRESSIONS ================= // ================= EXPRESSIONS =================
tuple_type = { "(" ~ (type_expr ~ ("," ~ type_expr)*)? ~ ")" } tuple_type = { "(" ~ (type_expr ~ ("," ~ type_expr)*)? ~ ")" }
path_type = { static_path ~ ("<" ~ (type_expr ~ ("," ~ type_expr)*)? ~ ">")? } path_type = { static_path ~ ("<" ~ (type_expr ~ ("," ~ type_expr)*)? ~ ">")? }
+3 -1
View File
@@ -1,5 +1,7 @@
void main() { void main() {
for (usize mut i = 0; i < 10; i = i + 1;) { let iter = vec!(1, 2, 3, 4, 5);
for (i in iter) {
println!("{i}"); println!("{i}");
} }
} }