Permalink
Browse files

Generate parser at prepublish time

  • Loading branch information...
1 parent 2d08df7 commit 238a65ff0ab59a8523c2e991c8bb912c80d91563 @squaremo committed Oct 9, 2013
Showing with 20 additions and 21 deletions.
  1. +1 −0 .gitignore
  2. +8 −8 Makefile
  3. +4 −9 lib/parse.js
  4. +7 −4 package.json
View
@@ -1,2 +1,3 @@
*~
node_modules/
+lib/parser.js
View
@@ -1,11 +1,11 @@
-.PHONY: test
+.PHONY: test all
-# Current node leaks a variable 'val' in Buffer.readInt16LE
-GLOBALS_IGNORE=val
+GRAMMAR=lib/grammar.pegjs
-node_modules/mocha: node_modules/%:
- -mkdir -p node_modules
- npm install $(@F)
+all: lib/parser.js
-test: node_modules/mocha
- ./node_modules/.bin/mocha -R list --globals $(GLOBALS_IGNORE) -u tdd
+lib/parser.js:
+ ./node_modules/pegjs/bin/pegjs $(GRAMMAR) $@
+
+test: lib/parser.js
+ ./node_modules/.bin/mocha -R list -u tdd
View
@@ -1,13 +1,8 @@
// Parse patterns in string form into the form we use for interpreting
// (and later, for compiling).
-var peg = require('pegjs'),
-ast = require('./pattern'),
-path = require('path');
-
-var grammar = require('fs').readFileSync(
- path.join(path.dirname(module.filename), 'grammar.pegjs')).toString();
-var parser = peg.buildParser(grammar);
+var ast = require('./pattern');
+var parser = require('./parser');
function parse_pattern(string) {
var segments = parser.parse(string);
@@ -29,7 +24,7 @@ function parse_pattern(string) {
return segments;
}
-module.exports.parse = function(str) {
- str = (arguments.length > 1) ? [].join.call(arguments, ',') : str;
+module.exports.parse = function() {
+ var str = [].join.call(arguments, ',');
return parse_pattern(str);
};
View
@@ -12,14 +12,17 @@
},
"main": "./index",
"scripts": {
- "test": "make test"
+ "test": "make test",
+ "prepublish": "make all"
},
"engines": {
"node": ">=0.6"
},
"dependencies": {
- "pegjs": "~0.7",
- "buffer-more-ints": ""
+ "buffer-more-ints": "0.0.1"
},
- "devDependencies": {}
+ "devDependencies": {
+ "pegjs": "0.7.x",
+ "mocha": "0.9.x"
+ }
}

0 comments on commit 238a65f

Please sign in to comment.