code / tomo

Lines41.3K C23.7K Markdown9.7K YAML5.0K Tomo2.3K
7 others 763
Python231 Shell230 make212 INI47 Text21 SVG16 Lua6
(30 lines)
1 // This file defines utility functions for autoformatting code
3 #pragma once
5 #include <stdbool.h>
7 #include "../ast.h"
8 #include "../stdlib/datatypes.h"
9 #include "../stdlib/optionals.h"
11 #define MAX_WIDTH 100
13 #define must(expr) \
14 ({ \
15 OptionalText_t _expr = expr; \
16 if (_expr.tag == TEXT_NONE) return NONE_TEXT; \
17 (Text_t) _expr; \
18 })
20 extern const Text_t single_indent;
22 void add_line(Text_t *code, Text_t line, Text_t indent);
23 OptionalText_t next_comment(Table_t comments, const char **pos, const char *end);
24 bool range_has_comment(const char *start, const char *end, Table_t comments);
25 CONSTFUNC int suggested_blank_lines(ast_t *first, ast_t *second);
26 Text_t indent_code(Text_t code);
27 Text_t parenthesize(Text_t code, Text_t indent);
28 CONSTFUNC ast_t *unwrap_block(ast_t *ast);
29 OptionalText_t termify_inline(ast_t *ast, Table_t comments);
30 Text_t termify(ast_t *ast, Table_t comments, Text_t indent);