Improved for loop

This commit is contained in:
2026-05-07 23:43:22 +02:00
parent c7ada72029
commit 8b409f4ccf
4 changed files with 18 additions and 7 deletions
+2 -1
View File
@@ -164,7 +164,8 @@ pub enum Statement {
body: Box<Statement>,
},
For {
pattern: Identifier,
mutable: bool,
pattern: Pattern,
iterator: Expression,
body: Box<Statement>,
},
+1 -1
View File
@@ -142,7 +142,7 @@ c_for_stmt = {
}
for_stmt = {
"for" ~ "(" ~ identifier ~ "in" ~ expr ~ ")" ~ statement
"for" ~ "(" ~ mutable? ~ pattern ~ "in" ~ expr ~ ")" ~ statement
}
match_item = { pattern ~ "=>" ~ block }
+2 -1
View File
@@ -365,7 +365,8 @@ impl From<pest::iterators::Pair<'_, Rule>> for Statement {
},
Rule::for_stmt => Statement::For {
pattern: Identifier::from(inner.next().unwrap()),
mutable: listen_rule(&mut inner, Rule::mutable),
pattern: Pattern::from(inner.next().unwrap()),
iterator: inner.next().unwrap().into(),
body: Box::new(Statement::from(inner.next().unwrap())),
},