based on @Clonk 's answer, I have used SCF with dumpTree, `users.nimf` #? stdtmpl | standard #proc generateType(class: string, # fields: openArray[string]): string = # result = "" import macros dumpTree: type ${class}* = object #for field in items(fields): ${field}*: string #end for Run include "users.nimf" # writeFile("users.nim", generateType("Person", @["name", "job", "email"])) import macros macro writeFileAtCompileTime(filename: string, content: string): untyped = # This macro will generate code to write a file at compile time result = quote do: static: writeFile(`filename`, `content`) # Usage of the macro writeFileAtCompileTime("users.nim", generateType("Person", @["name", "job", "email"])) # Regular code continues here echo "File has been written at compile time" # dumpTree here include users Run
result: StmtList TypeSection TypeDef Postfix Ident "*" Ident "Person" Empty ObjectTy Empty Empty RecList IdentDefs Postfix Ident "*" Ident "name" Ident "string" Empty IdentDefs Postfix Ident "*" Ident "job" Ident "string" Empty IdentDefs Postfix Ident "*" Ident "email" Ident "string" Empty Run just an idea, can we use scf and dumpTree results to autogenerate macros from scf?