aboutsummaryrefslogtreecommitdiff
path: root/src/formatter.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/formatter.c')
-rw-r--r--src/formatter.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/formatter.c b/src/formatter.c
new file mode 100644
index 00000000..81a5e126
--- /dev/null
+++ b/src/formatter.c
@@ -0,0 +1,23 @@
+// This code defines functions for transforming ASTs back into Tomo source text
+
+#include "ast.h"
+#include "stdlib/datatypes.h"
+#include "stdlib/optionals.h"
+#include "stdlib/text.h"
+
+Text_t code_format(ast_t *ast, Table_t *comments) {
+ (void)comments;
+ switch (ast->tag) {
+ default: return Text$from_strn(ast->start, (int64_t)(ast->end - ast->start));
+ }
+}
+
+OptionalText_t code_format_inline(ast_t *ast, Table_t *comments) {
+ (void)comments;
+ for (const char *p = ast->start; p < ast->end; p++) {
+ if (*p == '\n' || *p == '\r') return NONE_TEXT;
+ }
+ switch (ast->tag) {
+ default: return Text$from_strn(ast->start, (int64_t)(ast->end - ast->start));
+ }
+}