Fix ReferenceError in compiler passes.

Previously, the report-left-recursion and report-missing-rules passes
used PEG.GrammarError without requiring it, causing a ReferenceError.

Since requiring lib/peg.js would cause circular requirements, this
commit imports lib/grammar-error.js as GrammarError.

The bug was introduced in commit
4cda79951a.

Fixes GH-135.
redux
Justin Blank 12 years ago
parent c54483bb17
commit ac179cda7b

@ -1,4 +1,5 @@
var utils = require("../../utils");
var utils = require("../../utils"),
GrammarError = require("../../grammar-error.js");
/* Checks that no left recursion is present. */
module.exports = function(ast) {
@ -48,7 +49,7 @@ module.exports = function(ast) {
rule_ref:
function(node, appliedRules) {
if (utils.contains(appliedRules, node.name)) {
throw new PEG.GrammarError(
throw new GrammarError(
"Left recursion detected for rule \"" + node.name + "\"."
);
}

@ -1,4 +1,5 @@
var utils = require("../../utils");
var utils = require("../../utils"),
GrammarError = require("../../grammar-error.js");
/* Checks that all referenced rules exist. */
module.exports = function(ast) {
@ -30,7 +31,7 @@ module.exports = function(ast) {
rule_ref:
function(node) {
if (!utils.findRuleByName(ast, node.name)) {
throw new PEG.GrammarError(
throw new GrammarError(
"Referenced rule \"" + node.name + "\" does not exist."
);
}

Loading…
Cancel
Save