To be able to process the code containing the proc definitons, they have to be 
passed to a macro. This can be done by indenting and passing the code block 
like this 
    
    
    import processcode
    
    processCode:
      proc someProc() {.script.} = discard
    
    
    Run

or, without indenting the code, with a source code filter which processes the 
entire module: 
    
    
    #? stdtmpl(emit="")
    #import processcode
    #processModuleSrc "" &
    
    proc someProc() {.script.} = discard
    
    
    Run

In both cases, processcode.nim is needed: 
    
    
    import macros, strutils
    
    # define the custom pragma
    template script* {.pragma.}
    
    macro processCode*(body: untyped): untyped =
      result = body
      
      # analyze the body and build whatever you need to add to the result.
    
    macro processModuleSrc*(src: string): typed =
      getAst(processCode(src.strVal.parseStmt))
    
    
    Run

Reply via email to