Added forever loop

This commit is contained in:
2026-05-22 03:05:08 +02:00
parent d33763be2e
commit a26c1c31fb
5 changed files with 21 additions and 1 deletions
+5
View File
@@ -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,
+7 -1
View File
@@ -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!");
}
} }
} }
+1
View File
@@ -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,
+6
View File
@@ -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
// ------------------------------------------------------ // ------------------------------------------------------
+2
View File
@@ -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(),