Unfortunately no, that's not doable. At least not with existing modules.

The `macros` module contains a proc `getImpl` which you _could_ potentially use 
on a module name. I say _could_ , because actually using it on a module returns 
a `nil` node.

The closest I was able to get to this was to create a macro with a typed body 
and use it with an include: 
    
    
    # procs.nim
    proc proc1(x: int): int = x * 2
    
    proc example(a, b: int): int = a * b
    
    
    # collectprocs.nim
    import std/macros
    
    macro collectProcsAux(module: typed): untyped =
      # typed parameters are sem-checked before being passed to macros – this
      # includes resolving imports and includes, so we'll exploit that
      
      var procSyms: seq[NimNode]
      
      # to get the procedures, we simply iterate over the included module:
      for stmt in module[1]:
        # and check whether the statement we got is a proc definition:
        if stmt.kind == nnkProcDef:
          procSyms.add(stmt[0])
      
      # the problem is that you can't really do much with your procs
      # outside of the macro. creating a const consisting of all those procs is
      # impossible because every one of them has a different type. you'd have to
      # work with the procs inside of this macro
    
    # you can also create a helper template for nicer syntax, like so:
    template includeAndCollectProcs(moduleName: untyped): untyped =
      collectProcsAux:
        include moduleName
    
    includeAndCollectProcs procs
    
    
    Run

But the side effect of `include`ing the module is that you're effectively 
compiling it twice, which can result in duplicate definition errors.

Reply via email to