From ac179cda7bae7bef539d235e3f66e5eed92b50ef Mon Sep 17 00:00:00 2001 From: Justin Blank Date: Fri, 7 Dec 2012 17:32:58 -0500 Subject: [PATCH] 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 4cda79951a2b502dd6d1c0df8fe2ed45464bb9b7. Fixes GH-135. --- lib/compiler/passes/report-left-recursion.js | 5 +++-- lib/compiler/passes/report-missing-rules.js | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/compiler/passes/report-left-recursion.js b/lib/compiler/passes/report-left-recursion.js index 1c6a7d9..5c8592d 100644 --- a/lib/compiler/passes/report-left-recursion.js +++ b/lib/compiler/passes/report-left-recursion.js @@ -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 + "\"." ); } diff --git a/lib/compiler/passes/report-missing-rules.js b/lib/compiler/passes/report-missing-rules.js index f600862..c1193bc 100644 --- a/lib/compiler/passes/report-missing-rules.js +++ b/lib/compiler/passes/report-missing-rules.js @@ -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." ); }