Skip to content

Commit

Permalink
Support for åäö and minus in text
Browse files Browse the repository at this point in the history
  • Loading branch information
knsv committed Nov 12, 2014
1 parent d158a13 commit e7cb84b
Show file tree
Hide file tree
Showing 13 changed files with 3,134 additions and 37 deletions.
5 changes: 5 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ gulp.task('jison2', function() {
gulp.task('jison', shell.task([
'jison src/parser/mermaid.jison -o src/parser/mermaid.js',
'source scripts/compileJison.sh'
]))

gulp.task('jison2', shell.task([
'jison src/parser/flow.jison -o src/parser/flow.js',
'source scripts/compileFlow.sh'
]))
8 changes: 6 additions & 2 deletions src/init.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

/*
require.config({
// Karma serves files from '/base'
baseUrl: './'
Expand All @@ -7,4 +7,8 @@ require.config({
require(['mermaid'],function(mermaid){
mermaid.init();
});
});
*/

console.log('Init running');
2 changes: 1 addition & 1 deletion src/mermaid.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

.node rect {
stroke: #999;
fill: #fff;
fill: #f99;
stroke-width: 1.5px;
}

Expand Down
18 changes: 7 additions & 11 deletions src/mermaid.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,15 @@ define('mermaid',['parser/graph','parser/mermaid'],function(graph,parser){


if(style === ''){
style = graph.defaultStyle();
//style = graph.defaultStyle();
}

console.log('g.setNode("'+vertice.id+'", { label: "'+verticeText+'" });');
if(vertice.type==='round'){
g.setNode(vertice.id, { label: verticeText,rx:5,ry:5,style:style });
}else{
if(vertice.type==='diamond'){
//g.setNode(vertice.id, {shape: "house", label: verticeText,rx:0,ry:0,style: "fill:#ffa;stroke: #f66; stroke-width: 3px; stroke-dasharray: 5, 5;fill:#ffa;stroke: #666;" });
g.setNode(vertice.id, {shape: "house", label: verticeText,rx:0,ry:0,style: style });
g.setNode(vertice.id, {shape: "question", label: verticeText,rx:0,ry:0,style: style });
}else{
g.setNode(vertice.id, { label: verticeText,rx:0,ry:0,style:style });
}
Expand Down Expand Up @@ -93,16 +92,11 @@ define('mermaid',['parser/graph','parser/mermaid'],function(graph,parser){
addVertices(vert,g);
addEdges(edges,g);

/*g.nodes().forEach(function(v) {
var node = g.node(v);
// Round the corners of the nodes
node.rx = node.ry = 5;
});
*/
// Create the renderer
var render = new dagreD3.render();
// Add our custom shape (a house)
render.shapes().house = function(parent, bbox, node) {

// Add our custom shape
render.shapes().question = function(parent, bbox, node) {
var w = bbox.width,
h = bbox.height*3,
points = [
Expand All @@ -115,6 +109,8 @@ define('mermaid',['parser/graph','parser/mermaid'],function(graph,parser){
.attr("points", points.map(function(d) { return d.x + "," + d.y; }).join(" "))
.style("fill", "#fff")
.style("stroke", "#333")
.attr("rx", 5)
.attr("ry", 5)
.attr("transform", "translate(" + (-w/2) + "," + (h * 2/4) + ")");
node.intersect = function(point) {
return dagreD3.intersect.polygon(node, points, point);
Expand Down
69 changes: 69 additions & 0 deletions src/parser/flow.jison
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* description: Parses end executes mathematical expressions. */

/* lexical grammar */
%lex

%%
"style" return 'STYLE';
[a-zåäöæøA-ZÅÄÖÆØ]+ return 'ALPHA';
\#[a-f0-9]+ return 'HEX';
[0-9]+ return 'NUM';
"px" return 'UNIT';
"pt" return 'UNIT';
"dot" return 'UNIT';
":" return 'COLON';
\- return 'MINUS';
";" return ';';
"," return 'COMMA';
[x] return 'ARROW_CROSS';
">" return 'ARROW_POINT';
[o] return 'ARROW_CIRCLE';
"|" return 'PIPE';
"(" return 'PS';
")" return 'PE';
"[" return 'SQS';
"]" return 'SQE';
"{" return 'DIAMOND_START'
"}" return 'DIAMOND_STOP'
\s return 'SPACE';
\n return 'NEWLINE';
<<EOF>> return 'EOF';

/lex

/* operator associations and precedence */

%left '^'

%start expressions

%% /* language grammar */

expressions
: id EOF
{return $1;}
;

flow: id
{$$='key';}
| STYLE
{$$=$1;}
;

id: id MINUS word
{$$=$1+'-'+$3}
| word
{$$=$1}
;

word: ALPHA
{$$=$1}
;



%%
define('parser/flow',function(){
console.log('bcs123');
return parser;
});
Loading

0 comments on commit e7cb84b

Please sign in to comment.