aboutsummaryrefslogtreecommitdiff
path: root/src/formatter/utils.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-08-26 02:54:56 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-08-26 02:54:56 -0400
commit5b06702dde3f53510a3d64a8156a349914afa605 (patch)
tree86f3103b075056098d861c19c678f53e96c3c07a /src/formatter/utils.c
parent180a48ed733bf0ee1e296e3afe5a9be2d1deebcf (diff)
Fixes for unops
Diffstat (limited to 'src/formatter/utils.c')
-rw-r--r--src/formatter/utils.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/formatter/utils.c b/src/formatter/utils.c
index 472829d9..37751377 100644
--- a/src/formatter/utils.c
+++ b/src/formatter/utils.c
@@ -9,6 +9,7 @@
#include "../stdlib/optionals.h"
#include "../stdlib/tables.h"
#include "../stdlib/text.h"
+#include "formatter.h"
const Text_t single_indent = Text(" ");
@@ -110,3 +111,22 @@ CONSTFUNC const char *binop_tomo_operator(ast_e tag) {
default: return NULL;
}
}
+
+OptionalText_t termify_inline(ast_t *ast, Table_t comments) {
+ if (range_has_comment(ast->start, ast->end, comments)) return NONE_TEXT;
+ switch (ast->tag) {
+ case BINOP_CASES:
+ case Not:
+ case Negative: return parenthesize(format_inline_code(ast, comments), EMPTY_TEXT);
+ default: return format_inline_code(ast, comments);
+ }
+}
+
+Text_t termify(ast_t *ast, Table_t comments, Text_t indent) {
+ switch (ast->tag) {
+ case BINOP_CASES:
+ case Not:
+ case Negative: return parenthesize(format_code(ast, comments, indent), indent);
+ default: return format_inline_code(ast, comments);
+ }
+}