I was talking about having some structure similar to the code below, where you 
construct the data that actually makes sense as a representation of the 
documentation format, and then you write it out in JSON form. Then, anyone is 
free to take the `doc_ir.nim` file and implement the rendering tool of their 
choice.
    
    
    type
      DocQualName = object
        name: str
        module: str
        path: seq[str] ## Qualify full name from the library root, to avoid 
messing two
                       ## types in two modules with the same name, like 
`path1/mod.nim`
                       ## declaring `Type` and then `path2/mod.nim` declaring 
`Type`
                       ## as well.
      
      DocType = object
        fullName: DocQualName
        parameters: seq[DocType]
        
        # Not writing out the whole variant tree for number literals and so on
        # but the type should map type as seen by the user, like array, 
static[int]
        # etc. function types are omitted as well.
      
      DocField = object
        name: str
        exported: bool
        case isCase: bool
          of true:
            nested: seq[DocField]
          
          of false:
            typ: DocType
      
      DocObject = object
        field: seq[DocField]
        docs: string
        base: Optional[DocQualName]
        exported: bool
      
      DocArg = object
        name: str
        typ: DocType
      
      DocRunnableExample = object
        code: string
        nimCParams: seq[string]
      
      DocProc = object
        name: DocQualName
        arguments: seq[DocArg]
        returnType: Optional[DocType]
        documentation: string
        raises: seq[DocType]
        effects: seq[DocType]
      
      
      DocEnumField = object
        name: string
        documentation: string
        value: string # Or variant type?
      
      DocEnum = object
        name: DocQualName
        fields: seq[DocEnumField]
        exported: bool
      
      
      DocEntry = object
        case kind: DocEntryKind
          of dekEnum:
            denum: DocEnum
          
          of dekObject:
            dobject: DocObject
          
          of dekProc:
            dproc: DocProc
          
          of dekExample:
            ## Toplevel runnable example
            dexample: DocRunnableExample
          
          of dekComment:
            comment: string ## Toplevel comment
      
      DocModule = object
        imports: seq[DocQualName]
        toplevel: seq[DocEntry]
    
    
    
    
    Run

Reply via email to