diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-10-11 15:31:38 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-10-11 15:31:38 -0400 |
| commit | 7e8604daeb9239e1669c5414dd6caa37af30c4ff (patch) | |
| tree | 8fcab61a296381280902a3fc7b2d8456e2a9b227 /src/formatter | |
| parent | 25fa8ace21f0f6874f5b3ad1248e0e5d21190c84 (diff) | |
Make `{a,b,c}` shorthand for `{a:Empty(), b:Empty(), c:Empty()}` and
display it that way. Same for type annotations.
Diffstat (limited to 'src/formatter')
| -rw-r--r-- | src/formatter/formatter.c | 6 | ||||
| -rw-r--r-- | src/formatter/types.c | 3 |
2 files changed, 6 insertions, 3 deletions
diff --git a/src/formatter/formatter.c b/src/formatter/formatter.c index 55fff920..5cb5d3cc 100644 --- a/src/formatter/formatter.c +++ b/src/formatter/formatter.c @@ -223,7 +223,8 @@ OptionalText_t format_inline_code(ast_t *ast, Table_t comments) { } /*inline*/ case TableEntry: { DeclareMatch(entry, ast, TableEntry); - return Texts(fmt_inline(entry->key, comments), "=", fmt_inline(entry->value, comments)); + if (entry->value) return Texts(fmt_inline(entry->key, comments), ": ", fmt_inline(entry->value, comments)); + else return Texts(fmt_inline(entry->key, comments)); } /*inline*/ case Declare: { DeclareMatch(decl, ast, Declare); @@ -629,7 +630,8 @@ Text_t format_code(ast_t *ast, Table_t comments, Text_t indent) { /*multiline*/ case TableEntry: { if (inlined_fits) return inlined; DeclareMatch(entry, ast, TableEntry); - return Texts(fmt(entry->key, comments, indent), ": ", fmt(entry->value, comments, indent)); + if (entry->value) return Texts(fmt(entry->key, comments, indent), ": ", fmt(entry->value, comments, indent)); + else return Texts(fmt(entry->key, comments, indent)); } /*multiline*/ case Declare: { if (inlined_fits) return inlined; diff --git a/src/formatter/types.c b/src/formatter/types.c index 670405f6..929c8ff9 100644 --- a/src/formatter/types.c +++ b/src/formatter/types.c @@ -19,7 +19,8 @@ Text_t format_type(type_ast_t *type) { } case TableTypeAST: { DeclareMatch(table, type, TableTypeAST); - Text_t code = Texts("{", format_type(table->key), ":", format_type(table->value)); + Text_t code = Texts("{", format_type(table->key)); + if (table->value != NULL) code = Texts(code, ":", format_type(table->value)); if (table->default_value) { OptionalText_t val = format_inline_code(table->default_value, (Table_t){}); assert(val.tag != TEXT_NONE); |
