Skip to content

Commit

Permalink
idlc: parser doxygen comment.
Browse files Browse the repository at this point in the history
  • Loading branch information
xicilion committed Jun 16, 2017
1 parent 5aa4d7a commit bc58e63
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 7 deletions.
2 changes: 1 addition & 1 deletion fibjs/include/ifs/Message.idl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
var mq = require("mq");
var m = new mq.Message();
@endcode
* */
*/
interface Message : object
{
/*! @brief 指定消息类型 1,代表一个文本类型 */
Expand Down
12 changes: 6 additions & 6 deletions fibjs/include/ifs/zmq.idl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

/*! @brief zeroMQ 消息队列模块
*
* 基础模块。提供 zeroMQ 消息队列支撑。
* \code
* var zmq = require('zmq');
* \endcode
*/

基础模块。提供 zeroMQ 消息队列支撑。
\code
var zmq = require('zmq');
\endcode
*/
module zmq
{
const PAIR = 0;
Expand Down
8 changes: 8 additions & 0 deletions tools/docs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var parser = require('./util/parser');
var gen_docs = require('./util/gen_docs');

var baseFolder = "../fibjs/include/ifs/";
var docsFolder = "../docs/docs/manual/";

var defs = parser(baseFolder);
gen_docs(defs, docsFolder);
8 changes: 8 additions & 0 deletions tools/util/gen_docs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var fs = require("fs");
var util = require("util");
var path = require('path');

module.exports = function (defs, docsFolder) {
console.log(defs);

}
87 changes: 87 additions & 0 deletions tools/util/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,87 @@ newToken = "new"

var parser = peg.generate(grammar);

function parser_comment(comment) {
var lines;
var doc = {
descript: '',
detail: [],
params: []
};

function check_padding() {
var sp = 0;
var s;

lines.forEach(l => {
var r = /^\s*/.exec(l)[0];
if (r !== '') {
if (sp === 0 || sp > r.length) {
sp = r.length;
s = r;
}
}
});

if (sp) {
lines = lines.map(line => {
if (line.substr(0, sp) === s)
return line.substr(sp);
return line;
});
}
}

function get_title() {
lines = comment.split('\n');
lines = lines.map(line => {
return line.trimRight();
});

doc.descript = lines[0];

lines = lines.slice(1);
if (lines[0] == '')
lines = lines.slice(1);
}

function get_docs() {
var now = doc;
lines.forEach(l => {
var re = /^\s*@((param)\s+([^\s]+)|return)\s*(.*)/g;
var r = re.exec(l);

if (r) {
if (r[1] === 'return') {
doc["return"] = now = {
descript: r[4],
detail: []
};
} else if (r[2] === 'param') {
doc.params.push(now = {
name: r[3],
descript: r[4],
detail: []
});
}
} else
now.detail.push(l);
});
}

comment = comment.replace(/^\s*!?\s*(@brief)?\s*/, '');
comment = comment.replace(/\s*$/, '');

if (comment == '')
return doc;

get_title();
check_padding();
get_docs();

return doc;
}

module.exports = function (baseFolder) {
var defs = {};

Expand All @@ -303,5 +384,11 @@ module.exports = function (baseFolder) {
}
});

for (var n in defs) {
defs[n].declare.doc = parser_comment(defs[n].declare.comments);
for (var m in defs[n].members)
defs[n].members[m].doc = parser_comment(defs[n].members[m].comments);
}

return defs;
};

0 comments on commit bc58e63

Please sign in to comment.