Some nodes were missing, found everything:
    
    
    import macros
    
    proc parseCustomStmt(code: string): NimNode {.compileTime.} =
      let tree = parseStmt(code)
      return tree
    
    macro parseAndVisit(code: static[string]): void =
      let tree = parseCustomStmt(code)
      
      proc visit(n: NimNode): void =
        case n.kind
        of nnkStmtList, nnkBlockStmt:
          for child in n:
            visit(child)
        
        of nnkProcDef:
          echo "Found procedure declaration: ", n[0].strVal
          for child in n:
            visit(child)
        
        of nnkVarSection, nnkLetSection:
          for vars in n:
            if vars.kind == nnkIdentDefs:
              for varDef in vars:
                if varDef.kind == nnkIdent:
                  echo "Found variable declaration: ", varDef.strVal
                  visit(varDef)
        
        of nnkReturnStmt:
          echo "Found return statement"
          if n.len > 0 and n[0].kind != nnkEmpty: visit(n[0])
        
        else:
          discard
      
      visit(tree)
    
    parseAndVisit("""
    proc foo(x, y: int): int =
      let z = x
      return z
    """)
    
    
    Run

Reply via email to