diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-08-25 23:53:03 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-08-25 23:53:03 -0400 |
| commit | 91b6746fe1315aa9c09936b69cea3892c04c11af (patch) | |
| tree | 338a167cf476e9c27529b05fdd6b1e4c5dd48612 /src/formatter/types.c | |
| parent | 8898144eeaeab90cefeb6cbf746e9a336bf239be (diff) | |
Split out formatter into subfiles
Diffstat (limited to 'src/formatter/types.c')
| -rw-r--r-- | src/formatter/types.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/formatter/types.c b/src/formatter/types.c new file mode 100644 index 00000000..282a299f --- /dev/null +++ b/src/formatter/types.c @@ -0,0 +1,30 @@ +// Logic for formatting types + +#include "../ast.h" +#include "../stdlib/datatypes.h" +#include "../stdlib/optionals.h" +#include "../stdlib/text.h" +#include "formatter.h" + +OptionalText_t format_inline_type(type_ast_t *type, Table_t comments) { + if (range_has_comment(type->start, type->end, comments)) return NONE_TEXT; + switch (type->tag) { + default: { + Text_t code = Text$from_strn(type->start, (int64_t)(type->end - type->start)); + if (Text$has(code, Text("\n"))) return NONE_TEXT; + return Text$replace(code, Text("\t"), single_indent); + } + } +} + +Text_t format_type(type_ast_t *type, Table_t comments, Text_t indent) { + (void)comments, (void)indent; + switch (type->tag) { + default: { + OptionalText_t inline_type = format_inline_type(type, comments); + if (inline_type.length >= 0) return inline_type; + Text_t code = Text$from_strn(type->start, (int64_t)(type->end - type->start)); + return Text$replace(code, Text("\t"), single_indent); + } + } +} |
