From 4c519b98b2d9c2739f696aa08600a40136f72c01 Mon Sep 17 00:00:00 2001 From: Huw Walters Date: Thu, 26 Dec 2024 13:02:34 +0000 Subject: [PATCH 1/3] Unindent code in main block. --- src/modules/main.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/modules/main.rs b/src/modules/main.rs index aab1e110..62843c51 100644 --- a/src/modules/main.rs +++ b/src/modules/main.rs @@ -73,7 +73,16 @@ 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 translate. Unlike + // other instances of code blocks, we do not want to indent + // the code generated from the main block. We will ultimately + // need to rewrite the code generation, and this hack will go + // away. + meta.decrease_indent(); + let result = format!("{args}\n{}", self.block.translate(meta)); + meta.increase_indent(); + result } } } From 08031c00e7f4026271de1a3e7542afce4015b914 Mon Sep 17 00:00:00 2001 From: Huw Walters Date: Thu, 26 Dec 2024 17:23:12 +0000 Subject: [PATCH 2/3] Cap indentation level at zero. --- src/utils/metadata/translate.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/metadata/translate.rs b/src/utils/metadata/translate.rs index 4448769c..a53c6531 100644 --- a/src/utils/metadata/translate.rs +++ b/src/utils/metadata/translate.rs @@ -1,3 +1,4 @@ +use std::cmp; use std::collections::VecDeque; use crate::compiler::CompilerOptions; @@ -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) { From 3c2d73df2acf106d748ac7c4304f1a254bb345b0 Mon Sep 17 00:00:00 2001 From: Huw Walters Date: Tue, 31 Dec 2024 13:17:31 +0000 Subject: [PATCH 3/3] Add TODO comment as requested. --- src/modules/main.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/modules/main.rs b/src/modules/main.rs index 62843c51..c2b0eac1 100644 --- a/src/modules/main.rs +++ b/src/modules/main.rs @@ -74,11 +74,10 @@ impl TranslateModule for Main { |name| format!("declare -r {name}=({quote}{dollar}0{quote} {quote}{dollar}@{quote})") ); // Temporarily decrease the indentation level to counteract - // the indentation applied by the block translate. Unlike + // 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. We will ultimately - // need to rewrite the code generation, and this hack will go - // away. + // 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();