Browse Source

Git repo npmization: Make the repo a npm package

Includes:

  * Moving the source code from /src to /lib.
  * Adding an explicit file list to package.json
  * Updating the Makefile.
  * Updating the spec and benchmark suites and their READMEs.

Part of a fix for GH-32.
redux
David Majda 10 years ago
parent
commit
0519d7e3ce
  1. 3
      .gitignore
  2. 163
      Makefile
  3. 29
      benchmark/README
  4. 2
      benchmark/index.html
  5. 0
      lib/compiler.js
  6. 0
      lib/compiler/passes.js
  7. 0
      lib/compiler/passes/allocate-registers.js
  8. 0
      lib/compiler/passes/generate-code.js
  9. 0
      lib/compiler/passes/remove-proxy-rules.js
  10. 0
      lib/compiler/passes/report-left-recursion.js
  11. 0
      lib/compiler/passes/report-missing-rules.js
  12. 0
      lib/grammar-error.js
  13. 0
      lib/parser.js
  14. 0
      lib/peg.js
  15. 0
      lib/utils.js
  16. 23
      package.json
  17. 29
      spec/README
  18. 2
      spec/index.html

3
.gitignore

@ -1,2 +1 @@
lib/*
dist/*
browser/*

163
Makefile

@ -20,31 +20,21 @@ MODULES = utils \
# ===== Directories =====
SRC_DIR = src
LIB_DIR = lib
BIN_DIR = bin
BROWSER_DIR = browser
SPEC_DIR = spec
BENCHMARK_DIR = benchmark
EXAMPLES_DIR = examples
LIB_DIR = lib
DIST_DIR = dist
DIST_WEB_DIR = $(DIST_DIR)/web
DIST_NODE_DIR = $(DIST_DIR)/node
# ===== Files =====
PARSER_SRC_FILE = $(SRC_DIR)/parser.pegjs
PARSER_OUT_FILE = $(SRC_DIR)/parser.js
PARSER_OUT_FILE = $(LIB_DIR)/parser.js
PEGJS_SRC_FILE = $(SRC_DIR)/peg.js
PEGJS_LIB_FILE = $(LIB_DIR)/peg.js
BROWSER_FILE_DEV = $(BROWSER_DIR)/peg-$(PEGJS_VERSION).js
BROWSER_FILE_MIN = $(BROWSER_DIR)/peg-$(PEGJS_VERSION).min.js
PEGJS_DIST_FILE_DEV = $(DIST_WEB_DIR)/peg-$(PEGJS_VERSION).js
PEGJS_DIST_FILE_MIN = $(DIST_WEB_DIR)/peg-$(PEGJS_VERSION).min.js
PACKAGE_JSON_FILE = package.json
CHANGELOG_FILE = CHANGELOG
LICENSE_FILE = LICENSE
README_FILE = README.md
VERSION_FILE = VERSION
VERSION_FILE = VERSION
# ===== Executables =====
@ -56,107 +46,86 @@ BENCHMARK_RUN = $(BENCHMARK_DIR)/run
# ===== Targets =====
# Default target
all: browser
# Generate the grammar parser
parser:
$(PEGJS) $(PARSER_SRC_FILE) $(PARSER_OUT_FILE)
# Build the PEG.js library
build:
mkdir -p $(LIB_DIR)
rm -f $(PEGJS_LIB_FILE)
# Build the browser version of the library
browser:
mkdir -p $(BROWSER_DIR)
rm -f $(BROWSER_FILE_DEV)
rm -f $(BROWSER_FILE_MIN)
# The following code is inspired by CoffeeScript's Cakefile.
echo '/*' >> $(PEGJS_LIB_FILE)
echo " * PEG.js $(PEGJS_VERSION)" >> $(PEGJS_LIB_FILE)
echo ' *' >> $(PEGJS_LIB_FILE)
echo ' * http://pegjs.majda.cz/' >> $(PEGJS_LIB_FILE)
echo ' *' >> $(PEGJS_LIB_FILE)
echo ' * Copyright (c) 2010-2012 David Majda' >> $(PEGJS_LIB_FILE)
echo ' * Licensed under the MIT license' >> $(PEGJS_LIB_FILE)
echo ' */' >> $(PEGJS_LIB_FILE)
echo 'var PEG = (function(undefined) {' >> $(PEGJS_LIB_FILE)
echo ' var modules = {' >> $(PEGJS_LIB_FILE)
echo ' define: function(name, factory) {' >> $(PEGJS_LIB_FILE)
echo ' var dir = name.replace(/(^|\/)[^/]+$$/, "$$1"),' >> $(PEGJS_LIB_FILE)
echo ' module = { exports: {} };' >> $(PEGJS_LIB_FILE)
echo '' >> $(PEGJS_LIB_FILE)
echo ' function require(path) {' >> $(PEGJS_LIB_FILE)
echo ' var name = dir + path,' >> $(PEGJS_LIB_FILE)
echo ' regexp = /[^\/]+\/\.\.\/|\.\//;' >> $(PEGJS_LIB_FILE)
echo '' >> $(PEGJS_LIB_FILE)
echo " /* Can't use /.../g because we can move backwards in the string. */" >> $(PEGJS_LIB_FILE)
echo ' while (regexp.test(name)) {' >> $(PEGJS_LIB_FILE)
echo ' name = name.replace(regexp, "");' >> $(PEGJS_LIB_FILE)
echo ' }' >> $(PEGJS_LIB_FILE)
echo '' >> $(PEGJS_LIB_FILE)
echo ' return modules[name];' >> $(PEGJS_LIB_FILE)
echo ' }' >> $(PEGJS_LIB_FILE)
echo '' >> $(PEGJS_LIB_FILE)
echo ' factory(module, require);' >> $(PEGJS_LIB_FILE)
echo ' this[name] = module.exports;' >> $(PEGJS_LIB_FILE)
echo ' }' >> $(PEGJS_LIB_FILE)
echo ' };' >> $(PEGJS_LIB_FILE)
echo '' >> $(PEGJS_LIB_FILE)
for module in $(MODULES); do \
echo " modules.define(\"$$module\", function(module, require) {" >> $(PEGJS_LIB_FILE); \
sed -e 's/^/ /' src/$$module.js >> $(PEGJS_LIB_FILE); \
echo ' });' >> $(PEGJS_LIB_FILE); \
echo '' >> $(PEGJS_LIB_FILE); \
echo '/*' >> $(BROWSER_FILE_DEV)
echo " * PEG.js $(PEGJS_VERSION)" >> $(BROWSER_FILE_DEV)
echo ' *' >> $(BROWSER_FILE_DEV)
echo ' * http://pegjs.majda.cz/' >> $(BROWSER_FILE_DEV)
echo ' *' >> $(BROWSER_FILE_DEV)
echo ' * Copyright (c) 2010-2012 David Majda' >> $(BROWSER_FILE_DEV)
echo ' * Licensed under the MIT license' >> $(BROWSER_FILE_DEV)
echo ' */' >> $(BROWSER_FILE_DEV)
echo 'var PEG = (function(undefined) {' >> $(BROWSER_FILE_DEV)
echo ' var modules = {' >> $(BROWSER_FILE_DEV)
echo ' define: function(name, factory) {' >> $(BROWSER_FILE_DEV)
echo ' var dir = name.replace(/(^|\/)[^/]+$$/, "$$1"),' >> $(BROWSER_FILE_DEV)
echo ' module = { exports: {} };' >> $(BROWSER_FILE_DEV)
echo '' >> $(BROWSER_FILE_DEV)
echo ' function require(path) {' >> $(BROWSER_FILE_DEV)
echo ' var name = dir + path,' >> $(BROWSER_FILE_DEV)
echo ' regexp = /[^\/]+\/\.\.\/|\.\//;' >> $(BROWSER_FILE_DEV)
echo '' >> $(BROWSER_FILE_DEV)
echo " /* Can't use /.../g because we can move backwards in the string. */" >> $(BROWSER_FILE_DEV)
echo ' while (regexp.test(name)) {' >> $(BROWSER_FILE_DEV)
echo ' name = name.replace(regexp, "");' >> $(BROWSER_FILE_DEV)
echo ' }' >> $(BROWSER_FILE_DEV)
echo '' >> $(BROWSER_FILE_DEV)
echo ' return modules[name];' >> $(BROWSER_FILE_DEV)
echo ' }' >> $(BROWSER_FILE_DEV)
echo '' >> $(BROWSER_FILE_DEV)
echo ' factory(module, require);' >> $(BROWSER_FILE_DEV)
echo ' this[name] = module.exports;' >> $(BROWSER_FILE_DEV)
echo ' }' >> $(BROWSER_FILE_DEV)
echo ' };' >> $(BROWSER_FILE_DEV)
echo '' >> $(BROWSER_FILE_DEV)
for module in $(MODULES); do \
echo " modules.define(\"$$module\", function(module, require) {" >> $(BROWSER_FILE_DEV); \
sed -e 's/^/ /' lib/$$module.js >> $(BROWSER_FILE_DEV); \
echo ' });' >> $(BROWSER_FILE_DEV); \
echo '' >> $(BROWSER_FILE_DEV); \
done
echo ' return modules["peg"]' >> $(PEGJS_LIB_FILE)
echo '})();' >> $(PEGJS_LIB_FILE)
echo '' >> $(PEGJS_LIB_FILE)
echo 'if (typeof module !== "undefined") {' >> $(PEGJS_LIB_FILE)
echo ' module.exports = PEG;' >> $(PEGJS_LIB_FILE)
echo '}' >> $(PEGJS_LIB_FILE)
# Remove built PEG.js library (created by "build")
clean:
rm -rf $(LIB_DIR)
# Prepare dstribution files
dist: build
# Web
mkdir -p $(DIST_WEB_DIR)
cp $(PEGJS_LIB_FILE) $(PEGJS_DIST_FILE_DEV)
$(UGLIFYJS) --ascii -o $(PEGJS_DIST_FILE_MIN) $(PEGJS_LIB_FILE)
# Node.js
mkdir -p $(DIST_NODE_DIR)
cp -r \
$(LIB_DIR) \
$(BIN_DIR) \
$(EXAMPLES_DIR) \
$(PACKAGE_JSON_FILE) \
$(CHANGELOG_FILE) \
$(LICENSE_FILE) \
$(README_FILE) \
$(VERSION_FILE) \
$(DIST_NODE_DIR)
# Remove distribution file (created by "dist")
distclean:
rm -rf $(DIST_DIR)
echo ' return modules["peg"]' >> $(BROWSER_FILE_DEV)
echo '})();' >> $(BROWSER_FILE_DEV)
$(UGLIFYJS) --ascii -o $(BROWSER_FILE_MIN) $(BROWSER_FILE_DEV)
# Remove browser version of the library (created by "browser")
browserclean:
rm -rf $(BROWSER_DIR)
# Run the spec suite
spec: build
spec:
$(JASMINE_NODE) --verbose $(SPEC_DIR)
# Run the benchmark suite
benchmark: build
benchmark:
$(BENCHMARK_RUN)
# Run JSHint on the source
hint: build
hint:
$(JSHINT) \
`find $(SRC_DIR) -name '*.js'` \
`find $(LIB_DIR) -name '*.js'` \
`find $(SPEC_DIR) -name '*.js' -and -not -path '$(SPEC_DIR)/vendor/*'` \
$(BENCHMARK_DIR)/*.js \
$(BENCHMARK_RUN) \
$(PEGJS)
.PHONY: spec benchmark hint parser build clean dist distclean
.SILENT: spec benchmark hint parser build clean dist distclean
.PHONY: all parser browser browserclean spec benchmark hint
.SILENT: all parser browser browserclean spec benchmark hint

29
benchmark/README

@ -8,27 +8,36 @@ optimization.
Running in a browser
--------------------
1. Start a web server and make it serve the PEG.js root directory (one level
up from this one).
1. Make sure you have Node.js and all the development dependencies specified
in package.json installed.
2. Point your browser to an URL corresponding to the index.html file.
2. Run the following command in the PEG.js root directory (one level up from
this one):
3. Wait for the table to fill.
make browser
3. Start a web server and make it serve the PEG.js root directory.
4. Point your browser to an URL corresponding to the index.html file.
5. Click the "Run" button and wait for the table to fill.
If you have Python installed, you can just run the following command in the
PEG.js root directory
If you have Python installed, you can fulfill steps 3 and 4 by running the
following command in the PEG.js root directory
python -m SimpleHTTPServer
and load http://localhost:8000/benchmark/ in your browser.
and load http://localhost:8000/benchmark/index.html in your browser.
Running from a command-line
---------------------------
1. Make sure you have Node.js installed.
1. Make sure you have Node.js and all the development dependencies specified
in package.json installed.
2. Run the following command:
2. Run the following command in the PEG.js root directory (one level up from
this one):
./run
make benchmark
3. Wait for the table to fill.

2
benchmark/index.html

@ -30,7 +30,7 @@
</tr>
</table>
<script src="../lib/peg.js"></script>
<script src="../browser/peg-0.7.0.js"></script>
<script src="vendor/jquery/jquery.js"></script>
<script src="vendor/jquery.scrollto/jquery.scrollTo.js"></script>
<script src="benchmarks.js"></script>

0
src/compiler.js → lib/compiler.js

0
src/compiler/passes.js → lib/compiler/passes.js

0
src/compiler/passes/allocate-registers.js → lib/compiler/passes/allocate-registers.js

0
src/compiler/passes/generate-code.js → lib/compiler/passes/generate-code.js

0
src/compiler/passes/remove-proxy-rules.js → lib/compiler/passes/remove-proxy-rules.js

0
src/compiler/passes/report-left-recursion.js → lib/compiler/passes/report-left-recursion.js

0
src/compiler/passes/report-missing-rules.js → lib/compiler/passes/report-missing-rules.js

0
src/grammar-error.js → lib/grammar-error.js

0
src/parser.js → lib/parser.js

0
src/peg.js → lib/peg.js

0
src/utils.js → lib/utils.js

23
package.json

@ -8,6 +8,29 @@
"email": "david@majda.cz",
"url": "http://majda.cz/"
},
"files": [
"CHANGELOG",
"LICENSE",
"README.md",
"VERSION",
"bin/pegjs",
"examples/arithmetics.pegjs",
"examples/css.pegjs",
"examples/javascript.pegjs",
"examples/json.pegjs",
"lib/compiler.js",
"lib/compiler/passes.js",
"lib/compiler/passes/allocate-registers.js",
"lib/compiler/passes/generate-code.js",
"lib/compiler/passes/remove-proxy-rules.js",
"lib/compiler/passes/report-left-recursion.js",
"lib/compiler/passes/report-missing-rules.js",
"lib/grammar-error.js",
"lib/parser.js",
"lib/peg.js",
"lib/utils.js",
"package.json"
],
"main": "lib/peg",
"bin": "bin/pegjs",
"scripts": {

29
spec/README

@ -7,27 +7,36 @@ should always pass on all supported platforms.
Running in a browser
--------------------
1. Start a web server and make it serve the PEG.js root directory (one level
up from this one).
1. Make sure you have Node.js and all the development dependencies specified
in package.json installed.
2. Point your browser to an URL corresponding to the index.html file.
2. Run the following command in the PEG.js root directory (one level up from
this one):
3. Watch the specs pass (or fail).
make browser
3. Start a web server and make it serve the PEG.js root directory.
4. Point your browser to an URL corresponding to the index.html file.
5. Watch the specs pass (or fail).
If you have Python installed, you can just run the following command in the
PEG.js root directory
If you have Python installed, you can fulfill steps 3 and 4 by running the
following command in the PEG.js root directory
python -m SimpleHTTPServer
and load http://localhost:8000/spec/ in your browser.
and loading http://localhost:8000/spec/index.html in your browser.
Running from a command-line
---------------------------
1. Make sure you have Node.js and the "jasmine-node" npm pacakge installed.
1. Make sure you have Node.js and all the development dependencies specified
in package.json installed.
2. Run the following command:
2. Run the following command in the PEG.js root directory (one level up from
this one):
jasmine-node --verbose .
make spec
3. Watch the specs pass (or fail).

2
spec/index.html

@ -5,7 +5,7 @@
<link rel="stylesheet" href="vendor/jasmine/jasmine.css">
<script src="vendor/jasmine/jasmine.js"></script>
<script src="vendor/jasmine/jasmine-html.js"></script>
<script src="../lib/peg.js"></script>
<script src="../browser/peg-0.7.0.js"></script>
<script src="helpers.js"></script>
<script src="parser.spec.js"></script>
<script src="generated-parser.spec.js"></script>

Loading…
Cancel
Save