Merge pull request #345 from arlolra/split4

Even more split outs from #339
redux
David Majda 9 years ago
commit cb640cd0b2

@ -10,8 +10,10 @@
"loopfunc": true,
"newcap": false,
"noarg": true,
"node": true,
"noempty": true,
"nonew": true,
"strict": true,
"trailing": true,
"validthis": true,
"-W082": false

@ -79,6 +79,8 @@ browser:
echo ' * Licensed under the MIT license.' >> $(BROWSER_FILE_DEV)
echo ' */' >> $(BROWSER_FILE_DEV)
echo 'var PEG = (function(undefined) {' >> $(BROWSER_FILE_DEV)
echo ' "use strict";' >> $(BROWSER_FILE_DEV)
echo '' >> $(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)

@ -1,38 +1,50 @@
benchmarks = [
{
id: "json",
title: "JSON",
tests: [
{ file: "example1.json", title: "Example 1" },
{ file: "example2.json", title: "Example 2" },
{ file: "example3.json", title: "Example 3" },
{ file: "example4.json", title: "Example 4" },
{ file: "example5.json", title: "Example 5" }
]
},
{
id: "css",
title: "CSS",
tests: [
{ file: "blueprint/src/reset.css", title: "Blueprint - reset.css (source)" },
{ file: "blueprint/src/typography.css", title: "Blueprint - typography.css (source)" },
{ file: "blueprint/src/forms.css", title: "Blueprint - forms.css (source)" },
{ file: "blueprint/src/grid.css", title: "Blueprint - grid.css (source)" },
{ file: "blueprint/src/print.css", title: "Blueprint - print.css (source)" },
// Contains syntax errors.
// { file: "blueprint/src/ie.css", title: "Blueprint - ie.css (source)" },
{ file: "blueprint/min/screen.css", title: "Blueprint - screen.css (minified)" },
{ file: "blueprint/min/print.css", title: "Blueprint - print.css (minified)" },
// Contains syntax errors.
// { file: "blueprint/min/ie.css", title: "Blueprint - ie.css (minified)" },
{ file: "960.gs/src/reset.css", title: "960.gs - reset.css (source)" },
{ file: "960.gs/src/text.css", title: "960.gs - text.css (source)" },
{ file: "960.gs/src/960.css", title: "960.gs - 960.css (source)" },
{ file: "960.gs/src/960_24_col.css", title: "960.gs - 960_24_col.css (source)" },
{ file: "960.gs/min/reset.css", title: "960.gs - reset.css (minified)" },
{ file: "960.gs/min/text.css", title: "960.gs - text.css (minified)" },
{ file: "960.gs/min/960.css", title: "960.gs - 960.css (minified)" },
{ file: "960.gs/min/960_24_col.css", title: "960.gs - 960_24_col.css (minified)" }
]
"use strict";
(function(root, factory) {
if (typeof module !== 'undefined' && module.exports) {
module.exports = factory();
} else {
root.benchmarks = factory();
}
];
}(this, function() {
return [
{
id: "json",
title: "JSON",
tests: [
{ file: "example1.json", title: "Example 1" },
{ file: "example2.json", title: "Example 2" },
{ file: "example3.json", title: "Example 3" },
{ file: "example4.json", title: "Example 4" },
{ file: "example5.json", title: "Example 5" }
]
},
{
id: "css",
title: "CSS",
tests: [
{ file: "blueprint/src/reset.css", title: "Blueprint - reset.css (source)" },
{ file: "blueprint/src/typography.css", title: "Blueprint - typography.css (source)" },
{ file: "blueprint/src/forms.css", title: "Blueprint - forms.css (source)" },
{ file: "blueprint/src/grid.css", title: "Blueprint - grid.css (source)" },
{ file: "blueprint/src/print.css", title: "Blueprint - print.css (source)" },
// Contains syntax errors.
// { file: "blueprint/src/ie.css", title: "Blueprint - ie.css (source)" },
{ file: "blueprint/min/screen.css", title: "Blueprint - screen.css (minified)" },
{ file: "blueprint/min/print.css", title: "Blueprint - print.css (minified)" },
// Contains syntax errors.
// { file: "blueprint/min/ie.css", title: "Blueprint - ie.css (minified)" },
{ file: "960.gs/src/reset.css", title: "960.gs - reset.css (source)" },
{ file: "960.gs/src/text.css", title: "960.gs - text.css (source)" },
{ file: "960.gs/src/960.css", title: "960.gs - 960.css (source)" },
{ file: "960.gs/src/960_24_col.css", title: "960.gs - 960_24_col.css (source)" },
{ file: "960.gs/min/reset.css", title: "960.gs - reset.css (minified)" },
{ file: "960.gs/min/text.css", title: "960.gs - text.css (minified)" },
{ file: "960.gs/min/960.css", title: "960.gs - 960.css (minified)" },
{ file: "960.gs/min/960_24_col.css", title: "960.gs - 960_24_col.css (minified)" }
]
}
];
}));

@ -1,4 +1,8 @@
/* jshint node:false */
/* global $, alert, benchmarks, document, Runner */
$("#run").click(function() {
"use strict";
/* Results Table Manipulation */
@ -130,5 +134,7 @@ $("#run").click(function() {
});
$(document).ready(function() {
"use strict";
$("#run").focus();
});

@ -1,15 +1,13 @@
#!/usr/bin/env node
"use strict";
var util = require("util");
var fs = require("fs");
var PEG = require("../lib/peg");
[
"benchmarks.js",
"runner.js",
].forEach(function(file) {
eval(fs.readFileSync(__dirname + "/" + file, "utf8"));
});
var benchmarks = require("./benchmarks.js");
var Runner = require("./runner.js")(PEG);
/* Results Table Manipulation */

@ -1,119 +1,131 @@
Runner = {
run: function(benchmarks, runCount, options, callbacks) {
"use strict";
/* Queue */
(function(root, factory) {
if (typeof module !== 'undefined' && module.exports) {
module.exports = factory;
} else {
root.Runner = factory(root.PEG);
}
}(this, function(PEG) {
return {
run: function(benchmarks, runCount, options, callbacks) {
/* Queue */
var Q = {
functions: [],
var Q = {
functions: [],
add: function(f) {
this.functions.push(f);
},
add: function(f) {
this.functions.push(f);
},
run: function() {
if (this.functions.length > 0) {
this.functions.shift()();
run: function() {
if (this.functions.length > 0) {
this.functions.shift()();
/*
* We can't use |arguments.callee| here because |this| would get
* messed-up in that case.
*/
setTimeout(function() { Q.run(); }, 0);
/*
* We can't use |arguments.callee| here because |this| would get
* messed-up in that case.
*/
setTimeout(function() { Q.run(); }, 0);
}
}
}
};
};
/*
* The benchmark itself is factored out into several functions (some of them
* generated), which are enqueued and run one by one using |setTimeout|. We
* do this for two reasons:
*
* 1. To avoid bowser mechanism for interrupting long-running scripts to
* kick-in (or at least to not kick-in that often).
*
* 2. To ensure progressive rendering of results in the browser (some
* browsers do not render at all when running JavaScript code).
*
* The enqueued functions share state, which is all stored in the properties
* of the |state| object.
*/
var state = {}, i, j;
function initialize() {
callbacks.start();
state.totalInputSize = 0;
state.totalParseTime = 0;
}
/*
* The benchmark itself is factored out into several functions (some of them
* generated), which are enqueued and run one by one using |setTimeout|. We
* do this for two reasons:
*
* 1. To avoid bowser mechanism for interrupting long-running scripts to
* kick-in (or at least to not kick-in that often).
*
* 2. To ensure progressive rendering of results in the browser (some
* browsers do not render at all when running JavaScript code).
*
* The enqueued functions share state, which is all stored in the properties
* of the |state| object.
*/
var state = {}, i, j;
function initialize() {
callbacks.start();
state.totalInputSize = 0;
state.totalParseTime = 0;
}
function benchmarkInitializer(i) {
return function() {
callbacks.benchmarkStart(benchmarks[i]);
function benchmarkInitializer(i) {
return function() {
callbacks.benchmarkStart(benchmarks[i]);
state.parser = PEG.buildParser(
callbacks.readFile("../examples/" + benchmarks[i].id + ".pegjs"),
options
);
state.benchmarkInputSize = 0;
state.benchmarkParseTime = 0;
};
}
state.parser = PEG.buildParser(
callbacks.readFile("../examples/" + benchmarks[i].id + ".pegjs"),
options
);
state.benchmarkInputSize = 0;
state.benchmarkParseTime = 0;
};
}
function testRunner(i, j) {
return function() {
var benchmark = benchmarks[i],
test = benchmark.tests[j],
input, parseTime, averageParseTime, k, t;
function testRunner(i, j) {
return function() {
var benchmark = benchmarks[i],
test = benchmark.tests[j],
input, parseTime, averageParseTime, k, t;
callbacks.testStart(benchmark, test);
callbacks.testStart(benchmark, test);
input = callbacks.readFile(benchmark.id + "/" + test.file);
input = callbacks.readFile(benchmark.id + "/" + test.file);
parseTime = 0;
for (k = 0; k < runCount; k++) {
t = (new Date()).getTime();
state.parser.parse(input);
parseTime += (new Date()).getTime() - t;
}
averageParseTime = parseTime / runCount;
parseTime = 0;
for (k = 0; k < runCount; k++) {
t = (new Date()).getTime();
state.parser.parse(input);
parseTime += (new Date()).getTime() - t;
}
averageParseTime = parseTime / runCount;
callbacks.testFinish(benchmark, test, input.length, averageParseTime);
callbacks.testFinish(benchmark, test, input.length, averageParseTime);
state.benchmarkInputSize += input.length;
state.benchmarkParseTime += averageParseTime;
};
}
state.benchmarkInputSize += input.length;
state.benchmarkParseTime += averageParseTime;
};
}
function benchmarkFinalizer(i) {
return function() {
callbacks.benchmarkFinish(
benchmarks[i],
state.benchmarkInputSize,
state.benchmarkParseTime
);
state.totalInputSize += state.benchmarkInputSize;
state.totalParseTime += state.benchmarkParseTime;
};
}
function benchmarkFinalizer(i) {
return function() {
callbacks.benchmarkFinish(
benchmarks[i],
state.benchmarkInputSize,
state.benchmarkParseTime
);
function finalize() {
callbacks.finish(state.totalInputSize, state.totalParseTime);
}
state.totalInputSize += state.benchmarkInputSize;
state.totalParseTime += state.benchmarkParseTime;
};
}
function finalize() {
callbacks.finish(state.totalInputSize, state.totalParseTime);
}
/* Main */
/* Main */
Q.add(initialize);
for (i = 0; i < benchmarks.length; i++) {
Q.add(benchmarkInitializer(i));
for (j = 0; j < benchmarks[i].tests.length; j++) {
Q.add(testRunner(i, j));
Q.add(initialize);
for (i = 0; i < benchmarks.length; i++) {
Q.add(benchmarkInitializer(i));
for (j = 0; j < benchmarks[i].tests.length; j++) {
Q.add(testRunner(i, j));
}
Q.add(benchmarkFinalizer(i));
}
Q.add(benchmarkFinalizer(i));
Q.add(finalize);
Q.run();
}
Q.add(finalize);
};
Q.run();
}
};
}));

@ -1,5 +1,7 @@
#!/usr/bin/env node
"use strict";
var util = require("util");
var fs = require("fs");
var path = require("path");

@ -1,3 +1,5 @@
"use strict";
var arrays = require("./utils/arrays"),
objects = require("./utils/objects");

@ -1,3 +1,5 @@
"use strict";
var arrays = require("../utils/arrays"),
visitor = require("./visitor");

@ -1,3 +1,5 @@
"use strict";
function hex(ch) { return ch.charCodeAt(0).toString(16).toUpperCase(); }
/* JavaScript code generation helpers. */

@ -1,3 +1,5 @@
"use strict";
/* Bytecode instruction opcodes. */
var opcodes = {
/* Stack Manipulation */

@ -1,3 +1,5 @@
"use strict";
var arrays = require("../../utils/arrays"),
objects = require("../../utils/objects"),
asts = require("../asts"),

@ -1,3 +1,5 @@
"use strict";
var arrays = require("../../utils/arrays"),
asts = require("../asts"),
op = require("../opcodes"),

@ -1,3 +1,5 @@
"use strict";
var arrays = require("../../utils/arrays"),
visitor = require("../visitor");

@ -1,3 +1,5 @@
"use strict";
var GrammarError = require("../../grammar-error"),
asts = require("../asts"),
visitor = require("../visitor");

@ -1,3 +1,5 @@
"use strict";
var arrays = require("../../utils/arrays"),
GrammarError = require("../../grammar-error"),
asts = require("../asts"),

@ -1,3 +1,5 @@
"use strict";
var GrammarError = require("../../grammar-error"),
asts = require("../asts"),
visitor = require("../visitor");

@ -1,3 +1,5 @@
"use strict";
var objects = require("../utils/objects"),
arrays = require("../utils/arrays");

@ -1,3 +1,5 @@
"use strict";
var classes = require("./utils/classes");
/* Thrown when the grammar contains an error. */

@ -1,3 +1,5 @@
"use strict";
var arrays = require("./utils/arrays"),
objects = require("./utils/objects");

@ -1,3 +1,5 @@
"use strict";
/* Array utilities. */
var arrays = {
range: function(start, stop) {

@ -1,3 +1,5 @@
"use strict";
/* Class utilities */
var classes = {
subclass: function(child, parent) {

@ -1,3 +1,5 @@
"use strict";
/* Object utilities. */
var objects = {
keys: function(object) {

@ -1,3 +1,7 @@
/* global describe, expect, it, PEG, spyOn */
"use strict";
describe("generated parser API", function() {
describe("parse", function() {
it("parses input", function() {

@ -1,3 +1,7 @@
/* global describe, expect, it, PEG, spyOn */
"use strict";
describe("PEG.js API", function() {
describe("buildParser", function() {
it("builds a parser", function() {

@ -1,3 +1,7 @@
/* global beforeEach, describe, expect, it, jasmine, PEG */
"use strict";
describe("plugin API", function() {
beforeEach(function() {
this.addMatchers({

@ -1,3 +1,7 @@
/* global beforeEach, describe, expect, it, jasmine, PEG */
"use strict";
describe("generated parser behavior", function() {
function varyOptimizationOptions(block) {
function clone(object) {

@ -1,3 +1,7 @@
if (typeof module !== "undefined") {
PEG = require("../lib/peg.js");
}
"use strict";
(function(root) {
if (typeof module !== 'undefined') {
root.PEG = require("../lib/peg.js");
}
}(this));

@ -1,3 +1,7 @@
/* global describe, expect, it, PEG */
"use strict";
describe("compiler pass |generateBytecode|", function() {
var pass = PEG.compiler.passes.generate.generateBytecode;

@ -1,3 +1,7 @@
/* global beforeEach, jasmine, PEG */
"use strict";
beforeEach(function() {
this.addMatchers({
toChangeAST: function(grammar) {

@ -1,3 +1,7 @@
/* global describe, expect, it, PEG */
"use strict";
describe("compiler pass |removeProxyRules|", function() {
var pass = PEG.compiler.passes.transform.removeProxyRules;

@ -1,3 +1,7 @@
/* global describe, expect, it, PEG */
"use strict";
describe("compiler pass |reportLeftRecursion|", function() {
var pass = PEG.compiler.passes.check.reportInfiniteLoops;

@ -1,3 +1,7 @@
/* global describe, expect, it, PEG */
"use strict";
describe("compiler pass |reportLeftRecursion|", function() {
var pass = PEG.compiler.passes.check.reportLeftRecursion;

@ -1,3 +1,7 @@
/* global describe, expect, it, PEG */
"use strict";
describe("compiler pass |reportMissingRules|", function() {
var pass = PEG.compiler.passes.check.reportMissingRules;

@ -1,3 +1,7 @@
/* global beforeEach, describe, expect, it, jasmine, PEG */
"use strict";
describe("PEG.js grammar parser", function() {
var literalAbcd = { type: "literal", value: "abcd", ignoreCase: false },
literalEfgh = { type: "literal", value: "efgh", ignoreCase: false },

Loading…
Cancel
Save