Fixes for issues #47 and #55 including new test cases.

This commit is contained in:
knsv
2014-12-13 08:42:40 +01:00
parent 728bd656d7
commit 3f3e23b419
11 changed files with 545 additions and 419 deletions

View File

@@ -136,9 +136,10 @@ statements
spaceListNewline
: spaceList
: SPACE spaceListNewline
| NEWLINE spaceListNewline
| NEWLINE
| SPACE
;
@@ -243,10 +244,6 @@ text: textToken
{$$=$1+''+$2;}
;
textStatement: textToken
| textToken textStatement
;
textToken: ALPHA
{$$=$1;}
| NUM
@@ -276,6 +273,73 @@ textToken: ALPHA
| keywords
{$$ = $1;}
;
commentText: commentToken
{$$=$1;}
| commentText commentToken
{$$=$1+''+$2;}
;
commentToken: ALPHA
{$$=$1;}
| NUM
{$$=$1;}
| COLON
{$$ = $1;}
| COMMA
{$$ = $1;}
| PLUS
{$$ = $1;}
| EQUALS
{$$ = $1;}
| MULT
{$$ = $1;}
| DOT
{$$ = $1;}
| TAGSTART
{$$ = $1;}
| TAGEND
{$$ = $1;}
| BRKT
{$$ = '<br>';}
| PIPE
{$$ = '<br>';}
| PS
{$$ = '<br>';}
| PE
{$$ = '<br>';}
| SQS
{$$ = '<br>';}
| SQE
{$$ = '<br>';}
| DIAMOND_START
{$$ = '<br>';}
| DIAMOND_STOP
{$$ = '<br>';}
| TAG_START
{$$ = '<br>';}
| TAG_END
{$$ = '<br>';}
| ARROW_CROSS
{$$ = '<br>';}
| ARROW_POINT
{$$ = '<br>';}
| ARROW_CIRCLE
{$$ = '<br>';}
| ARROW_OPEN
{$$ = '<br>';}
| QUOTE
{$$ = '<br>';}
| SPACE
{$$ = $1;}
| MINUS
{$$ = $1;}
| SEMI
{$$ = $1;}
| keywords
{$$ = $1;}
;
keywords
: STYLE | LINKSTYLE | CLASSDEF | CLASS | CLICK | GRAPH | DIR;
@@ -335,7 +399,7 @@ linkStyleStatement:
{$$ = $1;yy.updateLink($3,$5);}
;
commentStatement:
PCT PCT text
PCT PCT commentText
{$$ = $1;}
;
stylesOpt: style

File diff suppressed because one or more lines are too long

View File

@@ -62,6 +62,38 @@ describe('when parsing ',function(){
expect(edges[0].text).toBe('');
});
it('should handle a comments mermaid flowchart code in them',function(){
var res = flow.parser.parse('graph TD;\n\n\n %% Test od>Odd shape]-->|Two line<br>edge comment|ro;\n A-->B;');
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('it should handle a trailing whitespaces after statememnts',function(){
var res = flow.parser.parse('graph TD;\n\n\n %% CComment\n A-->B; \nB-->C;');
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(2);
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 open ended edges',function(){
var res = flow.parser.parse('graph TD;A---B;');

View File

@@ -24,7 +24,7 @@ str = str + 'bfs:someNode.setLevel';
//console.log(sq.parse(str));
describe('when parsing ',function() {
describe('when parsing a sequence it',function() {
var parseError;
beforeEach(function () {
sq = require('./parser/sequence').parser;