Possibly removed the need for ensure_semicolon

This commit is contained in:
2026-07-02 06:33:17 +02:00
parent 68cf239f92
commit 4579c656b9
6 changed files with 20 additions and 54 deletions
-2
View File
@@ -362,7 +362,6 @@ impl ClassProcessedData {
if *i > 0 {
cg.add(", ");
}
ctx.expr_ensure_semicolon = false;
param.name.gen_rust(ctx, cg);
}
cg.addln(");");
@@ -599,7 +598,6 @@ pub fn gen_method_point(method: &FunctionDecl, ctx: &mut Context, cg: &mut RustC
for (_, param) in &params {
cg.add(", ");
ctx.expr_ensure_semicolon = false;
param.name.gen_rust(ctx, cg);
}
-16
View File
@@ -68,14 +68,6 @@ impl GenRust for Literal {
impl GenRust for Expression {
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
let ensure_semicolon = if ctx.expr_ensure_semicolon {
ctx.expr_ensure_semicolon = false;
true
} else {
false
};
match self {
Expression::Path(path) => cg.add(&path.get_rust_ctx(ctx)),
Expression::Literal(literal) => literal.gen_rust(ctx, cg),
@@ -152,14 +144,6 @@ impl GenRust for Expression {
}
}
}
if ensure_semicolon {
ctx.expr_ensure_semicolon = true;
if !self.is_block() {
cg.add(";");
}
}
}
}
-14
View File
@@ -4,13 +4,6 @@ use crate::fmt::{Context, GenMist, GetMist, MistCodegen};
impl GenMist for Expression {
fn gen_mist(&self, ctx: &mut Context, cg: &mut MistCodegen) {
let ensure_semicolon = if ctx.expr_ensure_semicolon {
ctx.expr_ensure_semicolon = false;
true
} else {
false
};
match self {
Expression::Path(path) => cg.add(&path.get_mist()),
Expression::Literal(literal) => literal.gen_mist(ctx, cg),
@@ -75,13 +68,6 @@ impl GenMist for Expression {
}
}
}
if ensure_semicolon {
ctx.expr_ensure_semicolon = true;
if !self.is_block() {
cg.add(";");
}
}
}
}
-2
View File
@@ -12,7 +12,6 @@ use mist_parser::{
};
pub struct Context {
pub expr_ensure_semicolon: bool,
pub expr_super: Option<ExprPath>,
}
@@ -81,7 +80,6 @@ impl RustCodegen {
pub fn generate(&mut self, toplevels: Vec<TopLevel>) -> String {
let mut ctx = Context {
expr_ensure_semicolon: true,
expr_super: None,
};
+11 -9
View File
@@ -10,14 +10,15 @@ impl GenRust for Block {
cg.indent += 1;
for stmt in &self.statements {
ctx.expr_ensure_semicolon = true;
cg.add_indented("");
stmt.gen_rust(ctx, cg);
if stmt.item.is_semicolon_required() {
cg.add(";");
}
cg.addln("");
}
if let Some(soft_return) = &self.soft_return {
ctx.expr_ensure_semicolon = false;
cg.add_indented("");
soft_return.gen_rust(ctx, cg);
cg.addln("");
@@ -86,14 +87,12 @@ impl GenRust for Statement {
else_branch,
} => {
cg.add("if ");
ctx.expr_ensure_semicolon = false;
initial.condition.gen_rust(ctx, cg);
cg.add(" ");
initial.body.gen_rust(ctx, cg);
for else_if_branch in else_if {
cg.add(" else if ");
ctx.expr_ensure_semicolon = false;
else_if_branch.condition.gen_rust(ctx, cg);
cg.add(" ");
else_if_branch.body.gen_rust(ctx, cg);
@@ -126,17 +125,18 @@ impl GenRust for Statement {
cg.addln("{");
cg.indent += 1;
ctx.expr_ensure_semicolon = true;
cg.add_indented("");
init.gen_rust(ctx, cg);
if init.is_semicolon_required() {
cg.add(";");
}
cg.addln("");
cg.add_indented("while ");
ctx.expr_ensure_semicolon = false;
condition.gen_rust(ctx, cg);
cg.add(" ");
@@ -144,12 +144,14 @@ impl GenRust for Statement {
cg.add("{");
cg.indent += 1;
ctx.expr_ensure_semicolon = true;
body.gen_rust(ctx, cg);
update.gen_rust(ctx, cg);
if update.is_semicolon_required() {
cg.add(";");
}
cg.addln("");
cg.indent -= 1;