Skip to content

Commit

Permalink
Unindent main block (#654)
Browse files Browse the repository at this point in the history
* Unindent code in main block.

* Cap indentation level at zero.

* Add TODO comment as requested.
  • Loading branch information
hdwalters authored Jan 4, 2025
1 parent 0f05af9 commit 665cdc1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/modules/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,15 @@ impl TranslateModule for Main {
String::new,
|name| format!("declare -r {name}=({quote}{dollar}0{quote} {quote}{dollar}@{quote})")
);
format!("{args}\n{}", self.block.translate(meta))
// Temporarily decrease the indentation level to counteract
// the indentation applied by the block translation. Unlike
// other instances of code blocks, we do not want to indent
// the code generated from the main block.
// TODO: Rethink as part of the Bash output improvement work.
meta.decrease_indent();
let result = format!("{args}\n{}", self.block.translate(meta));
meta.increase_indent();
result
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/utils/metadata/translate.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::cmp;
use std::collections::VecDeque;

use crate::compiler::CompilerOptions;
Expand Down Expand Up @@ -50,7 +51,7 @@ impl TranslateMetadata {
}

pub fn gen_indent(&self) -> String {
INDENT_SPACES.repeat(self.indent as usize)
INDENT_SPACES.repeat(cmp::max(self.indent, 0) as usize)
}

pub fn increase_indent(&mut self) {
Expand Down

0 comments on commit 665cdc1

Please sign in to comment.