Well, you have no choice than use macros. If you don't want to deal with the 
ast, you can still [work with strings](https://glot.io/snippets/eu2z63ru1r): 
    
    
    import macros, strutils
    
    macro typeGen(tName, extra: untyped): untyped =
      var typeStr = """
        type
          tName = object
            fname: string
            age: int"""
      
      typeStr = replace(typeStr, "tName", $tName)
      add(typeStr, "\l        ")
      
      for f in extra:
        add(typeStr, repr(f[0]) & ':' & repr(f[1][0]))
        add(typeStr, "\l        ")
      
      return parseStmt(typeStr)
    
    typeGen Test:
      a: bool
      b: byte
    

Reply via email to