mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-25 18:30:10 +02:00
1st version parsing for class diagrams
This commit is contained in:
@@ -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);
|
||||||
|
};
|
@@ -145,12 +145,12 @@ statement
|
|||||||
|
|
||||||
classStatement
|
classStatement
|
||||||
: CLASS className
|
: 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
|
members
|
||||||
: MEMBER { return $1; }
|
: MEMBER { $$ = [$1]; }
|
||||||
| MEMBER members { /*console.log('member: ',$1);*/}
|
| MEMBER members { $2.push($1);$$=$2;}
|
||||||
;
|
;
|
||||||
|
|
||||||
methodStatement
|
methodStatement
|
||||||
|
@@ -93,13 +93,13 @@ case 8:
|
|||||||
/*console.log('Label found',$$[$0]);*/
|
/*console.log('Label found',$$[$0]);*/
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 12:
|
||||||
/*console.log($$[$0-3]);*/
|
console.log($$[$0-3],JSON.stringify($$[$0-1]));
|
||||||
break;
|
break;
|
||||||
case 13:
|
case 13:
|
||||||
return $$[$0];
|
this.$ = [$$[$0]];
|
||||||
break;
|
break;
|
||||||
case 14:
|
case 14:
|
||||||
/*console.log('member: ',$$[$0-1]);*/
|
$$[$0].push($$[$0-1]);this.$=$$[$0];
|
||||||
break;
|
break;
|
||||||
case 15:
|
case 15:
|
||||||
/*console.log('Rel found',$$[$0]);*/
|
/*console.log('Rel found',$$[$0]);*/
|
||||||
|
Reference in New Issue
Block a user