Your syntax for macro's call is OK, your key-value pair is parsed as a call 
(`id` being regarded as a proc name, and `int` as statement list (block), 
passed to it). Now you need to write a macro, that can use it. In that macro 
you first assign to `result` the constant part of your type, and then add to it 
new nodes, via procs from `macros` module (search forum for examples).
    
    
    import macros
    template obj(tName: untyped): untyped =
      type
        tName = object
          fname: string
          age: int
    macro typeGen(tName, extraCode: untyped): untyped =
      result = getAst(obj(tName))
      echo result.treeRepr # so you can see, where and how you add fields
      echo extraCode.treeRepr # so you can see, from where and you get them
      # and here you parse ``extraCode`` and add additional nodes to 
result[0][0][2][2];
      # as is now, it will create a type with just 2 fields in the template
    
    typeGen(Employee):
      id: int
    

Reply via email to