mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-21 01:06:43 +02:00
Draft test shell with karma and jasmine
This commit is contained in:
@@ -20,5 +20,9 @@
|
|||||||
"bower_components",
|
"bower_components",
|
||||||
"test",
|
"test",
|
||||||
"tests"
|
"tests"
|
||||||
]
|
],
|
||||||
|
"devDependencies": {
|
||||||
|
"jasmine": "~2.0.4",
|
||||||
|
"requirejs": "~2.1.15"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,5 +11,5 @@ gulp.task('jison', function() {
|
|||||||
gulp.task('shorthand', shell.task([
|
gulp.task('shorthand', shell.task([
|
||||||
'echo hello',
|
'echo hello',
|
||||||
'echo world',
|
'echo world',
|
||||||
'jison src/mermaid.jison -o src/mermaid.js'
|
'jison src/parser/mermaid.jison -o src/parser/mermaid.js'
|
||||||
]))
|
]))
|
@@ -12,6 +12,10 @@
|
|||||||
"gulp": "~3.8.9",
|
"gulp": "~3.8.9",
|
||||||
"jison": "~0.4.15",
|
"jison": "~0.4.15",
|
||||||
"jasmine": "~2.0.1",
|
"jasmine": "~2.0.1",
|
||||||
"gulp-jison": "~1.0.0"
|
"gulp-jison": "~1.0.0",
|
||||||
|
"karma": "~0.12.20",
|
||||||
|
"karma-jasmine": "~0.2.1",
|
||||||
|
"karma-chrome-launcher": "~0.1.5",
|
||||||
|
"karma-requirejs": "~0.2.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,60 +0,0 @@
|
|||||||
/* description: Parses end executes mathematical expressions. */
|
|
||||||
|
|
||||||
/* lexical grammar */
|
|
||||||
%lex
|
|
||||||
|
|
||||||
%%
|
|
||||||
\s+ /* skip whitespace */
|
|
||||||
[0-9]+("."[0-9]+)?\b return 'NUMBER';
|
|
||||||
\#[a-f0-9]+ return 'HEX';
|
|
||||||
"*" return '*';
|
|
||||||
"/" return '/';
|
|
||||||
"-" return '-';
|
|
||||||
"+" return '+';
|
|
||||||
"^" return '^';
|
|
||||||
"(" return '(';
|
|
||||||
")" return ')';
|
|
||||||
"PI" return 'PI';
|
|
||||||
"E" return 'E';
|
|
||||||
<<EOF>> return 'EOF';
|
|
||||||
|
|
||||||
/lex
|
|
||||||
|
|
||||||
/* operator associations and precedence */
|
|
||||||
|
|
||||||
%left '+' '-'
|
|
||||||
%left '*' '/'
|
|
||||||
%left '^'
|
|
||||||
%left UMINUS
|
|
||||||
|
|
||||||
%start expressions
|
|
||||||
|
|
||||||
%% /* language grammar */
|
|
||||||
|
|
||||||
expressions
|
|
||||||
: e EOF
|
|
||||||
{console.log($1); return $1;}
|
|
||||||
;
|
|
||||||
|
|
||||||
e
|
|
||||||
: e '+' e
|
|
||||||
{$$ = $1+$3;}
|
|
||||||
| e '-' e
|
|
||||||
{$$ = $1-$3;}
|
|
||||||
| e '*' e
|
|
||||||
{$$ = $1*$3;}
|
|
||||||
| e '/' e
|
|
||||||
{$$ = $1/$3;}
|
|
||||||
| e '^' e
|
|
||||||
{$$ = Math.pow($1, $3);}
|
|
||||||
| '-' e %prec UMINUS
|
|
||||||
{$$ = -$2;}
|
|
||||||
| '(' e ')'
|
|
||||||
{$$ = $2;}
|
|
||||||
| NUMBER
|
|
||||||
{$$ = Number(yytext);}
|
|
||||||
| E
|
|
||||||
{$$ = Math.E;}
|
|
||||||
| PI
|
|
||||||
{$$ = Math.PI;}
|
|
||||||
;
|
|
@@ -126,3 +126,8 @@ borderWidth: NUM UNIT
|
|||||||
borderStyle: BORDER_STYLE
|
borderStyle: BORDER_STYLE
|
||||||
{$$ = $1;}
|
{$$ = $1;}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
%%
|
||||||
|
define('parser/mermaid',function(){
|
||||||
|
return mermaid;
|
||||||
|
});
|
@@ -306,7 +306,12 @@ parse: function parse(input) {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}};
|
}};
|
||||||
/* generated by jison-lex 0.3.4 */
|
|
||||||
|
define('parser/mermaid.js',function(){
|
||||||
|
//var parserSource = generator.generate({moduleName: "mermaid"});
|
||||||
|
//return marserSource;
|
||||||
|
return parser;
|
||||||
|
});/* generated by jison-lex 0.3.4 */
|
||||||
var lexer = (function(){
|
var lexer = (function(){
|
||||||
var lexer = ({
|
var lexer = ({
|
||||||
|
|
16
src/test.js
16
src/test.js
@@ -2,17 +2,12 @@
|
|||||||
//console.log(p.parse('#fcfcfc'));
|
//console.log(p.parse('#fcfcfc'));
|
||||||
//console.log(p.parse('background: #fcfcfc'));
|
//console.log(p.parse('background: #fcfcfc'));
|
||||||
//console.log(p.parse('background: black'));
|
//console.log(p.parse('background: black'));
|
||||||
var scope={
|
//
|
||||||
addVertex:function(id,text,type,style){
|
|
||||||
console.log('Got node '+id+' '+type+' '+text+' styles: '+JSON.stringify(style));
|
|
||||||
},
|
|
||||||
addLink:function(start,end,type,linktext){
|
|
||||||
console.log('Got link from '+start+' to '+end+' type:'+type.type+' linktext:'+linktext);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var p = require('./mermaid.js');
|
|
||||||
p.parser.yy = scope;
|
/*
|
||||||
|
var p = require('./parser/mermaid.js');
|
||||||
|
p.parser.yy = require('./parser/scope');
|
||||||
|
|
||||||
|
|
||||||
console.log(p.parse('A-->B;'));
|
console.log(p.parse('A-->B;'));
|
||||||
@@ -32,3 +27,4 @@ console.log(p.parse('style R background:#fff,border:1px solid red;'));
|
|||||||
console.log(p.parse('style S background:#aaa;\nstyle T background:#bbb,border:1px solid red;'));
|
console.log(p.parse('style S background:#aaa;\nstyle T background:#bbb,border:1px solid red;'));
|
||||||
//console.log(p.parse('A;'));
|
//console.log(p.parse('A;'));
|
||||||
|
|
||||||
|
*/
|
Reference in New Issue
Block a user