From d9358ea38b82db1ec681e39947ce66395f1f21e4 Mon Sep 17 00:00:00 2001 From: Selimaj Dev Date: Tue, 5 May 2026 16:41:59 +0200 Subject: [PATCH] C style for loop AST gen --- parser/src/ast.rs | 2 +- parser/src/lib.rs | 7 +++++++ test/src/main.mist | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/parser/src/ast.rs b/parser/src/ast.rs index 6cbbd92..50579e4 100644 --- a/parser/src/ast.rs +++ b/parser/src/ast.rs @@ -108,7 +108,7 @@ pub enum Statement { While(StatementBranch), CStyleFor { init: Box, - condition: Box, + condition: Expression, update: Box, body: Box, }, diff --git a/parser/src/lib.rs b/parser/src/lib.rs index 851713d..9dc588c 100644 --- a/parser/src/lib.rs +++ b/parser/src/lib.rs @@ -333,6 +333,13 @@ impl From> for Statement { Rule::while_stmt => Statement::While(pair.into()), + Rule::c_for_stmt => Statement::CStyleFor { + init: Box::new(Statement::from(inner.next().unwrap())), + condition: inner.next().unwrap().into(), + update: Box::new(Statement::from(inner.next().unwrap())), + body: Box::new(Statement::from(inner.next().unwrap())), + }, + Rule::assign_statement => Statement::VarAssign(VarAssignStmt { target: Expression::from(inner.next().unwrap()), value: Expression::from(inner.next().unwrap()), diff --git a/test/src/main.mist b/test/src/main.mist index 1ecf710..b739c17 100644 --- a/test/src/main.mist +++ b/test/src/main.mist @@ -1,5 +1,5 @@ void main() { - for (usize i; i < 10; i = i + 1;) { + for (usize mut i = 0; i < 10; i = i + 1;) { println!("{i}"); } }