Added forever loop
This commit is contained in:
@@ -98,6 +98,11 @@ impl GenRust for Statement {
|
||||
cg.ensure_brackets(ctx, body);
|
||||
}
|
||||
|
||||
Statement::Loop(body) => {
|
||||
cg.add("loop ");
|
||||
cg.ensure_brackets_expr(ctx, body);
|
||||
}
|
||||
|
||||
Statement::CStyleFor {
|
||||
init,
|
||||
condition,
|
||||
|
||||
@@ -101,8 +101,14 @@ pub class Application {
|
||||
println!("{i}");
|
||||
}
|
||||
|
||||
while (true) {
|
||||
var i = 0;
|
||||
|
||||
while (i == 0) {
|
||||
println!("hi");
|
||||
}
|
||||
|
||||
loop {
|
||||
println!("loop!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ pub enum Statement {
|
||||
else_if: Vec<StatementBranch>,
|
||||
else_branch: Option<Box<Statement>>,
|
||||
},
|
||||
Loop(Expression),
|
||||
While(StatementBranch),
|
||||
CStyleFor {
|
||||
init: Expression,
|
||||
|
||||
@@ -29,6 +29,7 @@ keyword = {
|
||||
| "true"
|
||||
| "false"
|
||||
| "dyn"
|
||||
| "loop"
|
||||
}
|
||||
|
||||
identifier = @{
|
||||
@@ -379,6 +380,7 @@ control_flow = {
|
||||
| c_for_stmt
|
||||
| for_stmt
|
||||
| match_stmt
|
||||
| loop_stmt
|
||||
| block
|
||||
}
|
||||
|
||||
@@ -412,6 +414,10 @@ for_stmt = {
|
||||
"for" ~ "(" ~ mutable? ~ pattern ~ ":" ~ expr ~ ")" ~ statement
|
||||
}
|
||||
|
||||
loop_stmt = {
|
||||
"loop" ~ statement
|
||||
}
|
||||
|
||||
// ------------------------------------------------------
|
||||
// MATCH
|
||||
// ------------------------------------------------------
|
||||
|
||||
@@ -74,6 +74,8 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Statement {
|
||||
|
||||
Rule::while_stmt => ast_expr!(Statement::While(inner.next().unwrap().try_into())),
|
||||
|
||||
Rule::loop_stmt => ast_expr!(Statement::Loop(inner.next().unwrap().try_into())),
|
||||
|
||||
Rule::c_for_stmt => ast_expr!(Statement::CStyleFor {
|
||||
init: inner.next().unwrap().try_into(),
|
||||
condition: inner.next().unwrap().try_into(),
|
||||
|
||||
Reference in New Issue
Block a user