You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Because Amber uses the same code to translate the main block as it uses for defined functions, the code in the main block is incorrectly indented.
To Reproduce
Create this Amber script:
hwalters@Ghostwheel ~/git/amber-lang (main)
$ cat main.ab
fun foo() {
echo "Function block should be indented"
}
main(args) {
echo "Main block should not be indented"
foo()
}
Build without running any postprocessors:
hwalters@Ghostwheel ~/git/amber-lang (main)
$ amber build main.ab - --no-proc '*'
#!/usr/bin/env bash
# Written in [Amber](https://amber-lang.com/)
# version: 0.4.0-alpha
# date: 2024-12-26 16:14:56
# #!/usr/bin/env amber
foo__0_v0() {
echo "Function block should be indented"
}
declare -r args=("$0" "$@")
echo "Main block should not be indented"
foo__0_v0 ;
__AF_foo0_v0__9_5="$__AF_foo0_v0";
echo "$__AF_foo0_v0__9_5" > /dev/null 2>&1
Expected behavior
The contents of the main block should not be indented:
hwalters@Ghostwheel ~/git/amber-lang (main)
$ amber build main.ab - --no-proc '*'
#!/usr/bin/env bash
# Written in [Amber](https://amber-lang.com/)
# version: 0.4.0-alpha
# date: 2024-12-26 16:14:56
# #!/usr/bin/env amber
foo__0_v0() {
echo "Function block should be indented"
}
declare -r args=("$0" "$@")
echo "Main block should not be indented"
foo__0_v0 ;
__AF_foo0_v0__9_5="$__AF_foo0_v0";
echo "$__AF_foo0_v0__9_5" > /dev/null 2>&1
Additional context
Currently, we generate Bash output in one of two ways: we either append individual lines directly to meta.stmt_queue, or build a Vec<String> with the lines, join on \n, and append the result to meta.stmt_queue. I would eventually like to add a new mechanism to format and indent lines in any scope as part of the 0.5.0 roadmap; but as a short-term workaround, I would like to decrease and increase the indentation level around the block translate call in src/modules/main.rs:
impl TranslateModule for Main {
fn translate(&self, meta: &mut TranslateMetadata) -> String {
...
meta.decrease_indent();
let result = format!("{args}\n{}", self.block.translate(meta));
meta.increase_indent();
result
...
}
}
Note, this will not cause an unsigned integer overflow, because the indentation level is stored as an i64. But just in case, we can cap the value at zero when doing the actual indentation:
Describe the bug
Because Amber uses the same code to translate the
main
block as it uses for defined functions, the code in themain
block is incorrectly indented.To Reproduce
Create this Amber script:
Build without running any postprocessors:
Expected behavior
The contents of the main block should not be indented:
Additional context
Currently, we generate Bash output in one of two ways: we either append individual lines directly to
meta.stmt_queue
, or build aVec<String>
with the lines, join on\n
, and append the result tometa.stmt_queue
. I would eventually like to add a new mechanism to format and indent lines in any scope as part of the 0.5.0 roadmap; but as a short-term workaround, I would like to decrease and increase the indentation level around the block translate call insrc/modules/main.rs
:Note, this will not cause an unsigned integer overflow, because the indentation level is stored as an
i64
. But just in case, we can cap the value at zero when doing the actual indentation:The text was updated successfully, but these errors were encountered: