No, the final enum has the export marker and the group macro adds an entry for 
the final enum and creates an optional enum with suffix "Msg" for actions (with 
the export marker too): 
    
    
    import macros
    
    # Groups Enum
    var groupEnum {.compileTime.} = newNimNode(nnkEnumTy).add(
      newEmptyNode(), newIdentNode("gGeneric")
    )
    
    # Group Builder
    macro group*(name: untyped, messages: untyped) =
      # Expects Ident and StmtList
      name.expectKind(nnkIdent)
      messages.expectKind(nnkStmtList)
      # Add the Group name to Group Enums
      groupEnum.add(
        newIdentNode("g" & name.strVal)
      )
      # Create a nameMsg enum if is not discarded
      if messages[0].kind != nnkDiscardStmt:
        result = nnkStmtList.newTree()
        # Create Enum Node
        var msgNode = newNimNode(nnkEnumTy)
        msgNode.add(newEmptyNode())
        for m in messages:
          m.expectKind(nnkIdent)
          msgNode.add(
            newIdentNode("msg" & m.strVal)
          )
        # Create Type Enum Node
        result.add(
          newNimNode(nnkTypeSection).add(
            newNimNode(nnkTypeDef).add(
              newNimNode(nnkPostfix).add(
                newIdentNode("*"),
                newIdentNode(name.strVal & "Msg")
              ),
              newEmptyNode(),
              msgNode
            )
          )
        )
    
    # Generates Group Enum
    macro groupType*(name: untyped) =
      # Expect name as ident
      name.expectKind(nnkIdent)
      # Create a new Enum type
      result = newNimNode(nnkTypeSection).add(
        newNimNode(nnkTypeDef).add(
          newNimNode(nnkPostfix).add(
            newIdentNode("*"), name
          ),
          newEmptyNode(),
          groupEnum
        )
      )
    
    group Window:
      Open
      Close
    
    # Generate Groups Type
    groupType(Groups)
    
    when isMainModule:
      echo sizeof(Groups)
      var s = {gWindow}
      echo s
    
    
    Run

i noticed that calling "group" macro after "groupType" macro doesn't add the 
group to enum too 
    
    
    # Called before groupType
    group Window:
      Exit
    
    # Generate Groups Type, only has Window
    groupType(Groups)
    
    # Called after groupType
    group SubWindow:
      Move
      Resize
    
    when isMainModule:
      echo sizeof(Groups)
      var s = {gWindow, gSubWindow} # undeclared identifier 'gSubWindow'
      echo s
    
    
    Run

maybe is impossible for now modify the generated enum type at every call of 
"group" macro. a workaround for this is still use a counter var and use a fixed 
set size (`set[0..63]`)

Reply via email to