diff --git a/MJLite.js b/MJLite.js index 57164ee61..500ab115a 100644 --- a/MJLite.js +++ b/MJLite.js @@ -1,4 +1,4 @@ -var parser = require("./parser"); +var parser = require("./parser.jison"); var buildExpression = function(expression) { return _.map(expression, function(ex, i) { diff --git a/Makefile b/Makefile index 61c5138f9..3cafbc891 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ FILES=parser.js style.css build.js index.html -.PHONY: build ship copy watch +.PHONY: build ship copy server build: parser.js ship: build @@ -14,5 +14,5 @@ copy: build parser.js: parser.jison ./node_modules/.bin/jison parser.jison -watch: - ./node_modules/.bin/watchify MJLite.js --standalone MJLite -o build/MJLite.js +server: + node server.js diff --git a/build/.gitkeep b/build/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/jisonify.js b/jisonify.js new file mode 100644 index 000000000..f3c3c7ff3 --- /dev/null +++ b/jisonify.js @@ -0,0 +1,31 @@ +var ebnfParser = require("ebnf-parser"); +var jison = require("jison"); +var through = require("through"); + +module.exports = function(file) { + if (!(/\.jison$/).test(file)) { + return through(); + } + + var data = ''; + return through(write, end); + + function write(buf) { + data += buf; + } + + function end() { + try { + var grammar = ebnfParser.parse(data); + var parser = new jison.Parser(grammar); + var js = parser.generate({moduleType: "js"}); + js += "\nmodule.exports = parser;"; + + this.queue(js); + this.queue(null); + } catch (e) { + // TODO(alpert): Does this do anything? (Is it useful?) + this.emit("error", e); + } + } +}; diff --git a/package.json b/package.json index c390017b1..d73d01761 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,11 @@ "name": "mjlite", "version": "0.0.1", "devDependencies": { + "browserify": "~2.23.1", + "ebnf-parser": "~0.1.5", + "express": "~3.3.3", + "lex-parser": "~0.1.2", "jison": "~0.4.6", - "watchify": "~0.1.0" + "through": "~2.3.4" } } diff --git a/server.js b/server.js new file mode 100644 index 000000000..47a439591 --- /dev/null +++ b/server.js @@ -0,0 +1,29 @@ +var path = require("path"); + +var browserify = require("browserify"); +var express = require("express"); + +var jisonify = require("./jisonify"); + +var app = express(); + +app.use(express.logger()); + +app.get("/MJLite.js", function(req, res) { + var b = browserify(); + b.add("./MJLite"); + b.transform(jisonify); + + var stream = b.bundle({standalone: "MJLite"}); + var body = ""; + stream.on("data", function(s) { body += s; }); + stream.on("end", function() { + res.setHeader("Content-Type", "text/javascript"); + res.send(body); + }); +}); + +app.use(express.static(path.join(__dirname, 'static'))); + +app.listen(7936); +console.log("Serving on http://0.0.0.0:7936/ ..."); diff --git a/index.html b/static/index.html similarity index 86% rename from index.html rename to static/index.html index 56c1747d0..ff71de492 100644 --- a/index.html +++ b/static/index.html @@ -3,7 +3,7 @@