initi.doc/templates/initi/static/scripts/parse_complex_type.js

90 lines
2.1 KiB
JavaScript

/**
* Created by Aleksey Chichenkov <a.chichenkov@initi.ru> on 9/20/18.
*/
var helper = require('jsdoc/util/templateHelper');
// var linkto = helper.linkto;
var test_0 = "v2.map(v2.map(v2.string, v2.list(v2.integer)), v2.list(v2.pair(v2.list(v2.map(v2.map(v2.string, v2.list(v2.integer)), v2.list(v2.pair(v2.string, v2.vc)))), v2.vc)))";
var test_1 = "v2.map(v2.map(v2.string, v2.list(v2.integer)), v2.list(v2.pair(v2.string, v2.vc)))";
var test_2 = "v2.string";
var test_3 = "v2.string()";
var test_4 = "v2.string(v2.map)";
var split_args = function (_str) {
var delta = 0;
var found = 0;
for (var a = 0; a < _str.length; a++) {
var char = _str[a];
switch (char) {
case "(":
delta++;
break;
case ")":
delta--;
break;
case ",":
found = delta == 0;
break;
}
if (found) break;
}
if (found) {
var left = _str.substring(0, a);
var right = _str.substring(a + 1, _str.length);
return [left, right]
}
return [_str];
};
var recursive = function (_str, _class, _alias) {
var _id = _str.replace(" ", "");
var rx = /(.*?)\((.*)\)/im;
var res = _id.match(rx);
if(res == null) return helper.linkto(_id, (_alias ? _alias : _id), _class);
//if (res == null) return _id;
var first = res[1];
var second = res[2];
var result = helper.linkto(first, _alias, _class);
//var result = first;
if (second === "") return result;
var args = split_args(second);
result += "(";
if (args[0]) result += recursive(args[0], _class);
if (args[1]){
result += ", ";
result += recursive(args[1], _class);
}
result += ")";
return result;
};
var linkto = function (_id, _alias, _class) {
//console.log(_id, _alias)
// ns.longname, ns.name, "menu-title"
// remove all whitespaces
var res = recursive(_id, _class, _alias);
//console.log("result")
//console.log(res)
// /_id.match(rx);
return res;
};
module.exports = {
linkto: linkto
};