diff --git a/src/compiler/passes/generate-code.js b/src/compiler/passes/generate-code.js index 7bf6b7b..92d3a3c 100644 --- a/src/compiler/passes/generate-code.js +++ b/src/compiler/passes/generate-code.js @@ -273,6 +273,13 @@ PEG.compiler.passes.generateCode = function(ast, options) { ' * http://pegjs.majda.cz/', ' */', ' ', + /* This needs to be in sync with |subclass| in utils.js. */ + ' function subclass(child, parent) {', + ' function ctor() { this.constructor = child; }', + ' ctor.prototype = parent.prototype;', + ' child.prototype = new ctor();', + ' }', + ' ', /* This needs to be in sync with |quote| in utils.js. */ ' function quote(s) {', ' /*', @@ -546,7 +553,7 @@ PEG.compiler.passes.generateCode = function(ast, options) { ' this.column = column;', ' };', ' ', - ' result.SyntaxError.prototype = Error.prototype;', + ' subclass(result.SyntaxError, Error);', ' ', ' return result;', '})()' diff --git a/src/utils.js b/src/utils.js index 967168f..e97a3da 100644 --- a/src/utils.js +++ b/src/utils.js @@ -87,6 +87,10 @@ function defaults(object, defaults) { } } +/* + * The code needs to be in sync with the code template in the compilation + * function for "action" nodes. + */ function subclass(child, parent) { function ctor() { this.constructor = child; } ctor.prototype = parent.prototype;