Working mapgen and fixed indentation
This commit is contained in:
@@ -41,7 +41,7 @@ impl RustCodegen {
|
|||||||
output: String::new(),
|
output: String::new(),
|
||||||
indent: 0,
|
indent: 0,
|
||||||
mapping: HashSet::new(),
|
mapping: HashSet::new(),
|
||||||
position: RustMap(0, 0),
|
position: RustMap(1, 0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,17 +50,14 @@ impl RustCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn add(&mut self, s: &str) {
|
fn add(&mut self, s: &str) {
|
||||||
for c in s.chars() {
|
for b in s.bytes() {
|
||||||
match c {
|
if b == b'\n' {
|
||||||
'\n' => {
|
|
||||||
self.position.0 += 1;
|
self.position.0 += 1;
|
||||||
self.position.1 = 0;
|
self.position.1 = 0;
|
||||||
}
|
} else {
|
||||||
_ => {
|
|
||||||
self.position.1 += 1;
|
self.position.1 += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
self.output.push_str(s);
|
self.output.push_str(s);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,12 +11,14 @@ impl GenRust for Block {
|
|||||||
|
|
||||||
for stmt in &self.statements {
|
for stmt in &self.statements {
|
||||||
ctx.expr_ensure_semicolon = true;
|
ctx.expr_ensure_semicolon = true;
|
||||||
|
cg.add_indented("");
|
||||||
stmt.gen_rust(ctx, cg);
|
stmt.gen_rust(ctx, cg);
|
||||||
cg.addln("");
|
cg.addln("");
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(soft_return) = &self.soft_return {
|
if let Some(soft_return) = &self.soft_return {
|
||||||
ctx.expr_ensure_semicolon = false;
|
ctx.expr_ensure_semicolon = false;
|
||||||
|
cg.add_indented("");
|
||||||
soft_return.gen_rust(ctx, cg);
|
soft_return.gen_rust(ctx, cg);
|
||||||
cg.addln("");
|
cg.addln("");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ impl GenRust for ImplDecl {
|
|||||||
|
|
||||||
impl GenRust for FunctionDecl {
|
impl GenRust for FunctionDecl {
|
||||||
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
||||||
cg.add(&format!(
|
cg.add_indented(&format!(
|
||||||
"{}fn {}{}(",
|
"{}fn {}{}(",
|
||||||
self.visibility.get_rust(),
|
self.visibility.get_rust(),
|
||||||
self.name.get_rust(),
|
self.name.get_rust(),
|
||||||
@@ -97,8 +97,9 @@ impl GenRust for FunctionDecl {
|
|||||||
if let Some(body) = &self.body {
|
if let Some(body) = &self.body {
|
||||||
cg.add(" ");
|
cg.add(" ");
|
||||||
body.gen_rust(ctx, cg);
|
body.gen_rust(ctx, cg);
|
||||||
|
cg.addln("");
|
||||||
} else {
|
} else {
|
||||||
cg.add(";");
|
cg.addln(";");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user