Working for loop
This commit is contained in:
+1
-1
@@ -92,7 +92,7 @@ pub enum Statement {
|
|||||||
For {
|
For {
|
||||||
init: (VarKind, String, Option<Expression>),
|
init: (VarKind, String, Option<Expression>),
|
||||||
condition: Option<Expression>,
|
condition: Option<Expression>,
|
||||||
update: Option<Expression>,
|
update: Option<Box<Statement>>,
|
||||||
body: Box<Statement>,
|
body: Box<Statement>,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
+11
-3
@@ -257,13 +257,13 @@ impl Statement {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let condition = inner.next().map(Expression::from_pair);
|
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());
|
let body = Statement::from_pair(inner.next().unwrap());
|
||||||
|
|
||||||
Statement::For {
|
Statement::For {
|
||||||
init,
|
init,
|
||||||
condition: None,
|
condition,
|
||||||
update: None,
|
update: update.map(Box::new),
|
||||||
body: Box::new(body),
|
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 }
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user