Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unindent main block #654

Merged
merged 3 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
hdwalters marked this conversation as resolved.
Show resolved Hide resolved
// 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
Loading