diff --git a/src/peg.js b/src/peg.js index fd6522f..0150dca 100644 --- a/src/peg.js +++ b/src/peg.js @@ -8,6 +8,8 @@ */ var PEG = (function(undefined) { +// @include "utils.js" + var PEG = { /* PEG.js version (uses semantic versioning). */ VERSION: "@VERSION", @@ -35,9 +37,8 @@ PEG.GrammarError = function(message) { this.message = message; }; -PEG.GrammarError.prototype = Error.prototype; +subclass(PEG.GrammarError, Error); -// @include "utils.js" // @include "parser.js" // @include "compiler.js" diff --git a/src/utils.js b/src/utils.js index 24e2739..967168f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -87,6 +87,12 @@ function defaults(object, defaults) { } } +function subclass(child, parent) { + function ctor() { this.constructor = child; } + ctor.prototype = parent.prototype; + child.prototype = new ctor(); +} + /* * Returns a string padded on the left to a desired length with a character. *