mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-18 06:49:47 +02:00
#834 Using space as separator, simplfifying the grammar some more, reomving some logging
This commit is contained in:
@@ -498,7 +498,6 @@ export const indexNodes = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getSubGraphs = function() {
|
export const getSubGraphs = function() {
|
||||||
console.warn(subGraphs);
|
|
||||||
return subGraphs;
|
return subGraphs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -22,6 +22,16 @@ describe('[Singlenodes] when parsing', () => {
|
|||||||
expect(edges.length).toBe(0);
|
expect(edges.length).toBe(0);
|
||||||
expect(vert['A'].styles.length).toBe(0);
|
expect(vert['A'].styles.length).toBe(0);
|
||||||
});
|
});
|
||||||
|
it('should handle a single node with white space after it (SN1)', function() {
|
||||||
|
// Silly but syntactically correct
|
||||||
|
const res = flow.parser.parse('graph TD;A ;');
|
||||||
|
|
||||||
|
const vert = flow.parser.yy.getVertices();
|
||||||
|
const edges = flow.parser.yy.getEdges();
|
||||||
|
|
||||||
|
expect(edges.length).toBe(0);
|
||||||
|
expect(vert['A'].styles.length).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
it('should handle a single square node', function() {
|
it('should handle a single square node', function() {
|
||||||
// Silly but syntactically correct
|
// Silly but syntactically correct
|
||||||
|
@@ -20,7 +20,6 @@
|
|||||||
"interpolate" return 'INTERPOLATE';
|
"interpolate" return 'INTERPOLATE';
|
||||||
"classDef" return 'CLASSDEF';
|
"classDef" return 'CLASSDEF';
|
||||||
"class" return 'CLASS';
|
"class" return 'CLASS';
|
||||||
"EPA" return 'EPA';
|
|
||||||
"click" return 'CLICK';
|
"click" return 'CLICK';
|
||||||
"graph" {if(yy.lex.firstGraph()){this.begin("dir");} return 'GRAPH';}
|
"graph" {if(yy.lex.firstGraph()){this.begin("dir");} return 'GRAPH';}
|
||||||
"subgraph" return 'subgraph';
|
"subgraph" return 'subgraph';
|
||||||
@@ -250,7 +249,7 @@ spaceList
|
|||||||
|
|
||||||
statement
|
statement
|
||||||
: verticeStatement separator
|
: verticeStatement separator
|
||||||
{ console.warn('finat vs', $1.nodes); $$=$1.nodes}
|
{ /* console.warn('finat vs', $1.nodes); */ $$=$1.nodes}
|
||||||
| styleStatement separator
|
| styleStatement separator
|
||||||
{$$=[];}
|
{$$=[];}
|
||||||
| linkStyleStatement separator
|
| linkStyleStatement separator
|
||||||
@@ -289,74 +288,48 @@ separator: NEWLINE | SEMI | EOF ;
|
|||||||
// ;
|
// ;
|
||||||
|
|
||||||
|
|
||||||
verticeStatement: verticeStatement link node { console.warn('vs',$1.stmt,$3); yy.addLink($1.stmt,$3,$2); $$ = { stmt: $3, nodes: $3.concat($1.nodes) } }
|
verticeStatement: verticeStatement link node
|
||||||
|node {console.warn('noda', $1); $$ = {stmt: $1, nodes:$1 }}
|
{ /* console.warn('vs',$1.stmt,$3); */ yy.addLink($1.stmt,$3,$2); $$ = { stmt: $3, nodes: $3.concat($1.nodes) } }
|
||||||
|
| verticeStatement link node spaceList
|
||||||
|
{ /* console.warn('vs',$1.stmt,$3); */ yy.addLink($1.stmt,$3,$2); $$ = { stmt: $3, nodes: $3.concat($1.nodes) } }
|
||||||
|
|node spaceList {/*console.warn('noda', $1);*/ $$ = {stmt: $1, nodes:$1 }}
|
||||||
|
|node { /*console.warn('noda', $1);*/ $$ = {stmt: $1, nodes:$1 }}
|
||||||
;
|
;
|
||||||
|
|
||||||
node: vertex
|
node: vertex
|
||||||
{ console.warn('nod', $1);$$ = [$1];}
|
{ /* console.warn('nod', $1); */ $$ = [$1];}
|
||||||
| node PIPE vertex
|
| node spaceList vertex
|
||||||
{ $$ = [$1[0], $3]; console.warn('pip', $1, $3, $$); }
|
{ $$ = [$1[0], $3]; /*console.warn('pip', $1, $3, $$);*/ }
|
||||||
| vertex STYLE_SEPARATOR idString
|
| vertex STYLE_SEPARATOR idString
|
||||||
{$$ = [$1];yy.setClass($1,$3)}
|
{$$ = [$1];yy.setClass($1,$3)}
|
||||||
;
|
;
|
||||||
|
|
||||||
vertex: idString SQS text SQE
|
vertex: idString SQS text SQE
|
||||||
{$$ = $1;yy.addVertex($1,$3,'square');}
|
{$$ = $1;yy.addVertex($1,$3,'square');}
|
||||||
| idString SQS text SQE spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1,$3,'square');}
|
|
||||||
| idString PS PS text PE PE
|
| idString PS PS text PE PE
|
||||||
{$$ = $1;yy.addVertex($1,$4,'circle');}
|
{$$ = $1;yy.addVertex($1,$4,'circle');}
|
||||||
| idString PS PS text PE PE spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1,$4,'circle');}
|
|
||||||
| idString '(-' text '-)'
|
| idString '(-' text '-)'
|
||||||
{$$ = $1;yy.addVertex($1,$3,'ellipse');}
|
{$$ = $1;yy.addVertex($1,$3,'ellipse');}
|
||||||
| idString '(-' text '-)' spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1,$3,'ellipse');}
|
|
||||||
| idString STADIUMSTART text STADIUMEND
|
| idString STADIUMSTART text STADIUMEND
|
||||||
{$$ = $1;yy.addVertex($1,$3,'stadium');}
|
{$$ = $1;yy.addVertex($1,$3,'stadium');}
|
||||||
| idString STADIUMSTART text STADIUMEND spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1,$3,'stadium');}
|
|
||||||
| idString PS text PE
|
| idString PS text PE
|
||||||
{$$ = $1;yy.addVertex($1,$3,'round');}
|
{$$ = $1;yy.addVertex($1,$3,'round');}
|
||||||
| idString PS text PE spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1,$3,'round');}
|
|
||||||
| idString DIAMOND_START text DIAMOND_STOP
|
| idString DIAMOND_START text DIAMOND_STOP
|
||||||
{$$ = $1;yy.addVertex($1,$3,'diamond');}
|
{$$ = $1;yy.addVertex($1,$3,'diamond');}
|
||||||
| idString DIAMOND_START text DIAMOND_STOP spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1,$3,'diamond');}
|
|
||||||
| idString DIAMOND_START DIAMOND_START text DIAMOND_STOP DIAMOND_STOP
|
| idString DIAMOND_START DIAMOND_START text DIAMOND_STOP DIAMOND_STOP
|
||||||
{$$ = $1;yy.addVertex($1,$4,'hexagon');}
|
{$$ = $1;yy.addVertex($1,$4,'hexagon');}
|
||||||
| idString DIAMOND_START DIAMOND_START text DIAMOND_STOP DIAMOND_STOP spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1,$4,'hexagon');}
|
|
||||||
| idString TAGEND text SQE
|
| idString TAGEND text SQE
|
||||||
{$$ = $1;yy.addVertex($1,$3,'odd');}
|
{$$ = $1;yy.addVertex($1,$3,'odd');}
|
||||||
| idString TAGEND text SQE spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1,$3,'odd');}
|
|
||||||
| idString TRAPSTART text TRAPEND
|
| idString TRAPSTART text TRAPEND
|
||||||
{$$ = $1;yy.addVertex($1,$3,'trapezoid');}
|
{$$ = $1;yy.addVertex($1,$3,'trapezoid');}
|
||||||
| idString TRAPSTART text TRAPEND spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1,$3,'trapezoid');}
|
|
||||||
| idString INVTRAPSTART text INVTRAPEND
|
| idString INVTRAPSTART text INVTRAPEND
|
||||||
{$$ = $1;yy.addVertex($1,$3,'inv_trapezoid');}
|
{$$ = $1;yy.addVertex($1,$3,'inv_trapezoid');}
|
||||||
| idString INVTRAPSTART text INVTRAPEND spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1,$3,'inv_trapezoid');}
|
|
||||||
| idString TRAPSTART text INVTRAPEND
|
| idString TRAPSTART text INVTRAPEND
|
||||||
{$$ = $1;yy.addVertex($1,$3,'lean_right');}
|
{$$ = $1;yy.addVertex($1,$3,'lean_right');}
|
||||||
| idString TRAPSTART text INVTRAPEND spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1,$3,'lean_right');}
|
|
||||||
| idString INVTRAPSTART text TRAPEND
|
| idString INVTRAPSTART text TRAPEND
|
||||||
{$$ = $1;yy.addVertex($1,$3,'lean_left');}
|
{$$ = $1;yy.addVertex($1,$3,'lean_left');}
|
||||||
| idString INVTRAPSTART text TRAPEND spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1,$3,'lean_left');}
|
|
||||||
/* | idString SQS text TAGSTART
|
|
||||||
{$$ = $1;yy.addVertex($1,$3,'odd_right');}
|
|
||||||
| idString SQS text TAGSTART spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1,$3,'odd_right');} */
|
|
||||||
| idString
|
| idString
|
||||||
{console.warn('h: ', $1);$$ = $1;yy.addVertex($1);}
|
{ /*console.warn('h: ', $1);*/$$ = $1;yy.addVertex($1);}
|
||||||
| idString spaceList
|
|
||||||
{$$ = $1;yy.addVertex($1);}
|
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
|
@@ -192,6 +192,15 @@ describe('when parsing subgraphs', function() {
|
|||||||
expect(edges[0].type).toBe('arrow');
|
expect(edges[0].type).toBe('arrow');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle subgraphs3', function() {
|
||||||
|
const res = flow.parser.parse('graph TD\nA-->B\nsubgraph myTitle \n\n c-->d \nend\n');
|
||||||
|
|
||||||
|
const vert = flow.parser.yy.getVertices();
|
||||||
|
const edges = flow.parser.yy.getEdges();
|
||||||
|
|
||||||
|
expect(edges[0].type).toBe('arrow');
|
||||||
|
});
|
||||||
|
|
||||||
it('should handle nested subgraphs', function() {
|
it('should handle nested subgraphs', function() {
|
||||||
const str =
|
const str =
|
||||||
'graph TD\n' +
|
'graph TD\n' +
|
||||||
|
@@ -49,7 +49,7 @@ line
|
|||||||
|
|
||||||
statement
|
statement
|
||||||
: STR VALUE {
|
: STR VALUE {
|
||||||
console.log('str:'+$1+' value: '+$2)
|
/*console.log('str:'+$1+' value: '+$2)*/
|
||||||
yy.addSection($1,yy.cleanupValue($2)); }
|
yy.addSection($1,yy.cleanupValue($2)); }
|
||||||
| title {yy.setTitle($1.substr(6));$$=$1.substr(6);}
|
| title {yy.setTitle($1.substr(6));$$=$1.substr(6);}
|
||||||
;
|
;
|
||||||
|
Reference in New Issue
Block a user