mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +08:00
Removed warnings in the grammar oand some console logging
This commit is contained in:
parent
c0dd6f9e35
commit
c50a7533f6
@ -1,4 +1,5 @@
|
||||
import * as mindmapDB from './mindmapDb';
|
||||
import { setLogLevel } from '../../logger';
|
||||
|
||||
describe('when parsing a mindmap ', function () {
|
||||
let mindmap;
|
||||
@ -6,9 +7,10 @@ describe('when parsing a mindmap ', function () {
|
||||
mindmap = require('./parser/mindmap').parser;
|
||||
mindmap.yy = require('./mindmapDb');
|
||||
mindmap.yy.clear();
|
||||
setLogLevel('trace');
|
||||
});
|
||||
describe('hiearchy', function () {
|
||||
it('should handle a simple root definition', function () {
|
||||
it('MMP-1 should handle a simple root definition abc122', function () {
|
||||
let str = `mindmap
|
||||
root`;
|
||||
|
||||
@ -16,7 +18,7 @@ describe('when parsing a mindmap ', function () {
|
||||
// console.log('Time for checks', mindmap.yy.getMindmap().descr);
|
||||
expect(mindmap.yy.getMindmap().descr).toEqual('root');
|
||||
});
|
||||
it('should handle a hierachial mindmap definition', function () {
|
||||
it('MMP-2 should handle a hierachial mindmap definition', function () {
|
||||
let str = `mindmap
|
||||
root
|
||||
child1
|
||||
@ -31,7 +33,7 @@ describe('when parsing a mindmap ', function () {
|
||||
expect(mm.children[1].descr).toEqual('child2');
|
||||
});
|
||||
|
||||
it('should handle a simple root definition with a shape and without an id abc123', function () {
|
||||
it('3 should handle a simple root definition with a shape and without an id abc123', function () {
|
||||
let str = `mindmap
|
||||
(root)`;
|
||||
|
||||
@ -40,7 +42,7 @@ describe('when parsing a mindmap ', function () {
|
||||
expect(mindmap.yy.getMindmap().descr).toEqual('root');
|
||||
});
|
||||
|
||||
it('should handle a deeper hierachial mindmap definition', function () {
|
||||
it('MMP-4 should handle a deeper hierachial mindmap definition', function () {
|
||||
let str = `mindmap
|
||||
root
|
||||
child1
|
||||
@ -55,7 +57,7 @@ describe('when parsing a mindmap ', function () {
|
||||
expect(mm.children[0].children[0].descr).toEqual('leaf1');
|
||||
expect(mm.children[1].descr).toEqual('child2');
|
||||
});
|
||||
it('Multiple roots are illegal', function () {
|
||||
it('5 Multiple roots are illegal', function () {
|
||||
let str = `mindmap
|
||||
root
|
||||
fakeRoot`;
|
||||
@ -70,7 +72,7 @@ describe('when parsing a mindmap ', function () {
|
||||
);
|
||||
}
|
||||
});
|
||||
it('real root in wrong place', function () {
|
||||
it('MMP-6 real root in wrong place', function () {
|
||||
let str = `mindmap
|
||||
root
|
||||
fakeRoot
|
||||
@ -88,7 +90,7 @@ describe('when parsing a mindmap ', function () {
|
||||
});
|
||||
});
|
||||
describe('nodes', function () {
|
||||
it('should handle an id and type for a node definition', function () {
|
||||
it('MMP-7 should handle an id and type for a node definition', function () {
|
||||
let str = `mindmap
|
||||
root[The root]
|
||||
`;
|
||||
@ -99,7 +101,7 @@ describe('when parsing a mindmap ', function () {
|
||||
expect(mm.descr).toEqual('The root');
|
||||
expect(mm.type).toEqual(mindmap.yy.nodeType.RECT);
|
||||
});
|
||||
it('should handle an id and type for a node definition', function () {
|
||||
it('MMP-8 should handle an id and type for a node definition', function () {
|
||||
let str = `mindmap
|
||||
root
|
||||
theId(child1)`;
|
||||
@ -113,7 +115,7 @@ describe('when parsing a mindmap ', function () {
|
||||
expect(child.nodeId).toEqual('theId');
|
||||
expect(child.type).toEqual(mindmap.yy.nodeType.ROUNDED_RECT);
|
||||
});
|
||||
it('should handle an id and type for a node definition', function () {
|
||||
it('MMP-9 should handle an id and type for a node definition', function () {
|
||||
let str = `mindmap
|
||||
root
|
||||
theId(child1)`;
|
||||
@ -127,10 +129,10 @@ root
|
||||
expect(child.nodeId).toEqual('theId');
|
||||
expect(child.type).toEqual(mindmap.yy.nodeType.ROUNDED_RECT);
|
||||
});
|
||||
it('mutiple types (circle)', function () {
|
||||
it('MMP-10 mutiple types (circle)', function () {
|
||||
let str = `mindmap
|
||||
root((the root))
|
||||
`;
|
||||
`;
|
||||
|
||||
mindmap.parse(str);
|
||||
const mm = mindmap.yy.getMindmap();
|
||||
@ -139,7 +141,7 @@ root
|
||||
expect(mm.type).toEqual(mindmap.yy.nodeType.CIRCLE);
|
||||
});
|
||||
|
||||
it('mutiple types (cloud)', function () {
|
||||
it('MMP-11 mutiple types (cloud)', function () {
|
||||
let str = `mindmap
|
||||
root)the root(
|
||||
`;
|
||||
@ -150,7 +152,7 @@ root
|
||||
expect(mm.children.length).toEqual(0);
|
||||
expect(mm.type).toEqual(mindmap.yy.nodeType.CLOUD);
|
||||
});
|
||||
it('mutiple types (bang)', function () {
|
||||
it('MMP-12 mutiple types (bang)', function () {
|
||||
let str = `mindmap
|
||||
root))the root((
|
||||
`;
|
||||
@ -163,7 +165,7 @@ root
|
||||
});
|
||||
});
|
||||
describe('decorations', function () {
|
||||
it('should be possible to set an icon for the node', function () {
|
||||
it('MMP-13 should be possible to set an icon for the node', function () {
|
||||
let str = `mindmap
|
||||
root[The root]
|
||||
::icon(bomb)
|
||||
@ -177,7 +179,7 @@ root
|
||||
expect(mm.type).toEqual(mindmap.yy.nodeType.RECT);
|
||||
expect(mm.icon).toEqual('bomb');
|
||||
});
|
||||
it('should be possible to set classes for the node', function () {
|
||||
it('MMP-14 should be possible to set classes for the node', function () {
|
||||
let str = `mindmap
|
||||
root[The root]
|
||||
:::m-4 p-8
|
||||
@ -191,7 +193,7 @@ root
|
||||
expect(mm.type).toEqual(mindmap.yy.nodeType.RECT);
|
||||
expect(mm.class).toEqual('m-4 p-8');
|
||||
});
|
||||
it('should be possible to set both classes and icon for the node', function () {
|
||||
it('MMP-15 should be possible to set both classes and icon for the node', function () {
|
||||
let str = `mindmap
|
||||
root[The root]
|
||||
:::m-4 p-8
|
||||
@ -207,7 +209,7 @@ root
|
||||
expect(mm.class).toEqual('m-4 p-8');
|
||||
expect(mm.icon).toEqual('bomb');
|
||||
});
|
||||
it('should be possible to set both classes and icon for the node', function () {
|
||||
it('MMP-16 should be possible to set both classes and icon for the node', function () {
|
||||
let str = `mindmap
|
||||
root[The root]
|
||||
::icon(bomb)
|
||||
@ -225,7 +227,7 @@ root
|
||||
});
|
||||
});
|
||||
describe('descriptions', function () {
|
||||
it('should be possible to use node syntax in the descriptions', function () {
|
||||
it('MMP-17 should be possible to use node syntax in the descriptions', function () {
|
||||
let str = `mindmap
|
||||
root["String containing []"]
|
||||
`;
|
||||
@ -234,7 +236,7 @@ root
|
||||
expect(mm.nodeId).toEqual('root');
|
||||
expect(mm.descr).toEqual('String containing []');
|
||||
});
|
||||
it('should be possible to use node syntax in the descriptions in children', function () {
|
||||
it('MMP-18 should be possible to use node syntax in the descriptions in children', function () {
|
||||
let str = `mindmap
|
||||
root["String containing []"]
|
||||
child1["String containing ()"]
|
||||
@ -246,7 +248,7 @@ root
|
||||
expect(mm.children.length).toEqual(1);
|
||||
expect(mm.children[0].descr).toEqual('String containing ()');
|
||||
});
|
||||
it('should be possible to have a child after a class assignment', function () {
|
||||
it('MMP-19 should be possible to have a child after a class assignment', function () {
|
||||
let str = `mindmap
|
||||
root(Root)
|
||||
Child(Child)
|
||||
@ -266,7 +268,7 @@ root
|
||||
expect(child.children[1].nodeId).toEqual('b');
|
||||
});
|
||||
});
|
||||
it('should be possible to have meaningless empty rows in a mindmap abc124', function () {
|
||||
it('MMP-20 should be possible to have meaningless empty rows in a mindmap abc124', function () {
|
||||
let str = `mindmap
|
||||
root(Root)
|
||||
Child(Child)
|
||||
@ -285,7 +287,7 @@ root
|
||||
expect(child.children.length).toEqual(2);
|
||||
expect(child.children[1].nodeId).toEqual('b');
|
||||
});
|
||||
it('should be possible to have comments in a mindmap', function () {
|
||||
it('MMP-21 should be possible to have comments in a mindmap', function () {
|
||||
let str = `mindmap
|
||||
root(Root)
|
||||
Child(Child)
|
||||
@ -306,7 +308,7 @@ root
|
||||
expect(child.children[1].nodeId).toEqual('b');
|
||||
});
|
||||
|
||||
it('should be possible to have comments at the end of a line', function () {
|
||||
it('MMP-22 should be possible to have comments at the end of a line', function () {
|
||||
let str = `mindmap
|
||||
root(Root)
|
||||
Child(Child)
|
||||
|
@ -1,6 +1,6 @@
|
||||
/** Created by knut on 15-01-14. */
|
||||
import { sanitizeText, getConfig } from '../../diagram-api/diagramAPI';
|
||||
import { log } from '../../logger';
|
||||
import { log as _log } from '../../logger';
|
||||
|
||||
let nodes = [];
|
||||
let cnt = 0;
|
||||
@ -25,7 +25,7 @@ export const getMindmap = () => {
|
||||
return nodes.length > 0 ? nodes[0] : null;
|
||||
};
|
||||
export const addNode = (level, id, descr, type) => {
|
||||
console.info('addNode', level, id, descr, type);
|
||||
log.info('addNode', level, id, descr, type);
|
||||
const conf = getConfig();
|
||||
const node = {
|
||||
id: cnt++,
|
||||
@ -132,7 +132,8 @@ export const type2Str = (type) => {
|
||||
return 'no-border';
|
||||
}
|
||||
};
|
||||
|
||||
// Expose logger to grammar
|
||||
export const log = _log;
|
||||
export const getNodeById = (id) => nodes[id];
|
||||
export const getElementById = (id) => elements[id];
|
||||
// export default {
|
||||
|
@ -17,20 +17,21 @@
|
||||
|
||||
%%
|
||||
|
||||
\s*\%\%.*\n {console.log('Found comment',yytext);}
|
||||
\s*\%\%.* {yy.log.trace('Found comment',yytext);}
|
||||
// \%\%[^\n]*\n /* skip comments */
|
||||
"mindmap" return 'MINDMAP';
|
||||
":::" { this.begin('CLASS'); }
|
||||
<CLASS>.+ { this.popState();return 'CLASS'; }
|
||||
<CLASS>\n { this.popState();}
|
||||
[\n\s]*"::icon(" { this.begin('ICON'); }
|
||||
[\n]+ /* return 'NL'; */
|
||||
// [\s]*"::icon(" { this.begin('ICON'); }
|
||||
"::icon(" { yy.log.trace('Begin icon');this.begin('ICON'); }
|
||||
[\n]+ return 'NL';
|
||||
<ICON>[^\)]+ { return 'ICON'; }
|
||||
<ICON>\) {this.popState();}
|
||||
"-)" { console.log('Exploding node'); this.begin('NODE');return 'NODE_DSTART'; }
|
||||
"(-" { console.log('Cloud'); this.begin('NODE');return 'NODE_DSTART'; }
|
||||
"))" { console.log('Explosion Bang'); this.begin('NODE');return 'NODE_DSTART'; }
|
||||
")" { console.log('Cloud Bang'); this.begin('NODE');return 'NODE_DSTART'; }
|
||||
<ICON>\) {yy.log.trace('end icon');this.popState();}
|
||||
"-)" { yy.log.trace('Exploding node'); this.begin('NODE');return 'NODE_DSTART'; }
|
||||
"(-" { yy.log.trace('Cloud'); this.begin('NODE');return 'NODE_DSTART'; }
|
||||
"))" { yy.log.trace('Explosion Bang'); this.begin('NODE');return 'NODE_DSTART'; }
|
||||
")" { yy.log.trace('Cloud Bang'); this.begin('NODE');return 'NODE_DSTART'; }
|
||||
"((" { this.begin('NODE');return 'NODE_DSTART'; }
|
||||
"(" { this.begin('NODE');return 'NODE_DSTART'; }
|
||||
"[" { this.begin('NODE');return 'NODE_DSTART'; }
|
||||
@ -38,18 +39,18 @@
|
||||
// !(-\() return 'NODE_ID';
|
||||
[^\(\[\n\-\)]+ return 'NODE_ID';
|
||||
<<EOF>> return 'EOF';
|
||||
<NODE>["] { console.log('Starting NSTR');this.begin("NSTR");}
|
||||
<NSTR>[^"]+ { console.log('description:', yytext); return "NODE_DESCR";}
|
||||
<NODE>["] { yy.log.trace('Starting NSTR');this.begin("NSTR");}
|
||||
<NSTR>[^"]+ { yy.log.trace('description:', yytext); return "NODE_DESCR";}
|
||||
<NSTR>["] {this.popState();}
|
||||
<NODE>[\)]\) {this.popState();console.log('node end ))');return "NODE_DEND";}
|
||||
<NODE>[\)] {this.popState();console.log('node end )');return "NODE_DEND";}
|
||||
<NODE>[\]] {this.popState();console.log('node end ...');return "NODE_DEND";}
|
||||
<NODE>"(-" {this.popState();console.log('node end (-');return "NODE_DEND";}
|
||||
<NODE>"-)" {this.popState();console.log('node end (-');return "NODE_DEND";}
|
||||
<NODE>"((" {this.popState();console.log('node end ((');return "NODE_DEND";}
|
||||
<NODE>"(" {this.popState();console.log('node end ((');return "NODE_DEND";}
|
||||
<NODE>[^\)\]\(]+ { console.log('Long description:', yytext); return 'NODE_DESCR';}
|
||||
<NODE>.+(?!\(\() { console.log('Long description:', yytext); return 'NODE_DESCR';}
|
||||
<NODE>[\)]\) {this.popState();yy.log.trace('node end ))');return "NODE_DEND";}
|
||||
<NODE>[\)] {this.popState();yy.log.trace('node end )');return "NODE_DEND";}
|
||||
<NODE>[\]] {this.popState();yy.log.trace('node end ...',yytext);return "NODE_DEND";}
|
||||
<NODE>"(-" {this.popState();yy.log.trace('node end (-');return "NODE_DEND";}
|
||||
<NODE>"-)" {this.popState();yy.log.trace('node end (-');return "NODE_DEND";}
|
||||
<NODE>"((" {this.popState();yy.log.trace('node end ((');return "NODE_DEND";}
|
||||
<NODE>"(" {this.popState();yy.log.trace('node end ((');return "NODE_DEND";}
|
||||
<NODE>[^\)\]\(]+ { yy.log.trace('Long description:', yytext); return 'NODE_DESCR';}
|
||||
<NODE>.+(?!\(\() { yy.log.trace('Long description:', yytext); return 'NODE_DESCR';}
|
||||
// [\[] return 'NODE_START';
|
||||
// .+ return 'TXT' ;
|
||||
|
||||
@ -62,29 +63,33 @@
|
||||
start
|
||||
// %{ : info document 'EOF' { return yy; } }
|
||||
: MINDMAP document { return yy; }
|
||||
| MINDMAP NL document { return yy; }
|
||||
| SPACELIST MINDMAP document { return yy; }
|
||||
;
|
||||
|
||||
stop
|
||||
: NL {yy.log.trace('Stop NL ');}
|
||||
| EOF {yy.log.trace('Stop EOF ');}
|
||||
| stop NL {yy.log.trace('Stop NL2 ');}
|
||||
| stop EOF {yy.log.trace('Stop EOF2 ');}
|
||||
;
|
||||
document
|
||||
: document line
|
||||
| line
|
||||
;
|
||||
|
||||
line
|
||||
: statement { }
|
||||
: document statement stop
|
||||
| statement stop
|
||||
;
|
||||
|
||||
statement
|
||||
: SPACELIST node { yy.addNode($1.length, $2.id, $2.descr, $2.type); }
|
||||
| SPACELIST ICON { yy.decorateNode({icon: $2}); }
|
||||
| SPACELIST EOF
|
||||
| SPACELIST NL
|
||||
| node { console.log($1.id);yy.addNode(0, $1.id, $1.descr, $1.type); }
|
||||
: SPACELIST node { yy.log.trace('Node: ',$2.id);yy.addNode($1.length, $2.id, $2.descr, $2.type); }
|
||||
| SPACELIST ICON { yy.log.trace('Icon: ',$2);yy.decorateNode({icon: $2}); }
|
||||
| SPACELIST CLASS { yy.decorateNode({class: $2}); }
|
||||
| node { yy.log.trace('Node: ',$1.id);yy.addNode(0, $1.id, $1.descr, $1.type); }
|
||||
| ICON { yy.decorateNode({icon: $1}); }
|
||||
| SPACELIST CLASS { yy.decorateNode({class: $2}); }
|
||||
| CLASS { yy.decorateNode({class: $1}); }
|
||||
| EOF
|
||||
| CLASS { yy.decorateNode({class: $1}); }
|
||||
| SPACELIST
|
||||
;
|
||||
|
||||
|
||||
|
||||
node
|
||||
:nodeWithId
|
||||
|nodeWithoutId
|
||||
@ -92,12 +97,12 @@ node
|
||||
|
||||
nodeWithoutId
|
||||
: NODE_DSTART NODE_DESCR NODE_DEND
|
||||
{ console.log("node found ..", $1); $$ = { id: $2, descr: $2, type: yy.getType($1, $3) }; }
|
||||
{ yy.log.trace("node found ..", $1); $$ = { id: $2, descr: $2, type: yy.getType($1, $3) }; }
|
||||
;
|
||||
|
||||
nodeWithId
|
||||
: NODE_ID { $$ = { id: $1, descr: $1, type: yy.nodeType.DEFAULT }; }
|
||||
| NODE_ID NODE_DSTART NODE_DESCR NODE_DEND
|
||||
{ console.log("node found ..", $1); $$ = { id: $1, descr: $3, type: yy.getType($2, $4) }; }
|
||||
{ yy.log.trace("node found ..", $1); $$ = { id: $1, descr: $3, type: yy.getType($2, $4) }; }
|
||||
;
|
||||
%%
|
||||
|
Loading…
x
Reference in New Issue
Block a user