aboutsummaryrefslogtreecommitdiff
path: root/src/formatter/utils.h
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-08-25 23:59:09 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-08-25 23:59:09 -0400
commit978835e3dd8dd59a1efaa869f2f603eb9eea5a3f (patch)
tree112078680658abcb9d9fa310e2f8c8553d0fa40b /src/formatter/utils.h
parent91b6746fe1315aa9c09936b69cea3892c04c11af (diff)
Split out utility functions
Diffstat (limited to 'src/formatter/utils.h')
-rw-r--r--src/formatter/utils.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/formatter/utils.h b/src/formatter/utils.h
new file mode 100644
index 00000000..a8def627
--- /dev/null
+++ b/src/formatter/utils.h
@@ -0,0 +1,28 @@
+// This file defines utility functions for autoformatting code
+
+#pragma once
+
+#include <stdbool.h>
+
+#include "../ast.h"
+#include "../stdlib/datatypes.h"
+
+#define MAX_WIDTH 100
+
+#define must(expr) \
+ ({ \
+ OptionalText_t _expr = expr; \
+ if (_expr.length < 0) return NONE_TEXT; \
+ (Text_t) _expr; \
+ })
+
+extern const Text_t single_indent;
+
+void add_line(Text_t *code, Text_t line, Text_t indent);
+OptionalText_t next_comment(Table_t comments, const char **pos, const char *end);
+bool range_has_comment(const char *start, const char *end, Table_t comments);
+CONSTFUNC bool should_have_blank_line(ast_t *ast);
+Text_t indent_code(Text_t code);
+Text_t parenthesize(Text_t code, Text_t indent);
+CONSTFUNC ast_t *unwrap_block(ast_t *ast);
+CONSTFUNC const char *binop_tomo_operator(ast_e tag);