Working for loop

This commit is contained in:
2026-04-14 06:17:30 +02:00
parent 43ce27c12e
commit 77f1759b3b
2 changed files with 12 additions and 4 deletions
+1 -1
View File
@@ -92,7 +92,7 @@ pub enum Statement {
For {
init: (VarKind, String, Option<Expression>),
condition: Option<Expression>,
update: Option<Expression>,
update: Option<Box<Statement>>,
body: Box<Statement>,
},
+11 -3
View File
@@ -257,13 +257,13 @@ impl Statement {
.unwrap();
let condition = inner.next().map(Expression::from_pair);
let update = inner.next().map(Expression::from_pair);
let update = inner.next().map(parse_var_assign_no_semicolon);
let body = Statement::from_pair(inner.next().unwrap());
Statement::For {
init,
condition: None,
update: None,
condition,
update: update.map(Box::new),
body: Box::new(body),
}
}
@@ -370,3 +370,11 @@ impl Postfix {
}
}
}
fn parse_var_assign_no_semicolon(pair: pest::iterators::Pair<Rule>) -> Statement {
let mut inner = pair.into_inner();
let target = Expression::from_pair(inner.next().unwrap());
let value = Expression::from_pair(inner.next().unwrap());
Statement::VarAssign { target, value }
}