From 6551aee03b35d8ea091f15288b97f5ad55bc5e3a Mon Sep 17 00:00:00 2001 From: Selimaj Dev Date: Sun, 24 May 2026 12:43:35 +0200 Subject: [PATCH] Fixed block propaganda --- crates/parser/src/ast/statement.rs | 10 +++++++--- crates/parser/src/grammar.pest | 2 +- crates/parser/src/parser/common/statement.rs | 9 ++------- mist-test/src/event.mist | 6 +++--- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/crates/parser/src/ast/statement.rs b/crates/parser/src/ast/statement.rs index f0682c5..ff89e07 100644 --- a/crates/parser/src/ast/statement.rs +++ b/crates/parser/src/ast/statement.rs @@ -14,7 +14,7 @@ pub enum Statement { If { initial: StatementBranch, else_if: Vec, - else_branch: Option>, + else_branch: Option, }, Loop(Expression), While(StatementBranch), @@ -28,7 +28,7 @@ pub enum Statement { mutable: bool, pattern: Pattern, iterator: Expression, - body: Box, + body: Expression, }, Match(Expression, Vec<(Vec, Expression)>), @@ -60,7 +60,11 @@ pub struct StatementBranch { impl Statement { pub fn is_block(&self) -> bool { match self { - Self::Block(_) => true, + Self::Block(_) | Self::Match(_, _) => true, + Self::While(branch) => branch.body.is_block(), + Self::For { body, .. } | Self::Loop(body) | Self::CStyleFor { body, .. } => { + body.is_block() + } Self::If { initial, else_if, diff --git a/crates/parser/src/grammar.pest b/crates/parser/src/grammar.pest index 94803f2..d255253 100644 --- a/crates/parser/src/grammar.pest +++ b/crates/parser/src/grammar.pest @@ -91,7 +91,7 @@ generics = { "<" ~ (generic ~ ("," ~ generic)*)? ~ ">" } // ====================================================== tuple_type = { - "(" ~ (type_expr ~ ("," ~ type_expr)*)? ~ ")" + "[" ~ (type_expr ~ ("," ~ type_expr)*)? ~ "]" } path_type = { diff --git a/crates/parser/src/parser/common/statement.rs b/crates/parser/src/parser/common/statement.rs index 7ed8227..07c57f2 100644 --- a/crates/parser/src/parser/common/statement.rs +++ b/crates/parser/src/parser/common/statement.rs @@ -63,12 +63,7 @@ impl<'a> TryFrom> for Statement { ast_expr!(Statement::If { initial: inner.next().unwrap().try_into(), else_if: collect_recovered(inner.next().unwrap().into_inner()), - else_branch: inner - .next() - .map(Expression::try_from) - .transpose() - .map(|v| v.map(Box::new)) - .get_map(|v| { Some(Box::new(v)) }), + else_branch: inner.next().map(Expression::try_from).transpose(), }) } @@ -87,7 +82,7 @@ impl<'a> TryFrom> for Statement { mutable: Ok(listen_rule(&mut inner, Rule::mutable)) as AstResult<'_, bool>, pattern: inner.next().unwrap().try_into(), iterator: inner.next().unwrap().try_into(), - body: inner.next().unwrap().try_into().map(Box::new), + body: inner.next().unwrap().try_into(), }), Rule::match_stmt => ast_expr!(Statement::Match( diff --git a/mist-test/src/event.mist b/mist-test/src/event.mist index 6340bf4..61a1292 100644 --- a/mist-test/src/event.mist +++ b/mist-test/src/event.mist @@ -1,7 +1,7 @@ pub enum Event { Startup, Shutdown, - TaskExecuted(String), - PluginLoaded(String), - Error(String), + TaskExecuted[String], + PluginLoaded[String], + Error[String], } \ No newline at end of file