Improved for loops

This commit is contained in:
2026-05-22 02:52:22 +02:00
parent 960cc40886
commit b7cfa9fbe6
5 changed files with 37 additions and 12 deletions
+3 -3
View File
@@ -19,10 +19,10 @@ pub enum Statement {
},
While(StatementBranch),
CStyleFor {
init: Box<Statement>,
init: Expression,
condition: Expression,
update: Box<Statement>,
body: Box<Statement>,
update: Expression,
body: Expression,
},
For {
mutable: bool,
+2 -2
View File
@@ -405,11 +405,11 @@ while_stmt = {
}
c_for_stmt = {
"for" ~ "(" ~ statement ~ expr ~ semicolon ~ statement ~ ")" ~ statement
"for" ~ "(" ~ statement ~ statement ~ expr ~ ")" ~ statement
}
for_stmt = {
"for" ~ "(" ~ mutable? ~ pattern ~ "in" ~ expr ~ ")" ~ statement
"for" ~ "(" ~ mutable? ~ pattern ~ ":" ~ expr ~ ")" ~ statement
}
// ------------------------------------------------------
+3 -3
View File
@@ -75,10 +75,10 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Statement {
Rule::while_stmt => ast_expr!(Statement::While(inner.next().unwrap().try_into())),
Rule::c_for_stmt => ast_expr!(Statement::CStyleFor {
init: inner.next().unwrap().try_into().map(Box::new),
init: inner.next().unwrap().try_into(),
condition: inner.next().unwrap().try_into(),
update: inner.next().unwrap().try_into().map(Box::new),
body: inner.next().unwrap().try_into().map(Box::new),
update: inner.next().unwrap().try_into(),
body: inner.next().unwrap().try_into(),
}),
Rule::for_stmt => ast_expr!(Statement::For {