Rename the "PEG" variable to "peg"

So far, PEG.js was exported in a "PEG" global variable when no module
loader was detected. The same variable name was also conventionally used
when requiring it in Node.js or otherwise referring to it. This was
reflected in various places in the code, documentation, examples, etc.

This commit changes the variable name to "peg" and fixes all relevant
occurrences. The main reason for the change is that in Node.js, modules
are generally referred to by lower-case variable names, so "PEG" was
sticking out when used in Node.js projects.
redux
David Majda 9 years ago
parent 057a93fbc7
commit 0847a69643

@ -74,7 +74,7 @@ browser:
echo ' * Licensed under the MIT license.' >> $(BROWSER_FILE_DEV)
echo ' */' >> $(BROWSER_FILE_DEV)
$(BROWSERIFY) --standalone PEG $(MAIN_FILE) >> $(BROWSER_FILE_DEV)
$(BROWSERIFY) --standalone peg $(MAIN_FILE) >> $(BROWSER_FILE_DEV)
$(UGLIFYJS) \
--mangle \

@ -87,25 +87,25 @@ You can tweak the generated parser with several options:
* `--plugin` — makes PEG.js use a specified plugin (can be specified multiple
times)
* `--extra-options` — additional options (in JSON format) to pass to
`PEG.buildParser`
`peg.buildParser`
* `--extra-options-file` — file with additional options (in JSON format) to
pass to `PEG.buildParser`
pass to `peg.buildParser`
* `--trace` — makes the parser trace its progress
### JavaScript API
In Node.js, require the PEG.js parser generator module:
var PEG = require("pegjs");
var peg = require("pegjs");
In browser, include the PEG.js library in your web page or application using the
`<script>` tag. If PEG.js detects an AMD loader, it will define itself as a
module, otherwise the API will be available in the `PEG` global object.
module, otherwise the API will be available in the `peg` global object.
To generate a parser, call the `PEG.buildParser` method and pass your grammar as
To generate a parser, call the `peg.buildParser` method and pass your grammar as
a parameter:
var parser = PEG.buildParser("start = ('a' / 'b')+");
var parser = peg.buildParser("start = ('a' / 'b')+");
The method will return generated parser object or its source code as a string
(depending on the value of the `output` option — see below). It will throw an
@ -113,7 +113,7 @@ exception if the grammar is invalid. The exception will contain `message`
property with more details about the error.
You can tweak the generated parser by passing a second parameter with an options
object to `PEG.buildParser`. The following options are supported:
object to `peg.buildParser`. The following options are supported:
* `cache` — if `true`, makes the parser cache results, avoiding exponential
parsing time in pathological cases but making the parser slower (default:

@ -6,10 +6,10 @@
"use strict";
var fs = require("fs");
var PEG = require("../lib/peg");
var peg = require("../lib/peg");
var benchmarks = require("./benchmarks.js");
var Runner = require("./runner.js")(PEG);
var Runner = require("./runner.js")(peg);
/* Results Table Manipulation */

@ -6,9 +6,9 @@
if (typeof module !== 'undefined' && module.exports) {
module.exports = factory;
} else {
root.Runner = factory(root.PEG);
root.Runner = factory(root.peg);
}
}(this, function(PEG) {
}(this, function(peg) {
return {
run: function(benchmarks, runCount, options, callbacks) {
@ -63,7 +63,7 @@
return function() {
callbacks.benchmarkStart(benchmarks[i]);
state.parser = PEG.buildParser(
state.parser = peg.buildParser(
callbacks.readFile("../examples/" + benchmarks[i].id + ".pegjs"),
options
);

@ -4,12 +4,12 @@
var fs = require("fs");
var path = require("path");
var PEG = require("../lib/peg");
var peg = require("../lib/peg");
/* Helpers */
function printVersion() {
console.log("PEG.js " + PEG.VERSION);
console.log("PEG.js " + peg.VERSION);
}
function printHelp() {
@ -39,9 +39,9 @@ function printHelp() {
console.log(" --plugin <plugin> use a specified plugin (can be specified");
console.log(" multiple times)");
console.log(" --extra-options <options> additional options (in JSON format) to pass");
console.log(" to PEG.buildParser");
console.log(" to peg.buildParser");
console.log(" --extra-options-file <file> file with additional options (in JSON");
console.log(" format) to pass to PEG.buildParser");
console.log(" format) to pass to peg.buildParser");
console.log(" -v, --version print version information and exit");
console.log(" -h, --help print help and exit");
}
@ -272,7 +272,7 @@ readStream(inputStream, function(input) {
var source;
try {
source = PEG.buildParser(input, options);
source = peg.buildParser(input, options);
} catch (e) {
if (e.location !== undefined) {
abort(e.location.start.line + ":" + e.location.start.column + ": " + e.message);

@ -15,7 +15,7 @@ var compiler = {
*
* Each pass is a function that is passed the AST. It can perform checks on it
* or modify it as needed. If the pass encounters a semantic error, it throws
* |PEG.GrammarError|.
* |peg.GrammarError|.
*/
passes: {
check: {
@ -33,7 +33,7 @@ var compiler = {
},
/*
* Generates a parser from a specified grammar AST. Throws |PEG.GrammarError|
* Generates a parser from a specified grammar AST. Throws |peg.GrammarError|
* if the AST contains a semantic error. Note that not all errors are detected
* during the generation and some may protrude to the generated parser and
* cause its malfunction.

@ -3,7 +3,7 @@
var arrays = require("./utils/arrays"),
objects = require("./utils/objects");
var PEG = {
var peg = {
/* PEG.js version (uses semantic versioning). */
VERSION: "0.9.0",
@ -17,8 +17,8 @@ var PEG = {
* The grammar must be a string in the format described by the metagramar in
* the parser.pegjs file.
*
* Throws |PEG.parser.SyntaxError| if the grammar contains a syntax error or
* |PEG.GrammarError| if it contains a semantic error. Note that not all
* Throws |peg.parser.SyntaxError| if the grammar contains a syntax error or
* |peg.GrammarError| if it contains a semantic error. Note that not all
* errors are detected during the generation and some may protrude to the
* generated parser and cause its malfunction.
*/
@ -55,4 +55,4 @@ var PEG = {
}
};
module.exports = PEG;
module.exports = peg;

@ -1,24 +1,24 @@
/* eslint no-console: 0 */
/* global PEG, console */
/* global peg, console */
"use strict";
describe("generated parser API", function() {
describe("parse", function() {
it("parses input", function() {
var parser = PEG.buildParser('start = "a"');
var parser = peg.buildParser('start = "a"');
expect(parser.parse("a")).toBe("a");
});
it("throws an exception on syntax error", function() {
var parser = PEG.buildParser('start = "a"');
var parser = peg.buildParser('start = "a"');
expect(function() { parser.parse("b"); }).toThrow();
});
describe("start rule", function() {
var parser = PEG.buildParser([
var parser = peg.buildParser([
'a = "x" { return "a"; }',
'b = "x" { return "b"; }',
'c = "x" { return "c"; }'
@ -47,7 +47,7 @@ describe("generated parser API", function() {
});
describe("tracing", function() {
var parser = PEG.buildParser([
var parser = peg.buildParser([
'start = a / b',
'a = "a"',
'b = "b"'
@ -135,7 +135,7 @@ describe("generated parser API", function() {
});
it("accepts custom options", function() {
var parser = PEG.buildParser('start = "a"');
var parser = peg.buildParser('start = "a"');
parser.parse("a", { foo: 42 });
});

@ -1,22 +1,22 @@
/* global PEG */
/* global peg */
"use strict";
describe("PEG.js API", function() {
describe("buildParser", function() {
it("builds a parser", function() {
var parser = PEG.buildParser('start = "a"');
var parser = peg.buildParser('start = "a"');
expect(typeof parser).toBe("object");
expect(parser.parse("a")).toBe("a");
});
it("throws an exception on syntax error", function() {
expect(function() { PEG.buildParser('start = @'); }).toThrow();
expect(function() { peg.buildParser('start = @'); }).toThrow();
});
it("throws an exception on semantic error", function() {
expect(function() { PEG.buildParser('start = missing'); }).toThrow();
expect(function() { peg.buildParser('start = missing'); }).toThrow();
});
describe("allowed start rules", function() {
@ -34,7 +34,7 @@ describe("PEG.js API", function() {
describe("when optimizing for parsing speed", function() {
describe("when |allowedStartRules| is not set", function() {
it("generated parser can start only from the first rule", function() {
var parser = PEG.buildParser(grammar, { optimize: "speed" });
var parser = peg.buildParser(grammar, { optimize: "speed" });
expect(parser.parse("x", { startRule: "a" })).toBe("x");
expect(
@ -48,7 +48,7 @@ describe("PEG.js API", function() {
describe("when |allowedStartRules| is set", function() {
it("generated parser can start only from specified rules", function() {
var parser = PEG.buildParser(grammar, {
var parser = peg.buildParser(grammar, {
optimize: "speed",
allowedStartRules: ["b", "c"]
});
@ -65,7 +65,7 @@ describe("PEG.js API", function() {
describe("when optimizing for code size", function() {
describe("when |allowedStartRules| is not set", function() {
it("generated parser can start only from the first rule", function() {
var parser = PEG.buildParser(grammar, { optimize: "size" });
var parser = peg.buildParser(grammar, { optimize: "size" });
expect(parser.parse("x", { startRule: "a" })).toBe("x");
expect(
@ -79,7 +79,7 @@ describe("PEG.js API", function() {
describe("when |allowedStartRules| is set", function() {
it("generated parser can start only from specified rules", function() {
var parser = PEG.buildParser(grammar, {
var parser = peg.buildParser(grammar, {
optimize: "size",
allowedStartRules: ["b", "c"]
});
@ -103,7 +103,7 @@ describe("PEG.js API", function() {
describe("when |cache| is not set", function() {
it("generated parser doesn't cache intermediate parse results", function() {
var parser = PEG.buildParser(grammar);
var parser = peg.buildParser(grammar);
expect(parser.parse("ac")).toBe(2);
});
@ -111,7 +111,7 @@ describe("PEG.js API", function() {
describe("when |cache| is set to |false|", function() {
it("generated parser doesn't cache intermediate parse results", function() {
var parser = PEG.buildParser(grammar, { cache: false });
var parser = peg.buildParser(grammar, { cache: false });
expect(parser.parse("ac")).toBe(2);
});
@ -119,7 +119,7 @@ describe("PEG.js API", function() {
describe("when |cache| is set to |true|", function() {
it("generated parser caches intermediate parse results", function() {
var parser = PEG.buildParser(grammar, { cache: true });
var parser = peg.buildParser(grammar, { cache: true });
expect(parser.parse("ac")).toBe(1);
});
@ -131,7 +131,7 @@ describe("PEG.js API", function() {
describe("when |trace| is not set", function() {
it("generated parser doesn't trace", function() {
var parser = PEG.buildParser(grammar),
var parser = peg.buildParser(grammar),
tracer = jasmine.createSpyObj("tracer", ["trace"]);
parser.parse("a", { tracer: tracer });
@ -142,7 +142,7 @@ describe("PEG.js API", function() {
describe("when |trace| is set to |false|", function() {
it("generated parser doesn't trace", function() {
var parser = PEG.buildParser(grammar, { trace: false }),
var parser = peg.buildParser(grammar, { trace: false }),
tracer = jasmine.createSpyObj("tracer", ["trace"]);
parser.parse("a", { tracer: tracer });
@ -153,7 +153,7 @@ describe("PEG.js API", function() {
describe("when |trace| is set to |true|", function() {
it("generated parser traces", function() {
var parser = PEG.buildParser(grammar, { trace: true }),
var parser = peg.buildParser(grammar, { trace: true }),
tracer = jasmine.createSpyObj("tracer", ["trace"]);
parser.parse("a", { tracer: tracer });
@ -173,7 +173,7 @@ describe("PEG.js API", function() {
describe("when |output| is not set", function() {
it("returns generated parser object", function() {
var parser = PEG.buildParser(grammar);
var parser = peg.buildParser(grammar);
expect(typeof parser).toBe("object");
expect(parser.parse("a")).toBe("a");
@ -182,7 +182,7 @@ describe("PEG.js API", function() {
describe("when |output| is set to |\"parser\"|", function() {
it("returns generated parser object", function() {
var parser = PEG.buildParser(grammar, { output: "parser" });
var parser = peg.buildParser(grammar, { output: "parser" });
expect(typeof parser).toBe("object");
expect(parser.parse("a")).toBe("a");
@ -191,7 +191,7 @@ describe("PEG.js API", function() {
describe("when |output| is set to |\"source\"|", function() {
it("returns generated parser source code", function() {
var source = PEG.buildParser(grammar, { output: "source" });
var source = peg.buildParser(grammar, { output: "source" });
expect(typeof source).toBe("string");
expect(eval(source).parse("a")).toBe("a");
@ -208,7 +208,7 @@ describe("PEG.js API", function() {
/* The |plugins| option is tested in plugin API specs. */
it("accepts custom options", function() {
PEG.buildParser('start = "a"', { foo: 42 });
peg.buildParser('start = "a"', { foo: 42 });
});
});
});

@ -1,4 +1,4 @@
/* global PEG */
/* global peg */
"use strict";
@ -48,7 +48,7 @@ describe("plugin API", function() {
{ use: function() { pluginsUsed[2] = true; } }
];
PEG.buildParser(grammar, { plugins: plugins });
peg.buildParser(grammar, { plugins: plugins });
expect(pluginsUsed).toEqual([true, true, true]);
});
@ -82,7 +82,7 @@ describe("plugin API", function() {
}
};
PEG.buildParser(grammar, { plugins: [plugin] });
peg.buildParser(grammar, { plugins: [plugin] });
});
it("receives options", function() {
@ -93,13 +93,13 @@ describe("plugin API", function() {
},
buildParserOptions = { plugins: [plugin], foo: 42 };
PEG.buildParser(grammar, buildParserOptions);
peg.buildParser(grammar, buildParserOptions);
});
it("can replace parser", function() {
var plugin = {
use: function(config) {
var parser = PEG.buildParser([
var parser = peg.buildParser([
'start = .* {',
' return {',
' type: "grammar",',
@ -117,7 +117,7 @@ describe("plugin API", function() {
config.parser = parser;
}
},
parser = PEG.buildParser('a', { plugins: [plugin] });
parser = peg.buildParser('a', { plugins: [plugin] });
expect(parser.parse("a")).toBe("a");
});
@ -132,7 +132,7 @@ describe("plugin API", function() {
config.passes.generate = [pass];
}
},
parser = PEG.buildParser(grammar, { plugins: [plugin] });
parser = peg.buildParser(grammar, { plugins: [plugin] });
expect(parser.parse("a")).toBe(42);
});
@ -148,7 +148,7 @@ describe("plugin API", function() {
options.allowedStartRules = ["b", "c"];
}
},
parser = PEG.buildParser(grammar, {
parser = peg.buildParser(grammar, {
allowedStartRules: ["a"],
plugins: [plugin]
});

@ -1,4 +1,4 @@
/* global PEG */
/* global peg */
"use strict";
@ -130,7 +130,7 @@ describe("generated parser behavior", function() {
varyOptimizationOptions(function(options) {
describe("initializer", function() {
it("executes the code before parsing starts", function() {
var parser = PEG.buildParser([
var parser = peg.buildParser([
'{ var result = 42; }',
'start = "a" { return result; }'
].join("\n"), options);
@ -140,7 +140,7 @@ describe("generated parser behavior", function() {
describe("available variables and functions", function() {
it("|parser| contains the parser object", function() {
var parser = PEG.buildParser([
var parser = peg.buildParser([
'{ var result = parser; }',
'start = "a" { return result; }'
].join("\n"), options);
@ -149,7 +149,7 @@ describe("generated parser behavior", function() {
});
it("|options| contains options", function() {
var parser = PEG.buildParser([
var parser = peg.buildParser([
'{ var result = options; }',
'start = "a" { return result; }'
].join("\n"), options);
@ -162,7 +162,7 @@ describe("generated parser behavior", function() {
describe("rule", function() {
if (options.cache) {
it("caches rule match results", function() {
var parser = PEG.buildParser([
var parser = peg.buildParser([
'{ var n = 0; }',
'start = (a "b") / (a "c") { return n; }',
'a = "a" { n++; }'
@ -172,7 +172,7 @@ describe("generated parser behavior", function() {
});
} else {
it("doesn't cache rule match results", function() {
var parser = PEG.buildParser([
var parser = peg.buildParser([
'{ var n = 0; }',
'start = (a "b") / (a "c") { return n; }',
'a = "a" { n++; }'
@ -184,7 +184,7 @@ describe("generated parser behavior", function() {
describe("when the expression matches", function() {
it("returns its match result", function() {
var parser = PEG.buildParser('start = "a"');
var parser = peg.buildParser('start = "a"');
expect(parser).toParse("a", "a");
});
@ -193,7 +193,7 @@ describe("generated parser behavior", function() {
describe("when the expression doesn't match", function() {
describe("without display name", function() {
it("reports match failure and doesn't record any expectation", function() {
var parser = PEG.buildParser('start = "a"');
var parser = peg.buildParser('start = "a"');
expect(parser).toFailToParse("b", {
expected: [{ type: "literal", value: "a", description: '"a"' }]
@ -203,7 +203,7 @@ describe("generated parser behavior", function() {
describe("with display name", function() {
it("reports match failure and records an expectation of type \"other\"", function() {
var parser = PEG.buildParser('start "start" = "a"');
var parser = peg.buildParser('start "start" = "a"');
expect(parser).toFailToParse("b", {
expected: [{ type: "other", description: "start" }]
@ -211,7 +211,7 @@ describe("generated parser behavior", function() {
});
it("discards any expectations recorded when matching the expression", function() {
var parser = PEG.buildParser('start "start" = "a"');
var parser = peg.buildParser('start "start" = "a"');
expect(parser).toFailToParse("b", {
expected: [{ type: "other", description: "start" }]
@ -224,34 +224,34 @@ describe("generated parser behavior", function() {
describe("literal", function() {
describe("matching", function() {
it("matches empty literals", function() {
var parser = PEG.buildParser('start = ""', options);
var parser = peg.buildParser('start = ""', options);
expect(parser).toParse("");
});
it("matches one-character literals", function() {
var parser = PEG.buildParser('start = "a"', options);
var parser = peg.buildParser('start = "a"', options);
expect(parser).toParse("a");
expect(parser).toFailToParse("b");
});
it("matches multi-character literals", function() {
var parser = PEG.buildParser('start = "abcd"', options);
var parser = peg.buildParser('start = "abcd"', options);
expect(parser).toParse("abcd");
expect(parser).toFailToParse("efgh");
});
it("is case sensitive without the \"i\" flag", function() {
var parser = PEG.buildParser('start = "a"', options);
var parser = peg.buildParser('start = "a"', options);
expect(parser).toParse("a");
expect(parser).toFailToParse("A");
});
it("is case insensitive with the \"i\" flag", function() {
var parser = PEG.buildParser('start = "a"i', options);
var parser = peg.buildParser('start = "a"i', options);
expect(parser).toParse("a");
expect(parser).toParse("A");
@ -260,13 +260,13 @@ describe("generated parser behavior", function() {
describe("when it matches", function() {
it("returns the matched text", function() {
var parser = PEG.buildParser('start = "a"', options);
var parser = peg.buildParser('start = "a"', options);
expect(parser).toParse("a", "a");
});
it("consumes the matched text", function() {
var parser = PEG.buildParser('start = "a" .', options);
var parser = peg.buildParser('start = "a" .', options);
expect(parser).toParse("ab");
});
@ -274,7 +274,7 @@ describe("generated parser behavior", function() {
describe("when it doesn't match", function() {
it("reports match failure and records an expectation of type \"literal\"", function() {
var parser = PEG.buildParser('start = "a"', options);
var parser = peg.buildParser('start = "a"', options);
expect(parser).toFailToParse("b", {
expected: [{ type: "literal", value: "a", description: '"a"' }]
@ -286,13 +286,13 @@ describe("generated parser behavior", function() {
describe("character class", function() {
describe("matching", function() {
it("matches empty classes", function() {
var parser = PEG.buildParser('start = []', options);
var parser = peg.buildParser('start = []', options);
expect(parser).toFailToParse("a");
});
it("matches classes with a character list", function() {
var parser = PEG.buildParser('start = [abc]', options);
var parser = peg.buildParser('start = [abc]', options);
expect(parser).toParse("a");
expect(parser).toParse("b");
@ -301,7 +301,7 @@ describe("generated parser behavior", function() {
});
it("matches classes with a character range", function() {
var parser = PEG.buildParser('start = [a-c]', options);
var parser = peg.buildParser('start = [a-c]', options);
expect(parser).toParse("a");
expect(parser).toParse("b");
@ -310,21 +310,21 @@ describe("generated parser behavior", function() {
});
it("matches inverted classes", function() {
var parser = PEG.buildParser('start = [^a]', options);
var parser = peg.buildParser('start = [^a]', options);
expect(parser).toFailToParse("a");
expect(parser).toParse("b");
});
it("is case sensitive without the \"i\" flag", function() {
var parser = PEG.buildParser('start = [a]', options);
var parser = peg.buildParser('start = [a]', options);
expect(parser).toParse("a");
expect(parser).toFailToParse("A");
});
it("is case insensitive with the \"i\" flag", function() {
var parser = PEG.buildParser('start = [a]i', options);
var parser = peg.buildParser('start = [a]i', options);
expect(parser).toParse("a");
expect(parser).toParse("A");
@ -333,13 +333,13 @@ describe("generated parser behavior", function() {
describe("when it matches", function() {
it("returns the matched character", function() {
var parser = PEG.buildParser('start = [a]', options);
var parser = peg.buildParser('start = [a]', options);
expect(parser).toParse("a", "a");
});
it("consumes the matched character", function() {
var parser = PEG.buildParser('start = [a] .', options);
var parser = peg.buildParser('start = [a] .', options);
expect(parser).toParse("ab");
});
@ -347,7 +347,7 @@ describe("generated parser behavior", function() {
describe("when it doesn't match", function() {
it("reports match failure and records an expectation of type \"class\"", function() {
var parser = PEG.buildParser('start = [a]', options);
var parser = peg.buildParser('start = [a]', options);
expect(parser).toFailToParse("b", {
expected: [{ type: "class", value: "[a]", description: "[a]" }]
@ -359,7 +359,7 @@ describe("generated parser behavior", function() {
describe("dot", function() {
describe("matching", function() {
it("matches any character", function() {
var parser = PEG.buildParser('start = .', options);
var parser = peg.buildParser('start = .', options);
expect(parser).toParse("a");
expect(parser).toParse("b");
@ -369,13 +369,13 @@ describe("generated parser behavior", function() {
describe("when it matches", function() {
it("returns the matched character", function() {
var parser = PEG.buildParser('start = .', options);
var parser = peg.buildParser('start = .', options);
expect(parser).toParse("a", "a");
});
it("consumes the matched character", function() {
var parser = PEG.buildParser('start = . .', options);
var parser = peg.buildParser('start = . .', options);
expect(parser).toParse("ab");
});
@ -383,7 +383,7 @@ describe("generated parser behavior", function() {
describe("when it doesn't match", function() {
it("reports match failure and records an expectation of type \"any\"", function() {
var parser = PEG.buildParser('start = .', options);
var parser = peg.buildParser('start = .', options);
expect(parser).toFailToParse("", {
expected: [{ type: "any", description: "any character" }]
@ -395,7 +395,7 @@ describe("generated parser behavior", function() {
describe("rule reference", function() {
describe("when referenced rule's expression matches", function() {
it("returns its result", function() {
var parser = PEG.buildParser([
var parser = peg.buildParser([
'start = a',
'a = "a"'
].join("\n"), options);
@ -406,7 +406,7 @@ describe("generated parser behavior", function() {
describe("when referenced rule's expression doesn't match", function() {
it("reports match failure", function() {
var parser = PEG.buildParser([
var parser = peg.buildParser([
'start = a',
'a = "a"'
].join("\n"), options);
@ -424,7 +424,7 @@ describe("generated parser behavior", function() {
* |undefined| which we can't compare against in |toParse| due to the
* way optional parameters work.
*/
var parser = PEG.buildParser('start = &{ return true; } ""', options);
var parser = peg.buildParser('start = &{ return true; } ""', options);
expect(parser).toParse("", [undefined, ""]);
});
@ -432,7 +432,7 @@ describe("generated parser behavior", function() {
describe("when the code returns a falsey value", function() {
it("reports match failure", function() {
var parser = PEG.buildParser('start = &{ return false; }', options);
var parser = peg.buildParser('start = &{ return false; }', options);
expect(parser).toFailToParse("");
});
@ -441,7 +441,7 @@ describe("generated parser behavior", function() {
describe("label variables", function() {
describe("in containing sequence", function() {
it("can access variables defined by preceding labeled elements", function() {
var parser = PEG.buildParser(
var parser = peg.buildParser(
'start = a:"a" &{ return a === "a"; }',
options
);
@ -450,7 +450,7 @@ describe("generated parser behavior", function() {
});
it("cannot access variable defined by labeled predicate element", function() {
var parser = PEG.buildParser(
var parser = peg.buildParser(
'start = "a" b:&{ return b === undefined; } "c"',
options
);
@ -459,7 +459,7 @@ describe("generated parser behavior", function() {
});
it("cannot access variables defined by following labeled elements", function() {
var parser = PEG.buildParser(
var parser = peg.buildParser(
'start = &{ return a === "a"; } a:"a"',
options
);
@ -517,7 +517,7 @@ describe("generated parser behavior", function() {
parser, i;
for (i = 0; i < testcases.length; i++) {
parser = PEG.buildParser(testcases[i].grammar, options);
parser = peg.buildParser(testcases[i].grammar, options);
expect(parser).toFailToParse(testcases[i].input);
}
});
@ -525,7 +525,7 @@ describe("generated parser behavior", function() {
describe("in outer sequence", function() {
it("can access variables defined by preceding labeled elements", function() {
var parser = PEG.buildParser(
var parser = peg.buildParser(
'start = a:"a" ("b" &{ return a === "a"; })',
options
);
@ -534,7 +534,7 @@ describe("generated parser behavior", function() {
});
it("cannot access variable defined by labeled predicate element", function() {
var parser = PEG.buildParser(
var parser = peg.buildParser(
'start = "a" b:("b" &{ return b === undefined; }) "c"',
options
);
@ -543,7 +543,7 @@ describe("generated parser behavior", function() {
});
it("cannot access variables defined by following labeled elements", function() {
var parser = PEG.buildParser(
var parser = peg.buildParser(
'start = ("a" &{ return b === "b"; }) b:"b"',
options
);
@ -555,7 +555,7 @@ describe("generated parser behavior", function() {
describe("initializer variables & functions", function() {
it("can access variables defined in the initializer", function() {
var parser = PEG.buildParser([
var parser = peg.buildParser([
'{ var v = 42 }',
'start = &{ return v === 42; }'
].join("\n"), options);
@ -564,7 +564,7 @@ describe("generated parser behavior", function() {
});
it("can access functions defined in the initializer", function() {
var parser = PEG.buildParser([
var parser = peg.buildParser([
'{ function f() { return 42; } }',
'start = &{ return f() === 42; }'
].join("\n"), options);
@ -575,7 +575,7 @@ describe("generated parser behavior", function() {
describe("available variables & functions", function() {
it("|parser| contains the parser object", function() {
var parser = PEG.buildParser([
var parser = peg.buildParser([
'{ var result; }',
'start = &{ result = parser; return true; } { return result; }'
].join("\n"), options);
@ -584,7 +584,7 @@ describe("generated parser behavior", function() {
});
it("|options| contains options", function() {
var parser = PEG.buildParser([
var parser = peg.buildParser([
'{ var result; }',
'start = &{ result = options; return true; } { return result; }'
].join("\n"), options);
@ -593,7 +593,7 @@ describe("generated parser behavior", function() {
});
it("|location| returns current location info", function() {
var parser = PEG.buildParser([
var parser = peg.buildParser([
'{ var result; }',
'start = line (nl+ line)* { return result; }',
'line = thing (" "+ thing)*',
@ -629,7 +629,7 @@ describe("generated parser behavior", function() {
* |undefined| which we can't compare against in |toParse| due to the
* way optional parameters work.
*/
var parser = PEG.buildParser('start = !{ return false; } ""', options);
var parser = peg.buildParser('start = !{ return false; } ""', options);
expect(parser).toParse("", [undefined, ""]);
});
@ -637,7 +637,7 @@ describe("generated parser behavior", function() {
describe("when the code returns a truthy value", function() {
it("reports match failure", function() {
var parser = PEG.buildParser('start = !{ return true; }', options);
var parser = peg.buildParser('start = !{ return true; }', options);
expect(parser).toFailToParse("");
});
@ -646,7 +646,7 @@ describe("generated parser behavior", function() {
describe("label variables", function() {
describe("in containing sequence", function() {
it("can access variables defined by preceding labeled elements", function() {
var parser = PEG.buildParser(
var parser = peg.buildParser(
'start = a:"a" !{ return a !== "a"; }',
options
);
@ -655,7 +655,7 @@ describe("generated parser behavior", function() {
});
it("cannot access variable defined by labeled predicate element", function() {
var parser = PEG.buildParser(
var parser = peg.buildParser(
'start = "a" b:!{ return b !== undefined; } "c"',
options
);
@ -664,7 +664,7 @@ describe("generated parser behavior", function() {
});
it("cannot access variables defined by following labeled elements", function() {
var parser = PEG.buildParser(
var parser = peg.buildParser(
'start = !{ return a !== "a"; } a:"a"',
options
);
@ -722,7 +722,7 @@ describe("generated parser behavior", function() {
parser, i;
for (i = 0; i < testcases.length; i++) {
parser = PEG.buildParser(testcases[i].grammar, options);
parser = peg.buildParser(testcases[i].grammar, options);
expect(parser).toFailToParse(testcases[i].input);
}
});
@ -730,7 +730,7 @@ describe("generated parser behavior", function() {
describe("in outer sequence", function() {
it("can access variables defined by preceding labeled elements", function() {
var parser = PEG.buildParser(
var parser = peg.buildParser(
'start = a:"a" ("b" !{ return a !== "a"; })',
options
);
@ -739,7 +739,7 @@ describe("generated parser behavior", function() {
});
it("cannot access variable defined by labeled predicate element", function() {
var parser = PEG.buildParser(
var parser = peg.buildParser(
'start = "a" b:("b" !{ return b !== undefined; }) "c"',
options
);
@ -748,7 +748,7 @@ describe("generated parser behavior", function() {
});
it("cannot access variables defined by following labeled elements", function() {
var parser = PEG.buildParser(
var parser = peg.buildParser(
'start = ("a" !{ return b !== "b"; }) b:"b"',
options
);
@ -760,7 +760,7 @@ describe("generated parser behavior", function() {
describe("initializer variables & functions", function() {
it("can access variables defined in the initializer", function() {
var parser = PEG.buildParser([
var parser = peg.buildParser([
'{ var v = 42 }',
'start = !{ return v !== 42; }'
].join("\n"), options);
@ -769,7 +769,7 @@ describe("generated parser behavior", function() {
});
it("can access functions defined in the initializer", function() {
var parser = PEG.buildParser([
var parser = peg.buildParser([
'{ function f() { return 42; } }',
'start = !{ return f() !== 42; }'
].join("\n"), options);
@ -780,7 +780,7 @@ describe("generated parser behavior", function() {
describe("available variables & functions", function() {
it("|parser| contains the parser object", function() {
var parser = PEG.buildParser([
var parser = peg.buildParser([
'{ var result; }',
'start = !{ result = parser; return false; } { return result; }'
].join("\n"), options);
@ -789,7 +789,7 @@ describe("generated parser behavior", function() {
});
it("|options| contains options", function() {
var parser = PEG.buildParser([
var parser = peg.buildParser([
'{ var result; }',
'start = !{ result = options; return false; } { return result; }'
].join("\n"), options);
@ -798,7 +798,7 @@ describe("generated parser behavior", function() {
});
it("|location| returns current location info", function() {
var parser = PEG.buildParser([
var parser = peg.buildParser([
'{ var result; }',
'start = line (nl+ line)* { return result; }',
'line = thing (" "+ thing)*',
@ -829,7 +829,7 @@ describe("generated parser behavior", function() {
describe("group", function() {
describe("when the expression matches", function() {
it("returns its match result", function() {
var parser = PEG.buildParser('start = ("a")', options);
var parser = peg.buildParser('start = ("a")', options);
expect(parser).toParse("a", "a");
});
@ -837,7 +837,7 @@ describe("generated parser behavior", function() {
describe("when the expression doesn't match", function() {
it("reports match failure", function() {
var parser = PEG.buildParser('start = ("a")', options);
var parser = peg.buildParser('start = ("a")', options);
expect(parser).toFailToParse("b");
});
@ -847,7 +847,7 @@ describe("generated parser behavior", function() {
describe("optional", function() {
describe("when the expression matches", function() {
it("returns its match result", function() {
var parser = PEG.buildParser('start = "a"?', options);
var parser = peg.buildParser('start = "a"?', options);
expect(parser).toParse("a", "a");
});
@ -855,7 +855,7 @@ describe("generated parser behavior", function() {
describe("when the expression doesn't match", function() {
it("returns |null|", function() {
var parser = PEG.buildParser('start = "a"?', options);
var parser = peg.buildParser('start = "a"?', options);
expect(parser).toParse("", null);
});
@ -865,7 +865,7 @@ describe("generated parser behavior", function() {
describe("zero or more", function() {
describe("when the expression matches zero or more times", function() {
it("returns an array of its match results", function() {
var parser = PEG.buildParser('start = "a"*', options);
var parser = peg.buildParser('start = "a"*', options);
expect(parser).toParse("", []);
expect(parser).toParse("a", ["a"]);
@ -877,7 +877,7 @@ describe("generated parser behavior", function() {
describe("one or more", function() {
describe("when the expression matches one or more times", function() {
it("returns an array of its match results", function() {
var parser = PEG.buildParser('start = "a"+', options);
var parser = peg.buildParser('start = "a"+', options);
expect(parser).toParse("a", ["a"]);
expect(parser).toParse("aaa", ["a", "a", "a"]);
@ -886,7 +886,7 @@ describe("generated parser behavior", function() {
describe("when the expression doesn't match", function() {
it("reports match failure", function() {
var parser = PEG.buildParser('start = "a"+', options);
var parser = peg.buildParser('start = "a"+', options);
expect(parser).toFailToParse("");
});
@ -896,7 +896,7 @@ describe("generated parser behavior", function() {
describe("text", function() {
describe("when the expression matches", function() {
it("returns the matched text", function() {
var parser = PEG.buildParser('start = $("a" "b" "c")', options);
var parser = peg.buildParser('start = $("a" "b" "c")', options);
expect(parser).toParse("abc", "abc");
});
@ -904,7 +904,7 @@ describe("generated parser behavior", function() {
describe("when the expression doesn't match", function() {
it("reports match failure", function() {
var parser = PEG.buildParser('start = $("a")', options);
var parser = peg.buildParser('start = $("a")', options);
expect(parser).toFailToParse("b");
});
@ -914,13 +914,13 @@ describe("generated parser behavior", function() {
describe("positive simple predicate", function() {
describe("when the expression matches", function() {
it("returns |undefined|", function() {
var parser = PEG.buildParser('start = &"a" "a"', options);
var parser = peg.buildParser('start = &"a" "a"', options);
expect(parser).toParse("a", [undefined, "a"]);
});
it("resets parse position", function() {
var parser = PEG.buildParser('start = &"a" "a"', options);
var parser = peg.buildParser('start = &"a" "a"', options);
expect(parser).toParse("a");
});
@ -928,13 +928,13 @@ describe("generated parser behavior", function() {
describe("when the expression doesn't match", function() {
it("reports match failure", function() {
var parser = PEG.buildParser('start = &"a"', options);
var parser = peg.buildParser('start = &"a"', options);
expect(parser).toFailToParse("b");
});
it("discards any expectations recorded when matching the expression", function() {
var parser = PEG.buildParser('start = "a" / &"b" / "c"', options);
var parser = peg.buildParser('start = "a" / &"b" / "c"', options);
expect(parser).toFailToParse("d", {
expected: [
@ -949,7 +949,7 @@ describe("generated parser behavior", function() {
describe("negative simple predicate", function() {
describe("when the expression matches", function() {
it("reports match failure", function() {
var parser = PEG.buildParser('start = !"a"', options);
var parser = peg.buildParser('start = !"a"', options);
expect(parser).toFailToParse("a");
});
@ -957,19 +957,19 @@ describe("generated parser behavior", function() {
describe("when the expression doesn't match", function() {
it("returns |undefined|", function() {
var parser = PEG.buildParser('start = !"a" "b"', options);
var parser = peg.buildParser('start = !"a" "b"', options);
expect(parser).toParse("b", [undefined, "b"]);
});
it("resets parse position", function() {
var parser = PEG.buildParser('start = !"a" "b"', options);
var parser = peg.buildParser('start = !"a" "b"', options);
expect(parser).toParse("b");
});
it("discards any expectations recorded when matching the expression", function() {
var parser = PEG.buildParser('start = "a" / !"b" / "c"', options);
var parser = peg.buildParser('start = "a" / !"b" / "c"', options);
expect(parser).toFailToParse("b", {
expected: [
@ -984,7 +984,7 @@ describe("generated parser behavior", function() {
describe("label", function() {
describe("when the expression matches", function() {
it("returns its match result", function() {
var parser = PEG.buildParser('start = a:"a"', options);
var parser = peg.buildParser('start = a:"a"', options);
expect(parser).toParse("a", "a");
});
@ -992,7 +992,7 @@ describe("generated parser behavior", function() {
describe("when the expression doesn't match", function() {
it("reports match failure", function() {
var parser = PEG.buildParser('start = a:"a"', options);
var parser = peg.buildParser('start = a:"a"', options);
expect(parser).toFailToParse("b");
});
@ -1002,7 +1002,7 @@ describe("generated parser behavior", function() {
describe("sequence", function() {
describe("when all expressions match", function() {
it("returns an array of their match results", function() {
var parser = PEG.buildParser('start = "a" "b" "c"', options);
var parser = peg.buildParser('start = "a" "b" "c"', options);
expect(parser).toParse("abc", ["a", "b", "c"]);
});
@ -1010,7 +1010,7 @@ describe("generated parser behavior", function() {
describe("when any expression doesn't match", function() {
it("reports match failure", function() {
var parser = PEG.buildParser('start = "a" "b" "c"', options);
var parser = peg.buildParser('start = "a" "b" "c"', options);
expect(parser).toFailToParse("dbc");
expect(parser).toFailToParse("adc");
@ -1018,7 +1018,7 @@ describe("generated parser behavior", function() {
});
it("resets parse position", function() {
var parser = PEG.buildParser('start = "a" "b" / "a"', options);
var parser = peg.buildParser('start = "a" "b" / "a"', options);
expect(parser).toParse("a", "a");
});
@ -1028,7 +1028,7 @@ describe("generated parser behavior", function() {
describe("action", function() {
describe("when the expression matches", function() {
it("returns the value returned by the code", function() {
var parser = PEG.buildParser('start = "a" { return 42; }', options);
var parser = peg.buildParser('start = "a" { return 42; }', options);
expect(parser).toParse("a", 42);
});
@ -1036,13 +1036,13 @@ describe("generated parser behavior", function() {
describe("label variables", function() {
describe("in the expression", function() {
it("can access variable defined by labeled expression", function() {
var parser = PEG.buildParser('start = a:"a" { return a; }', options);
var parser = peg.buildParser('start = a:"a" { return a; }', options);
expect(parser).toParse("a", "a");
});
it("can access variables defined by labeled sequence elements", function() {
var parser = PEG.buildParser(
var parser = peg.buildParser(
'start = a:"a" b:"b" c:"c" { return [a, b, c]; }',
options
);
@ -1100,7 +1100,7 @@ describe("generated parser behavior", function() {
parser, i;
for (i = 0; i < testcases.length; i++) {
parser = PEG.buildParser(testcases[i].grammar, options);
parser = peg.buildParser(testcases[i].grammar, options);
expect(parser).toFailToParse(testcases[i].input);
}
});
@ -1108,7 +1108,7 @@ describe("generated parser behavior", function() {
describe("in outer sequence", function() {
it("can access variables defined by preceding labeled elements", function() {
var parser = PEG.buildParser(
var parser = peg.buildParser(
'start = a:"a" ("b" { return a; })',
options
);
@ -1117,7 +1117,7 @@ describe("generated parser behavior", function() {
});
it("cannot access variable defined by labeled action element", function() {
var parser = PEG.buildParser(
var parser = peg.buildParser(
'start = "a" b:("b" { return b; }) c:"c"',
options
);
@ -1126,7 +1126,7 @@ describe("generated parser behavior", function() {
});
it("cannot access variables defined by following labeled elements", function() {
var parser = PEG.buildParser(
var parser = peg.buildParser(
'start = ("a" { return b; }) b:"b"',
options
);
@ -1138,7 +1138,7 @@ describe("generated parser behavior", function() {
describe("initializer variables & functions", function() {
it("can access variables defined in the initializer", function() {
var parser = PEG.buildParser([
var parser = peg.buildParser([
'{ var v = 42 }',
'start = "a" { return v; }'
].join("\n"), options);
@ -1147,7 +1147,7 @@ describe("generated parser behavior", function() {
});
it("can access functions defined in the initializer", function() {
var parser = PEG.buildParser([
var parser = peg.buildParser([
'{ function f() { return 42; } }',
'start = "a" { return f(); }'
].join("\n"), options);
@ -1158,7 +1158,7 @@ describe("generated parser behavior", function() {
describe("available variables & functions", function() {
it("|parser| contains the parser object", function() {
var parser = PEG.buildParser(
var parser = peg.buildParser(
'start = "a" { return parser; }',
options
);
@ -1167,7 +1167,7 @@ describe("generated parser behavior", function() {
});
it("|options| contains options", function() {
var parser = PEG.buildParser(
var parser = peg.buildParser(
'start = "a" { return options; }',
options
);
@ -1176,7 +1176,7 @@ describe("generated parser behavior", function() {
});
it("|text| returns text matched by the expression", function() {
var parser = PEG.buildParser(
var parser = peg.buildParser(
'start = "a" { return text(); }',
options
);
@ -1185,7 +1185,7 @@ describe("generated parser behavior", function() {
});
it("|location| returns location info of the expression", function() {
var parser = PEG.buildParser([
var parser = peg.buildParser([
'{ var result; }',
'start = line (nl+ line)* { return result; }',
'line = thing (" "+ thing)*',
@ -1213,7 +1213,7 @@ describe("generated parser behavior", function() {
describe("|expected|", function() {
it("terminates parsing and throws an exception", function() {
var parser = PEG.buildParser(
var parser = peg.buildParser(
'start = "a" { expected("a"); }',
options
);
@ -1229,7 +1229,7 @@ describe("generated parser behavior", function() {
});
it("allows to set custom location info", function() {
var parser = PEG.buildParser([
var parser = peg.buildParser([
'start = "a" {',
' expected("a", {',
' start: { offset: 1, line: 1, column: 2 },',
@ -1251,7 +1251,7 @@ describe("generated parser behavior", function() {
describe("|error|", function() {
it("terminates parsing and throws an exception", function() {
var parser = PEG.buildParser(
var parser = peg.buildParser(
'start = "a" { error("a"); }',
options
);
@ -1267,7 +1267,7 @@ describe("generated parser behavior", function() {
});
it("allows to set custom location info", function() {
var parser = PEG.buildParser([
var parser = peg.buildParser([
'start = "a" {',
' error("a", {',
' start: { offset: 1, line: 1, column: 2 },',
@ -1291,13 +1291,13 @@ describe("generated parser behavior", function() {
describe("when the expression doesn't match", function() {
it("reports match failure", function() {
var parser = PEG.buildParser('start = "a" { return 42; }', options);
var parser = peg.buildParser('start = "a" { return 42; }', options);
expect(parser).toFailToParse("b");
});
it("doesn't execute the code", function() {
var parser = PEG.buildParser(
var parser = peg.buildParser(
'start = "a" { throw "Boom!"; } / "b"',
options
);
@ -1310,7 +1310,7 @@ describe("generated parser behavior", function() {
describe("choice", function() {
describe("when any expression matches", function() {
it("returns its match result", function() {
var parser = PEG.buildParser('start = "a" / "b" / "c"', options);
var parser = peg.buildParser('start = "a" / "b" / "c"', options);
expect(parser).toParse("a", "a");
expect(parser).toParse("b", "b");
@ -1320,7 +1320,7 @@ describe("generated parser behavior", function() {
describe("when all expressions don't match", function() {
it("reports match failure", function() {
var parser = PEG.buildParser('start = "a" / "b" / "c"', options);
var parser = peg.buildParser('start = "a" / "b" / "c"', options);
expect(parser).toFailToParse("d");
});
@ -1330,7 +1330,7 @@ describe("generated parser behavior", function() {
describe("error reporting", function() {
describe("behavior", function() {
it("reports only the rightmost error", function() {
var parser = PEG.buildParser('start = "a" "b" / "a" "c" "d"', options);
var parser = peg.buildParser('start = "a" "b" / "a" "c" "d"', options);
expect(parser).toFailToParse("ace", {
expected: [{ type: "literal", value: "d", description: '"d"' }]
@ -1340,7 +1340,7 @@ describe("generated parser behavior", function() {
describe("expectations reporting", function() {
it("reports expectations correctly with no alternative", function() {
var parser = PEG.buildParser('start = "a"', options);
var parser = peg.buildParser('start = "a"', options);
expect(parser).toFailToParse("ab", {
expected: [{ type: "end", description: "end of input" }]
@ -1348,7 +1348,7 @@ describe("generated parser behavior", function() {
});
it("reports expectations correctly with one alternative", function() {
var parser = PEG.buildParser('start = "a"', options);
var parser = peg.buildParser('start = "a"', options);
expect(parser).toFailToParse("b", {
expected: [{ type: "literal", value: "a", description: '"a"' }]
@ -1356,7 +1356,7 @@ describe("generated parser behavior", function() {
});
it("reports expectations correctly with multiple alternatives", function() {
var parser = PEG.buildParser('start = "a" / "b" / "c"', options);
var parser = peg.buildParser('start = "a" / "b" / "c"', options);
expect(parser).toFailToParse("d", {
expected: [
@ -1375,7 +1375,7 @@ describe("generated parser behavior", function() {
*
* See https://github.com/pegjs/pegjs/pull/146.
*/
var parser = PEG.buildParser('start = "a" / "a" / "a"', options);
var parser = peg.buildParser('start = "a" / "a" / "a"', options);
expect(parser).toFailToParse("b", {
expected: [{ type: "literal", value: "a", description: '"a"' }]
@ -1383,7 +1383,7 @@ describe("generated parser behavior", function() {
});
it("sorts expectations", function() {
var parser = PEG.buildParser('start = "c" / "b" / "a"', options);
var parser = peg.buildParser('start = "c" / "b" / "a"', options);
expect(parser).toFailToParse("d", {
expected: [
@ -1397,7 +1397,7 @@ describe("generated parser behavior", function() {
describe("message building", function() {
it("builds message correctly with no alternative", function() {
var parser = PEG.buildParser('start = "a"', options);
var parser = peg.buildParser('start = "a"', options);
expect(parser).toFailToParse("ab", {
message: 'Expected end of input.'
@ -1405,7 +1405,7 @@ describe("generated parser behavior", function() {
});
it("builds message correctly with one alternative", function() {
var parser = PEG.buildParser('start = "a"', options);
var parser = peg.buildParser('start = "a"', options);
expect(parser).toFailToParse("b", {
message: 'Expected "a".'
@ -1413,7 +1413,7 @@ describe("generated parser behavior", function() {
});
it("builds message correctly with multiple alternatives", function() {
var parser = PEG.buildParser('start = "a" / "b" / "c"', options);
var parser = peg.buildParser('start = "a" / "b" / "c"', options);
expect(parser).toFailToParse("d", {
message: 'Expected "a", "b" or "c".'
@ -1423,7 +1423,7 @@ describe("generated parser behavior", function() {
describe("position reporting", function() {
it("reports position correctly with no trailing input", function() {
var parser = PEG.buildParser('start = "a"', options);
var parser = peg.buildParser('start = "a"', options);
expect(parser).toFailToParse("b", {
location: {
@ -1434,7 +1434,7 @@ describe("generated parser behavior", function() {
});
it("reports position correctly with trailing input", function() {
var parser = PEG.buildParser('start = "a"', options);
var parser = peg.buildParser('start = "a"', options);
expect(parser).toFailToParse("aa", {
location: {
@ -1445,7 +1445,7 @@ describe("generated parser behavior", function() {
});
it("reports position correctly in complex cases", function() {
var parser = PEG.buildParser([
var parser = peg.buildParser([
'start = line (nl+ line)*',
'line = digit (" "+ digit)*',
'digit = [0-9]',
@ -1488,7 +1488,7 @@ describe("generated parser behavior", function() {
* Sum Product (('+' / '-') Product)*
* Expr Sum
*/
var parser = PEG.buildParser([
var parser = peg.buildParser([
'Expr = Sum',
'Sum = first:Product rest:(("+" / "-") Product)* {',
' var result = first, i;',
@ -1544,7 +1544,7 @@ describe("generated parser behavior", function() {
* A a A? b
* B b B? c
*/
var parser = PEG.buildParser([
var parser = peg.buildParser([
'S = &(A "c") a:"a"+ B:B !("a" / "b" / "c") { return a.join("") + B; }',
'A = a:"a" A:A? b:"b" { return [a, A, b].join(""); }',
'B = b:"b" B:B? c:"c" { return [b, B, c].join(""); }'
@ -1568,7 +1568,7 @@ describe("generated parser behavior", function() {
* N C / (!Begin !End Z)
* Z any single character
*/
var parser = PEG.buildParser([
var parser = peg.buildParser([
'C = begin:Begin ns:N* end:End { return begin + ns.join("") + end; }',
'N = C',
' / !Begin !End z:Z { return z; }',

@ -4,6 +4,6 @@
(function(root) {
if (typeof module !== 'undefined') {
root.PEG = require("../lib/peg.js");
root.peg = require("../lib/peg.js");
}
}(this));

@ -1,9 +1,9 @@
/* global PEG */
/* global peg */
"use strict";
describe("compiler pass |generateBytecode|", function() {
var pass = PEG.compiler.passes.generate.generateBytecode;
var pass = peg.compiler.passes.generate.generateBytecode;
function bytecodeDetails(bytecode) {
return {

@ -1,4 +1,4 @@
/* global PEG */
/* global peg */
"use strict";
@ -44,7 +44,7 @@ beforeEach(function() {
}
}
var ast = PEG.parser.parse(grammar);
var ast = peg.parser.parse(grammar);
this.actual(ast, options);
@ -61,7 +61,7 @@ beforeEach(function() {
},
toReportError: function(grammar, details) {
var ast = PEG.parser.parse(grammar);
var ast = peg.parser.parse(grammar);
try {
this.actual(ast);

@ -1,9 +1,9 @@
/* global PEG */
/* global peg */
"use strict";
describe("compiler pass |removeProxyRules|", function() {
var pass = PEG.compiler.passes.transform.removeProxyRules;
var pass = peg.compiler.passes.transform.removeProxyRules;
describe("when a proxy rule isn't listed in |allowedStartRules|", function() {
it("updates references and removes it", function() {

@ -1,9 +1,9 @@
/* global PEG */
/* global peg */
"use strict";
describe("compiler pass |reportInfiniteLoops|", function() {
var pass = PEG.compiler.passes.check.reportInfiniteLoops;
var pass = peg.compiler.passes.check.reportInfiniteLoops;
it("reports infinite loops for zero_or_more", function() {
expect(pass).toReportError('start = ("")*', {

@ -1,9 +1,9 @@
/* global PEG */
/* global peg */
"use strict";
describe("compiler pass |reportLeftRecursion|", function() {
var pass = PEG.compiler.passes.check.reportLeftRecursion;
var pass = peg.compiler.passes.check.reportLeftRecursion;
it("reports direct left recursion", function() {
expect(pass).toReportError('start = start', {

@ -1,9 +1,9 @@
/* global PEG */
/* global peg */
"use strict";
describe("compiler pass |reportMissingRules|", function() {
var pass = PEG.compiler.passes.check.reportMissingRules;
var pass = peg.compiler.passes.check.reportMissingRules;
it("reports missing rules", function() {
expect(pass).toReportError('start = missing', {

@ -1,4 +1,4 @@
/* global PEG */
/* global peg */
"use strict";
@ -182,7 +182,7 @@ describe("PEG.js grammar parser", function() {
var result;
try {
result = PEG.parser.parse(this.actual);
result = peg.parser.parse(this.actual);
stripLocation(result);
@ -210,7 +210,7 @@ describe("PEG.js grammar parser", function() {
var result;
try {
result = PEG.parser.parse(this.actual);
result = peg.parser.parse(this.actual);
stripLocation(result);

Loading…
Cancel
Save