Skip to content

Instantly share code, notes, and snippets.

@azproduction
Created September 13, 2012 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azproduction/3713940 to your computer and use it in GitHub Desktop.
Save azproduction/3713940 to your computer and use it in GitHub Desktop.
Simple JSDoc Parser

Code

/*not! @jsdoc*/

/**
 * Title
 *@pewpew1 ololo
 *
 *   @pewpew2 ololo
 * @pewpew3
 *  ololo
 *
 *  ololo
 */
function a() {

}

/**
 *@pewpew1 ololo
 *
 *   @pewpew1 ololo
 * @pewpew3
 *  ololo
 *
 *  ololo
 */

Parse result

[{
    "pewpew1": ["ololo"],
    "pewpew2": ["ololo"],
    "pewpew3": ["ololo  ololo"]
}, {
    "pewpew1": ["ololo", "ololo"],
    "pewpew3": ["ololo  ololo"]
}]

Example http://jsfiddle.net/TQtdR/1/

Known bugs

  • matches emails
function parseJsdoc(code, _blocks, _expressions) {
_blocks = [];
// Find JSDoc blocks
code.replace(/\/\*\*[\s\S]+?\*\//g, function (block) {
_expressions = {};
// Find @-expressions in each block
block.replace(/@\S+[^@]+/g, function (expression) {
expression = expression.replace(/\s*\*\/|\s+\*\s+/g, ' ').replace(/\s+$/, '').match(/@(\S+)\s+([\s\S]+)/);
if (!expression) {
return;
}
_expressions[expression[1]] = _expressions[expression[1]] || [];
_expressions[expression[1]].push(expression[2].replace(/\s+\*$/g, ''));
});
_blocks.push(_expressions);
});
return _blocks;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment