diff --git a/bower.json b/bower.json index b039d1997..9d7abe6a3 100644 --- a/bower.json +++ b/bower.json @@ -20,5 +20,9 @@ "bower_components", "test", "tests" - ] + ], + "devDependencies": { + "jasmine": "~2.0.4", + "requirejs": "~2.1.15" + } } diff --git a/gulpfile.js b/gulpfile.js index b939e9c72..ec19f4052 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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' ])) \ No newline at end of file diff --git a/package.json b/package.json index 3bf155ccd..1a0d21c01 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/src/calc.jison b/src/calc.jison deleted file mode 100644 index 9d1a56ce1..000000000 --- a/src/calc.jison +++ /dev/null @@ -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'; -<> 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;} - ; \ No newline at end of file diff --git a/src/mermaid.jison b/src/parser/mermaid.jison similarity index 97% rename from src/mermaid.jison rename to src/parser/mermaid.jison index fef905e61..19f10badf 100644 --- a/src/mermaid.jison +++ b/src/parser/mermaid.jison @@ -125,4 +125,9 @@ borderWidth: NUM UNIT borderStyle: BORDER_STYLE {$$ = $1;} - ; \ No newline at end of file + ; + +%% +define('parser/mermaid',function(){ + return mermaid; +}); \ No newline at end of file diff --git a/src/mermaid.js b/src/parser/mermaid.js similarity index 99% rename from src/mermaid.js rename to src/parser/mermaid.js index 4113287ab..9204698d9 100644 --- a/src/mermaid.js +++ b/src/parser/mermaid.js @@ -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 = ({ diff --git a/src/test.js b/src/test.js index a9654fee0..d77cfce43 100644 --- a/src/test.js +++ b/src/test.js @@ -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;')); +*/ \ No newline at end of file