added grammar

This commit is contained in:
Christian Klemm 2019-10-04 21:49:02 +02:00
parent 96735dd543
commit 912e850db4
No known key found for this signature in database
GPG Key ID: 57578469FC907C48
5 changed files with 18 additions and 8 deletions

View File

@ -98,6 +98,7 @@ Class01 : size()
Class01 : int chimp
Class01 : int gorilla
Class08 <--> C2: Cool label
<<interface>> Class01
```
![Class diagram](./img/class.png)

1
dist/index.html vendored
View File

@ -411,6 +411,7 @@ Class01 : size()
Class01 : int chimp
Class01 : int gorilla
Class08 <--> C2: Cool label
&lt;&lt;interface&gt;&gt; Class01
</div>
<script src="./mermaid.js"></script>
<script>

View File

@ -44,6 +44,10 @@ export const addRelation = function(relation) {
relations.push(relation);
};
export const addAnnotation = function(className, annotation) {
classes[className].annotations.push(annotation);
};
export const addMember = function(className, member) {
const theClass = classes[className];
if (typeof member === 'string') {
@ -86,6 +90,7 @@ export default {
clear,
getClass,
getClasses,
addAnnotation,
getRelations,
addRelation,
addMember,

View File

@ -264,9 +264,6 @@ const drawClass = function(elem, classDef) {
.attr('y', conf.textHeight + conf.padding)
.attr('x', 0);
// TODO: remove testing code
classDef.annotations = ['interface', 'injected'];
// add annotations
let isFirst = true;
classDef.annotations.forEach(function(member) {
@ -276,11 +273,12 @@ const drawClass = function(elem, classDef) {
});
// add class title
title
const classTitle = title
.append('tspan')
.text(classDef.id)
.attr('class', 'title')
.attr('dy', conf.textHeight);
.attr('class', 'title');
if (!isFirst) classTitle.attr('dy', conf.textHeight);
const titleHeight = title.node().getBBox().height;
@ -334,7 +332,6 @@ const drawClass = function(elem, classDef) {
// Center title
title.node().childNodes.forEach(function(x) {
console.dir(x.getBBox());
x.setAttribute('x', (classBox.width + 2 * conf.padding - x.getBBox().width) / 2);
});

View File

@ -21,6 +21,8 @@
"class" return 'CLASS';
"<<" return 'ANNOTATION_START';
">>" return 'ANNOTATION_END';
["] this.begin("string");
<string>["] this.popState();
<string>[^"]* return "STR";
@ -131,7 +133,6 @@ statements
| statement NEWLINE statements
;
className
: alphaNumToken className { $$=$1+$2; }
| alphaNumToken { $$=$1; }
@ -142,6 +143,7 @@ statement
| relationStatement LABEL { $1.title = yy.cleanupLabel($2); yy.addRelation($1); }
| classStatement
| methodStatement
| annotationStatement
;
classStatement
@ -149,6 +151,10 @@ classStatement
| CLASS className STRUCT_START members STRUCT_STOP {/*console.log($2,JSON.stringify($4));*/yy.addClass($2);yy.addMembers($2,$4);}
;
annotationStatement
: ANNOTATION_START alphaNumToken ANNOTATION_END className { yy.addAnnotation($4,$2); }
;
members
: MEMBER { $$ = [$1]; }
| MEMBER members { $2.push($1);$$=$2;}