From a1dcd245bb0197b3a067620dd5c018a0df9af0a6 Mon Sep 17 00:00:00 2001 From: David Majda Date: Wed, 21 Apr 2010 21:26:45 +0200 Subject: [PATCH] Action AST node no longer accepts functions as actions (only strings). --- lib/compiler.js | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/lib/compiler.js b/lib/compiler.js index a4008ef..06ae83b 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -993,23 +993,19 @@ PEG.Grammar.RuleRef.prototype.compile = function(resultVar) { PEG.Grammar.Action.prototype.compile = function(resultVar) { var expressionResultVar = PEG.Compiler.generateUniqueIdentifier("result"); - if (typeof(this._action) === "function") { - var actionFunction = this._action.toString(); - } else { - var actionCode = this._action.replace( - /\$(\d+)/g, - function(match, digits) { - return PEG.Compiler.formatCode( - "(arguments[${index}])", - { index: parseInt(digits) - 1 } - ); - } - ) - var actionFunction = PEG.Compiler.formatCode( - "function() { ${actionCode} }", - { actionCode: actionCode } - ); - } + var actionCode = this._action.replace( + /\$(\d+)/g, + function(match, digits) { + return PEG.Compiler.formatCode( + "(arguments[${index}])", + { index: parseInt(digits) - 1 } + ); + } + ) + var actionFunction = PEG.Compiler.formatCode( + "function() { ${actionCode} }", + { actionCode: actionCode } + ); /* * In case of sequences, we splat their elements into function arguments one