aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-08-26 01:05:25 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-08-26 01:05:25 -0400
commitfc126b1103a8b6b6cbde7cf10ee6e25a3279cd9f (patch)
treeb2eb7df4bfde8f5c7b4dfba6fb8542aa5bddd1af
parent8166e4c194b039f0a1e5c011286fb156a12c82c2 (diff)
Fix for 'else if'
-rw-r--r--src/formatter/formatter.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/formatter/formatter.c b/src/formatter/formatter.c
index b62d3fbe..7c27d053 100644
--- a/src/formatter/formatter.c
+++ b/src/formatter/formatter.c
@@ -305,9 +305,14 @@ Text_t format_code(ast_t *ast, Table_t comments, Text_t indent) {
Text_t code = Texts("if ", fmt(if_->condition, comments, indent), "\n", indent, single_indent,
fmt(if_->body, comments, Texts(indent, single_indent)));
- if (if_->else_body)
- code = Texts(code, "\n", indent, "else \n", indent, single_indent,
- fmt(if_->else_body, comments, Texts(indent, single_indent)));
+ if (if_->else_body) {
+ if (if_->else_body->tag != If) {
+ code = Texts(code, "\n", indent, "else\n", indent, single_indent,
+ fmt(if_->else_body, comments, Texts(indent, single_indent)));
+ } else {
+ code = Texts(code, "\n", indent, "else ", fmt(if_->else_body, comments, indent));
+ }
+ }
return code;
}
/*multiline*/ case When: {