1st version parsing for class diagrams

This commit is contained in:
knsv
2015-10-26 08:03:30 +01:00
parent dd6495abf6
commit 1a60b6e412
3 changed files with 73 additions and 6 deletions

View File

@@ -0,0 +1,67 @@
import * as Logger from '../../logger';
var log = new Logger.Log();
var relations = [];
var classes = {};
// Functions to be run after graph rendering
var funs = [];
/**
* Function called by parser when a node definition has been found
* @param id
* @param text
* @param type
* @param style
*/
exports.addClass = function (id, text, type, style) {
var txt;
if(typeof id === 'undefined'){
return;
}
if(id.trim().length === 0){
return;
}
if (typeof vertices[id] === 'undefined') {
vertices[id] = {id: id, styles: [], classes:[]};
}
if (typeof text !== 'undefined') {
txt = text.trim();
// strip quotes if string starts and exnds with a quote
if(txt[0] === '"' && txt[txt.length-1] === '"'){
txt = txt.substring(1,txt.length-1);
}
vertices[id].text = txt;
}
if (typeof type !== 'undefined') {
vertices[id].type = type;
}
if (typeof type !== 'undefined') {
vertices[id].type = type;
}
if (typeof style !== 'undefined') {
if (style !== null) {
style.forEach(function (s) {
vertices[id].styles.push(s);
});
}
}
};
exports.addRelation = function (id1, id2, type1, type2, relationTitle1, relationTitle2, title) {
log.debug('Got edge', start, end);
var edge = {
id1: id1,
id2: id2,
type1: type1,
type2: type2,
relationTitle1:relationTitle1,
relationTitle2:relationTitle2,
title:title
};
relations.push(edge);
};

View File

@@ -145,12 +145,12 @@ statement
classStatement
: CLASS className
| CLASS className STRUCT_START members STRUCT_STOP {/*console.log($2);*/}
| CLASS className STRUCT_START members STRUCT_STOP {/*console.log($2,JSON.stringify($4));*/yy.addMembers();}
;
members
: MEMBER { return $1; }
| MEMBER members { /*console.log('member: ',$1);*/}
: MEMBER { $$ = [$1]; }
| MEMBER members { $2.push($1);$$=$2;}
;
methodStatement

View File

@@ -93,13 +93,13 @@ case 8:
/*console.log('Label found',$$[$0]);*/
break;
case 12:
/*console.log($$[$0-3]);*/
console.log($$[$0-3],JSON.stringify($$[$0-1]));
break;
case 13:
return $$[$0];
this.$ = [$$[$0]];
break;
case 14:
/*console.log('member: ',$$[$0-1]);*/
$$[$0].push($$[$0-1]);this.$=$$[$0];
break;
case 15:
/*console.log('Rel found',$$[$0]);*/