Fixed block statements

This commit is contained in:
2026-05-22 03:00:43 +02:00
parent b7cfa9fbe6
commit d33763be2e
4 changed files with 23 additions and 7 deletions
+10 -3
View File
@@ -100,9 +100,16 @@ impl GenRust for Expression {
} }
} }
if ensure_semicolon { if let Expression::Statement(stmt) = self {
ctx.expr_ensure_semicolon = true; if !stmt.is_block() && ensure_semicolon {
cg.add(";"); ctx.expr_ensure_semicolon = true;
cg.add(";");
}
} else {
if ensure_semicolon {
ctx.expr_ensure_semicolon = true;
cg.add(";");
}
} }
} }
} }
+1 -1
View File
@@ -97,7 +97,7 @@ pub class Application {
println!("{x}"); println!("{x}");
} }
for (usize i = 0; i < 10; i++) { for (var mut i = 0; i < 10; i++) {
println!("{i}"); println!("{i}");
} }
+2 -2
View File
@@ -13,7 +13,7 @@ pub enum LogLevel {
impl fmt::Display for LogLevel { impl fmt::Display for LogLevel {
fmt::Result fmt(self*, Formatter<'_> mut* f) { fmt::Result fmt(self*, Formatter<'_> mut* f) {
return match (self) { match (self) {
LogLevel::Info => write!(f, "[INFO]"); LogLevel::Info => write!(f, "[INFO]");
LogLevel::Warning => write!(f, "[WARN]"); LogLevel::Warning => write!(f, "[WARN]");
@@ -66,7 +66,7 @@ pub class Logger {
impl fmt::Display { impl fmt::Display {
fmt::Result fmt(self*, Formatter<'_> mut* f) { fmt::Result fmt(self*, Formatter<'_> mut* f) {
return write!(f, "logger ({})", self.prefix); write!(f, "logger ({})", self.prefix)
} }
} }
} }
+10 -1
View File
@@ -11,7 +11,6 @@ pub struct Block(
#[derive(Debug, Clone, Serialize)] #[derive(Debug, Clone, Serialize)]
pub enum Statement { pub enum Statement {
Block(Block), Block(Block),
VarDecl(VarDeclStmt),
If { If {
initial: StatementBranch, initial: StatementBranch,
else_if: Vec<StatementBranch>, else_if: Vec<StatementBranch>,
@@ -32,6 +31,7 @@ pub enum Statement {
}, },
Match(Expression, Vec<(Vec<Pattern>, Expression)>), Match(Expression, Vec<(Vec<Pattern>, Expression)>),
VarDecl(VarDeclStmt),
Return(Option<Expression>), Return(Option<Expression>),
Break, Break,
Continue, Continue,
@@ -55,3 +55,12 @@ pub struct StatementBranch {
pub condition: Expression, pub condition: Expression,
pub body: Box<Statement>, pub body: Box<Statement>,
} }
impl Statement {
pub fn is_block(&self) -> bool {
match self {
Self::VarDecl(_) | Self::Return(_) | Self::Break | Self::Continue => false,
_ => true,
}
}
}