Flow grammer is modified to allow each line ending without semicolon to improve readablity. The old declarations also work. One test is also included in flow.spec.js to test the changes.

This commit is contained in:
vijay40
2014-12-15 15:32:47 +05:30
parent 13a65db40e
commit 3279edab33
3 changed files with 84 additions and 43 deletions

View File

@@ -120,13 +120,20 @@
expressions
: graphConfig statements EOF
| graphConfig statements
| graphConfig spaceListNewline statements EOF
{$$=$1;}
| graphConfig spaceListNewline statements
{$$=$1;}
;
graphConfig
: GRAPH SPACE DIR SEMI
{ yy.setDirection($3);$$ = $3;}
| GRAPH SPACE DIR NEWLINE
{ yy.setDirection($3);$$ = $3;}
| GRAPH SPACE DIR spaceList NEWLINE
{ yy.setDirection($3);$$ = $3;}
;
statements
@@ -152,11 +159,23 @@ statement
: commentStatement NEWLINE
{$$='Comment';}
| verticeStatement SEMI
| verticeStatement NEWLINE
| verticeStatement EOF
| styleStatement SEMI
| styleStatement NEWLINE
| styleStatement EOF
| linkStyleStatement SEMI
| linkStyleStatement NEWLINE
| linkStyleStatement EOF
| classDefStatement SEMI
| classDefStatement NEWLINE
| classDefStatement EOF
| classStatement SEMI
| classStatement NEWLINE
| classStatement EOF
| clickStatement SEMI
| clickStatement NEWLINE
| clickStatement EOF
;
verticeStatement:

File diff suppressed because one or more lines are too long

View File

@@ -46,6 +46,22 @@ describe('when parsing ',function(){
expect(edges[0].text).toBe('');
});
it('should handle a nodes and edges, a space between link and node and each line ending without semicolon',function(){
var res = flow.parser.parse('graph TD\nA --> B\n style e red');
var vert = flow.parser.yy.getVertices();
var edges = flow.parser.yy.getEdges();
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 comments',function(){
var res = flow.parser.parse('graph TD;\n%% CComment\n A-->B;');