Skip to content

Commit

Permalink
Fixes for issues #47 and #55 including new test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
knsv committed Dec 13, 2014
1 parent 728bd65 commit 3f3e23b
Show file tree
Hide file tree
Showing 11 changed files with 546 additions and 420 deletions.
367 changes: 191 additions & 176 deletions dist/mermaid.full.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/mermaid.full.min.js

Large diffs are not rendered by default.

367 changes: 191 additions & 176 deletions dist/mermaid.slim.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/mermaid.slim.min.js

Large diffs are not rendered by default.

23 changes: 11 additions & 12 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,30 @@ var paths = {

gulp.task('jison2', function() {
return gulp.src('./src/*.jison')
.pipe(jison({ moduleType: 'amd' }))
.pipe(jison({ moduleType: 'commonjs' }))
.pipe(gulp.dest('./src/parser'));
});

gulp.task('jison', shell.task([
'jison src/parser/flow.jison -o src/parser/flow.js',
'jison src/parser/dot.jison -o src/parser/dot.js',
'jison src/parser/js-sequence-diagram.jison -o src/parser/sequenceDiagram.js'
//'source scripts/compileJison.sh'
// 'jison src/parser/flow.jison -o src/parser/flow.js',
'jison src/diagrams/flowchart/parser/flow.jison -o src/diagrams/flowchart/parser/flow.js',
'jison src/diagrams/flowchart/parser/dot.jison -o src/diagrams/flowchart/parser/dot.js',
'jison src/diagrams/sequenceDiagram/parser/sequenceDiagram.jison -o src/diagrams/sequenceDiagram/parser/sequenceDiagram.js',
//'jison src/diagrams/sequenceDiagram/parser/sequence.jison -o src/diagrams/sequenceDiagram/parser/sequence.js'
]));

gulp.task('jisonSd', shell.task([
//'jison src/parser/flow.jison -o src/parser/flow.js',
'jison src/parser/sequence.jison -o src/parser/sequence.js'
//'source scripts/compileFlow.sh'
]));
gulp.task('jison2', function() {
return gulp.src('./src/diagrams/flowchart/**/*.jison')
.pipe(jison({ }))
.pipe(gulp.dest('./src/diagrams/flowchart'));
});

gulp.task('dist', ['slimDist', 'fullDist','jasmine']);

var jasmine = require('gulp-jasmine');

gulp.task('jasmine',['jison'], function () {
return gulp.src(['src/**/*.spec.js'])
.pipe(jasmine());
.pipe(jasmine({includeStackTrace:true}));
});

gulp.task('coverage', function (cb) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"lodash.values": "^2.4.1",
"mock-browser": "^0.90.27",
"path": "^0.4.9",
"phantomjs": "^1.9.12",
"rewire": "^2.1.3"
}
}
74 changes: 69 additions & 5 deletions src/diagrams/flowchart/parser/flow.jison
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ statements


spaceListNewline
: spaceList
: SPACE spaceListNewline
| NEWLINE spaceListNewline
| NEWLINE
| SPACE
;


Expand Down Expand Up @@ -243,11 +244,43 @@ text: textToken
{$$=$1+''+$2;}
;

textStatement: textToken
| textToken textStatement
textToken: ALPHA
{$$=$1;}
| NUM
{$$=$1;}
| COLON
{$$ = $1;}
| COMMA
{$$ = $1;}
| PLUS
{$$ = $1;}
| EQUALS
{$$ = $1;}
| MULT
{$$ = $1;}
| DOT
{$$ = $1;}
| TAGSTART
{$$ = $1;}
| TAGEND
{$$ = $1;}
| BRKT
{$$ = '<br>';}
| SPACE
{$$ = $1;}
| MINUS
{$$ = $1;}
| keywords
{$$ = $1;}
;

commentText: commentToken
{$$=$1;}
| commentText commentToken
{$$=$1+''+$2;}
;

textToken: ALPHA
commentToken: ALPHA
{$$=$1;}
| NUM
{$$=$1;}
Expand All @@ -269,13 +302,44 @@ textToken: ALPHA
{$$ = $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;

Expand Down Expand Up @@ -335,7 +399,7 @@ linkStyleStatement:
{$$ = $1;yy.updateLink($3,$5);}
;
commentStatement:
PCT PCT text
PCT PCT commentText
{$$ = $1;}
;
stylesOpt: style
Expand Down
88 changes: 44 additions & 44 deletions src/diagrams/flowchart/parser/flow.js

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions src/diagrams/flowchart/parser/flow.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;');

Expand Down
2 changes: 1 addition & 1 deletion src/diagrams/sequenceDiagram/sequence.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3f3e23b

Please sign in to comment.