Draft test shell with karma and jasmine

This commit is contained in:
knsv
2014-11-04 07:45:23 +01:00
parent d9b9288da9
commit 89093922ed
7 changed files with 29 additions and 75 deletions

View File

@@ -20,5 +20,9 @@
"bower_components",
"test",
"tests"
]
],
"devDependencies": {
"jasmine": "~2.0.4",
"requirejs": "~2.1.15"
}
}

View File

@@ -11,5 +11,5 @@ gulp.task('jison', function() {
gulp.task('shorthand', shell.task([
'echo hello',
'echo world',
'jison src/mermaid.jison -o src/mermaid.js'
'jison src/parser/mermaid.jison -o src/parser/mermaid.js'
]))

View File

@@ -12,6 +12,10 @@
"gulp": "~3.8.9",
"jison": "~0.4.15",
"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"
}
}

View File

@@ -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;}
;

View File

@@ -126,3 +126,8 @@ borderWidth: NUM UNIT
borderStyle: BORDER_STYLE
{$$ = $1;}
;
%%
define('parser/mermaid',function(){
return mermaid;
});

View File

@@ -306,7 +306,12 @@ parse: function parse(input) {
}
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 = ({

View File

@@ -2,17 +2,12 @@
//console.log(p.parse('#fcfcfc'));
//console.log(p.parse('background: #fcfcfc'));
//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;'));
@@ -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('A;'));
*/