Skip to content

Commit 1f30a4c

Browse files
committed
new trailing body macros implemented from c3c #1906
1 parent 87f5a51 commit 1f30a4c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/c3tools/codefmt/_formatters.c3

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,14 @@ fn bool! CodeFmt.format_fn(CodeFmt* self, Token* t, NodeParserState* state) @pri
320320
case IMPLIES:
321321
self.write(" %s ", t.value);
322322
break;
323+
case LBRACE:
324+
// fn int foo(int x) => @pool() { ... }
325+
if (state.scope_depth == 1) {
326+
self.cache_statement_dump(no_split: true)!;
327+
nextcase STATE: state.transition(SCOPE);
328+
} else {
329+
nextcase default;
330+
}
323331
case EOS:
324332
self.cache_statement_add(state, t);
325333
self.cache_statement_dump(no_split: true)!;

test/c3tools/codefmt/c3fmt_corpus/macros.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,19 @@ macro matrix_component_mul(mat, val) @private
174174
var $Type = Real[<$typeof(mat.m).len>];
175175
return $typeof(*mat){ .m = val * ($Type)mat.m };
176176
}
177+
================================================================================
178+
fn_trailing_body
179+
================================================================================
180+
fn int foo(int x) => @pool()
181+
{
182+
String s = string::tformat("%d", x);
183+
io::printn(s);
184+
return 2;
185+
}
186+
--------------------------------------------------------------------------------
187+
fn int foo(int x) => @pool()
188+
{
189+
String s = string::tformat("%d", x);
190+
io::printn(s);
191+
return 2;
192+
}

0 commit comments

Comments
 (0)