Integrating canopy (with a demo parser from the canopy docs)

This commit is contained in:
Jeff Avallone 2014-11-24 22:31:20 -05:00
parent fe06a99178
commit ba9b779ba7
8 changed files with 43 additions and 13 deletions

View File

@ -4,7 +4,7 @@
"other": "./src/**/*.!(html|scss|js)", "other": "./src/**/*.!(html|scss|js)",
"html": "./src/**/*.html", "html": "./src/**/*.html",
"sass": "./src/**/*.scss", "sass": "./src/**/*.scss",
"js": "./src/**/*.js", "js": ["./src/**/*.js", "./src/**/*.peg"],
"spec": "./spec/**/*_spec.js" "spec": "./spec/**/*_spec.js"
}, },
"compass": { "compass": {
@ -17,7 +17,6 @@
"browserify": { "browserify": {
"basedir": "./src/js", "basedir": "./src/js",
"debug": true, "debug": true,
"fullPaths": false, "fullPaths": false
"transform": ["es6ify"]
} }
} }

View File

@ -17,6 +17,8 @@ function browserifyPipe() {
var bundler = browserify(config.browserify); var bundler = browserify(config.browserify);
bundler.add([file.path, es6ify.runtime]); bundler.add([file.path, es6ify.runtime]);
bundler.transform(require('./lib/canopy-transform'));
bundler.transform(es6ify);
file.contents = bundler.bundle(); file.contents = bundler.bundle();
}); });

View File

@ -2,7 +2,7 @@ var _ = require('lodash'),
config = require('./config'); config = require('./config');
module.exports = function(karma) { module.exports = function(karma) {
var globs = [config.globs.js, config.globs.spec]; var globs = _.flatten([config.globs.js, config.globs.spec]);
karma.set({ karma.set({
frameworks: ['browserify', 'jasmine'], frameworks: ['browserify', 'jasmine'],
@ -19,7 +19,11 @@ module.exports = function(karma) {
singleRun: false, singleRun: false,
browserify: _.defaults({}, config.browserify, { browserify: _.defaults({}, config.browserify, {
prebundle: function(bundle) { prebundle: function(bundle) {
bundle.add([require('es6ify').runtime]); var es6ify = require('es6ify');
bundle.add([es6ify.runtime]);
bundle.transform(require('./lib/canopy-transform'));
bundle.transform(es6ify);
} }
}) })
}); });

24
lib/canopy-transform.js Normal file
View File

@ -0,0 +1,24 @@
var through = require('through'),
canopy = require('canopy');
module.exports = function(file) {
if (!/\.peg$/.test(file)) {
return through();
}
var data = '';
return through(
function(buf) {
data += buf;
},
function() {
try {
this.queue(String(canopy.compile(data)));
} catch(err) {
this.emit('error', err);
}
this.queue(null);
}
);
};

View File

@ -11,6 +11,7 @@
"private": true, "private": true,
"devDependencies": { "devDependencies": {
"browserify": "^6.3.2", "browserify": "^6.3.2",
"canopy": "^0.2.0",
"es6ify": "^1.5.1", "es6ify": "^1.5.1",
"gulp": "^3.8.10", "gulp": "^3.8.10",
"gulp-compass": "^2.0.3", "gulp-compass": "^2.0.3",
@ -25,6 +26,7 @@
"karma-jasmine": "^0.3.1", "karma-jasmine": "^0.3.1",
"karma-notify-reporter": "^0.1.1", "karma-notify-reporter": "^0.1.1",
"karma-phantomjs-launcher": "^0.1.4", "karma-phantomjs-launcher": "^0.1.4",
"lodash": "^2.4.1" "lodash": "^2.4.1",
"through": "^2.3.6"
} }
} }

View File

@ -1,5 +1,3 @@
import test from './test'; import parser from './parser.peg';
test('foo'); console.log('testing:', parser.parse('[0,1,2,3]'));
console.log('testing');

4
src/js/parser.peg Normal file
View File

@ -0,0 +1,4 @@
grammar Lists
value <- list / number
list <- "[" ( value ("," value)* )? "]"
number <- [0-9]

View File

@ -1,3 +0,0 @@
export default m => {
console.log(m);
};