Merge pull request #66 from vijay40/master
Allow special symbols for direction along with acronyms
This commit is contained in:
commit
8fa47dac37
|
@ -26,6 +26,8 @@
|
|||
"." return 'DOT';
|
||||
"<" return 'TAGSTART';
|
||||
">" return 'TAGEND';
|
||||
"^" return 'UP'
|
||||
"v" return 'DOWN'
|
||||
\-\-[x] return 'ARROW_CROSS';
|
||||
\-\-\> return 'ARROW_POINT';
|
||||
\-\-[o] return 'ARROW_CIRCLE';
|
||||
|
@ -128,14 +130,21 @@ expressions
|
|||
;
|
||||
|
||||
graphConfig
|
||||
: GRAPH SPACE DIR SEMI
|
||||
{ yy.setDirection($3);$$ = $3;}
|
||||
| GRAPH SPACE DIR NEWLINE
|
||||
{ yy.setDirection($3);$$ = $3;}
|
||||
| GRAPH SPACE DIR spaceList NEWLINE
|
||||
: GRAPH SPACE DIR FirstStmtSeperator
|
||||
{ yy.setDirection($3);$$ = $3;}
|
||||
| GRAPH SPACE TAGEND FirstStmtSeperator
|
||||
{ yy.setDirection("LR");$$ = $3;}
|
||||
| GRAPH SPACE TAGSTART FirstStmtSeperator
|
||||
{ yy.setDirection("RL");$$ = $3;}
|
||||
| GRAPH SPACE UP FirstStmtSeperator
|
||||
{ yy.setDirection("BT");$$ = $3;}
|
||||
| GRAPH SPACE DOWN FirstStmtSeperator
|
||||
{ yy.setDirection("TB");$$ = $3;}
|
||||
;
|
||||
|
||||
FirstStmtSeperator
|
||||
: SEMI | NEWLINE | spaceList NEWLINE ;
|
||||
|
||||
statements
|
||||
: statement spaceListNewline statements
|
||||
| statement statements
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -30,6 +30,84 @@ describe('when parsing ',function(){
|
|||
expect(edges[0].text).toBe('');
|
||||
});
|
||||
|
||||
it('should handle angle bracket '>' as direction LR',function(){
|
||||
var res = flow.parser.parse('graph >;A-->B;');
|
||||
|
||||
|
||||
var vert = flow.parser.yy.getVertices();
|
||||
var edges = flow.parser.yy.getEdges();
|
||||
var direction = flow.parser.yy.getDirection();
|
||||
|
||||
expect(direction).toBe('LR');
|
||||
|
||||
expect(vert['A'].id).toBe('A');
|
||||
expect(vert['B'].id).toBe('B');
|
||||
expect(edges.length).toBe(1);
|
||||
expect(edges[0].start).toBe('A');
|
||||
expect(edges[0].end).toBe('B');
|
||||
expect(edges[0].type).toBe('arrow');
|
||||
expect(edges[0].text).toBe('');
|
||||
});
|
||||
|
||||
it('should handle angle bracket '<' as direction RL',function(){
|
||||
var res = flow.parser.parse('graph <;A-->B;');
|
||||
|
||||
|
||||
var vert = flow.parser.yy.getVertices();
|
||||
var edges = flow.parser.yy.getEdges();
|
||||
var direction = flow.parser.yy.getDirection();
|
||||
|
||||
expect(direction).toBe('RL');
|
||||
|
||||
expect(vert['A'].id).toBe('A');
|
||||
expect(vert['B'].id).toBe('B');
|
||||
expect(edges.length).toBe(1);
|
||||
expect(edges[0].start).toBe('A');
|
||||
expect(edges[0].end).toBe('B');
|
||||
expect(edges[0].type).toBe('arrow');
|
||||
expect(edges[0].text).toBe('');
|
||||
});
|
||||
|
||||
|
||||
it('should handle caret '^' as direction BT',function(){
|
||||
var res = flow.parser.parse('graph ^;A-->B;');
|
||||
|
||||
|
||||
var vert = flow.parser.yy.getVertices();
|
||||
var edges = flow.parser.yy.getEdges();
|
||||
var direction = flow.parser.yy.getDirection();
|
||||
|
||||
expect(direction).toBe('BT');
|
||||
|
||||
expect(vert['A'].id).toBe('A');
|
||||
expect(vert['B'].id).toBe('B');
|
||||
expect(edges.length).toBe(1);
|
||||
expect(edges[0].start).toBe('A');
|
||||
expect(edges[0].end).toBe('B');
|
||||
expect(edges[0].type).toBe('arrow');
|
||||
expect(edges[0].text).toBe('');
|
||||
});
|
||||
|
||||
|
||||
it('should handle lower-case \'v\' as direction TB',function(){
|
||||
var res = flow.parser.parse('graph v;A-->B;');
|
||||
|
||||
|
||||
var vert = flow.parser.yy.getVertices();
|
||||
var edges = flow.parser.yy.getEdges();
|
||||
var direction = flow.parser.yy.getDirection();
|
||||
|
||||
expect(direction).toBe('TB');
|
||||
|
||||
expect(vert['A'].id).toBe('A');
|
||||
expect(vert['B'].id).toBe('B');
|
||||
expect(edges.length).toBe(1);
|
||||
expect(edges[0].start).toBe('A');
|
||||
expect(edges[0].end).toBe('B');
|
||||
expect(edges[0].type).toBe('arrow');
|
||||
expect(edges[0].text).toBe('');
|
||||
});
|
||||
|
||||
it('should handle a nodes and edges and a space between link and node',function(){
|
||||
var res = flow.parser.parse('graph TD;A --> B;');
|
||||
|
||||
|
|
Loading…
Reference in New Issue