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