var _ = require('lodash');
var jsParser = require('esprima');
var walk = require('../lib/walk');
var LEADING_STAR = /^[^\S\r\n]*\*[^\S\n\r]?/gm;

module.exports = function jsdocFileReader() {
  return {
    defaultPattern: /\.js$/,
    getDocs: function(fileInfo) {

      var ast = jsParser.parse(fileInfo.content, {
        loc: true,
        range: true,
        comment: true
      });

      return _(ast.comments)

        .filter(function(comment) {
          // To test for a jsdoc comment (i.e. starting with /** ), we need to check for a leading
          // star since the parser strips off the first "/*"
          return comment.type === 'Block' && comment.value.charAt(0) === '*';
        })

        .map(function(comment) {

          // Strip off any leading stars
          text = comment.value.replace(LEADING_STAR, '');

          // Trim off leading and trailing whitespace
          text = text.trim();

          // Extract the information about the code directly after this comment
          var codeNode = walk.findNodeAfter(ast, comment.range[1]);
          var codeAncestors = codeNode && walk.ancestor(ast, codeNode.node);

          // Create a doc from this comment
          return {
            startingLine: comment.loc.start.line,
            endingLine: comment.loc.end.line,
            content: text,
            codeNode: codeNode,
            codeAncestors: codeAncestors
          };

        })

        .value();
    }
  };
};
@@ -139,16 +139,395 @@
 %5D?/gm;%0A%0A
+/**%0A * @dgService jsdocFileReader%0A * @description%0A * This file reader will pull a doc for each jsdoc style comment in the source file%0A * (by default .js)%0A *%0A * The doc will initially have the form:%0A * %60%60%60%0A * %7B%0A *   content: 'the content of the comment',%0A *   startingLine: xxx,%0A *   endingLine: xxx,%0A *   codeNode: someASTNode%0A *   codeAncestors: arrayOfASTNodes%0A * %7D%0A * %60%60%60%0A */%0A
 module.e

add documentation block