I need to access doc comments to autogenerate API docs for a web framework. In 
macros, I can access CommentStmt that are in procs , but not in type section.

I dont know if i missed something. Does anyone know a way to extract doc 
comments from object declaration ?
    
    
    import macros
    
    type
      Foo = object
        ## This is an object
        afoo: string ## A foo field
    
    
    proc fooProc*() =
      ## This is a procedure
      discard
    
    
    macro desc(i: typed): untyped =
      result = newLit(i.getImpl.treeRepr)
    
    
    echo desc Foo
    echo "========================"
    echo desc fooProc
    
    
    Run

Prints
    
    
    TypeDef
      Sym "Foo"
      Empty
      ObjectTy
        Empty
        Empty
        RecList
          IdentDefs
            Ident "afoo"
            Sym "string"
            Empty
    ========================
    ProcDef
      Sym "fooProc"
      Empty
      Empty
      FormalParams
        Empty
      Empty
      Empty
      StmtList
        CommentStmt "This is a procedure"
        DiscardStmt
          Empty
    
    
    Run

Reply via email to