diff --git a/codegen/src/expr.rs b/codegen/src/expr.rs index 298b6cb..acf1e9c 100644 --- a/codegen/src/expr.rs +++ b/codegen/src/expr.rs @@ -100,9 +100,16 @@ impl GenRust for Expression { } } - if ensure_semicolon { - ctx.expr_ensure_semicolon = true; - cg.add(";"); + if let Expression::Statement(stmt) = self { + if !stmt.is_block() && ensure_semicolon { + ctx.expr_ensure_semicolon = true; + cg.add(";"); + } + } else { + if ensure_semicolon { + ctx.expr_ensure_semicolon = true; + cg.add(";"); + } } } } diff --git a/mist-test/src/app.mist b/mist-test/src/app.mist index f6af528..8ebeed7 100644 --- a/mist-test/src/app.mist +++ b/mist-test/src/app.mist @@ -97,7 +97,7 @@ pub class Application { println!("{x}"); } - for (usize i = 0; i < 10; i++) { + for (var mut i = 0; i < 10; i++) { println!("{i}"); } diff --git a/mist-test/src/logger.mist b/mist-test/src/logger.mist index e8ee98a..fab6cea 100644 --- a/mist-test/src/logger.mist +++ b/mist-test/src/logger.mist @@ -13,7 +13,7 @@ pub enum LogLevel { impl fmt::Display for LogLevel { fmt::Result fmt(self*, Formatter<'_> mut* f) { - return match (self) { + match (self) { LogLevel::Info => write!(f, "[INFO]"); LogLevel::Warning => write!(f, "[WARN]"); @@ -66,7 +66,7 @@ pub class Logger { impl fmt::Display { fmt::Result fmt(self*, Formatter<'_> mut* f) { - return write!(f, "logger ({})", self.prefix); + write!(f, "logger ({})", self.prefix) } } } \ No newline at end of file diff --git a/parser/src/ast/statement.rs b/parser/src/ast/statement.rs index 4ba6aa8..c6d9611 100644 --- a/parser/src/ast/statement.rs +++ b/parser/src/ast/statement.rs @@ -11,7 +11,6 @@ pub struct Block( #[derive(Debug, Clone, Serialize)] pub enum Statement { Block(Block), - VarDecl(VarDeclStmt), If { initial: StatementBranch, else_if: Vec, @@ -32,6 +31,7 @@ pub enum Statement { }, Match(Expression, Vec<(Vec, Expression)>), + VarDecl(VarDeclStmt), Return(Option), Break, Continue, @@ -55,3 +55,12 @@ pub struct StatementBranch { pub condition: Expression, pub body: Box, } + +impl Statement { + pub fn is_block(&self) -> bool { + match self { + Self::VarDecl(_) | Self::Return(_) | Self::Break | Self::Continue => false, + _ => true, + } + } +}