var parseComment = require('./parse_comment').parseComment;

exports.XQDoc = function(ast){
    'use strict';

    var doc = {};

    this.getDoc = function(){
        return doc;
    };

    this.WS = function(node){
        if(node.value.trim().substring(0, 3) === '(:~') {
            node.getParent.comment = parseComment(node.value);
        }
    };

    this.AnnotatedDecl = function(node){
        this.visitChildren(node);
        node.comment = node.getParent.comment;
        node.getParent.comment = undefined;
    };
    
    this.XQuery = function(node){
        this.visitChildren(node);
    };

    this.getXQDoc = function(sctx){
        var doc = {
            moduleNamespace: sctx.moduleNamespace,
            description: sctx.description,
            variables: [],
            functions: []
        };

        return doc;
    };

    this.visit = function (node) {
        var name = node.name;
        var skip = false;

        if (typeof this[name] === 'function') {
            skip = this[name](node) === true;
        }

        if (!skip) {
            this.visitChildren(node);
        }
    };

    this.visitChildren = function (node, handler) {
        for (var i = 0; i < node.children.length; i++) {
            var child = node.children[i];
            if (handler !== undefined && typeof handler[child.name] === 'function') {
                handler[child.name](child);
            } else {
                this.visit(child);
            }
        }
    };

    this.visit(ast);
};

@@ -1,12 +1,39 @@
+var _ = require('lodash');%0A
 var parseCom
@@ -842,24 +842,656 @@
         %7D;%0A%0A
+        _.forEach(sctx.variables, function(variable)%7B%0A            var varDecl = _.cloneDeep(variable.qname);%0A            varDecl.annotations = variable.annotations;%0A            doc.variables.push(varDecl);%0A        %7D);%0A%0A        _.forEach(sctx.functions, function(fn, key)%7B%0A            if(key.substring(0, 'http://www.w3.org/2001/XMLSchema#'.length) === 'http://www.w3.org/2001/XMLSchema#') %7B%0A                return;%0A            %7D%0A%0A            var tokens = key.split('#');%0A            doc.functions.push(%7B%0A                name: tokens%5B0%5D,%0A                uri: tokens%5B1%5D,%0A                params: fn.params%0A            %7D);%0A        %7D);%0A%0A
         retu

Add variables and functions