-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_comment.js
67 lines (63 loc) · 2.47 KB
/
parse_comment.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
'use strict';
// @see http://xqdoc.org/xqdoc_comments_doc.html
// @author,@version,@since,@see,@param,@return,@deprecated,@error
exports.parseComment = function (comment) {
comment = comment.trim();
var isXQDoc = comment.substring(0, 3) === '(:~';
if (isXQDoc) {
var lines = comment.slice(3).slice(0, -2).split('\n');
var ann = {
description: '',
params: {},
errors: [],
others: []
};
var tag = "description"; //starting (non) tag
lines.forEach(function (line, index) {
line = line.trim();
if (line[0] === ':') {line = line.substring(1).trim();}
if (line.length > 0) {
var reTag = new RegExp("^\\s*@(?<tag>\\w+)\\s+(?<rest>.+)$", "g");
var hits = reTag.exec(line);
var hasTag = hits !== null;
if (hasTag) {tag = hits.groups.tag;}
switch (tag) {
case "description":
ann.description += ' ' + line;
break;
case "param":
if (hasTag) {
var reParam = new RegExp("^\\s*(?<param>[$]\\w+)\\s+(?<rest>.+)$", "g");
var phit = reParam.exec(hits.groups.rest);
if (phit !== null) {
ann.params[phit.groups.param] = phit.groups.rest;}
} else {
console.log("TODO", tag, line);
}
break;
case "return":
if (hasTag) {
ann.return = hits.groups.rest;
} else {
ann.return += ' ' + line;
}
break;
case "error":
if (hasTag) {
ann.errors.push(hits.groups.rest);
} else {
console.log('TODO', tag, line);
}
break;
default:
if (hasTag) {
ann.others.push({ 'tag': tag, 'value': hits.groups.rest });
console.log('TODO', tag, line);
}
}
}
});
// console.log(ann);
return ann;
}
};