From cc3bd4f310d1b10f8fb827a0020d21b511c69e70 Mon Sep 17 00:00:00 2001 From: David Majda Date: Fri, 23 Sep 2011 17:45:05 +0200 Subject: [PATCH] Refactor "zero_or_more" emitter function a bit --- src/emitter.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/emitter.js b/src/emitter.js index 011f816..d9dc11f 100644 --- a/src/emitter.js +++ b/src/emitter.js @@ -754,11 +754,6 @@ PEG.compiler.emitter = function(ast) { }, zero_or_more: function(node, context) { - var expressionContext = { - resultIndex: context.resultIndex + 1, - posIndex: context.posIndex - }; - return formatCode( '#{resultVar} = [];', '#block expressionCode', @@ -767,7 +762,10 @@ PEG.compiler.emitter = function(ast) { ' #block expressionCode', '}', { - expressionCode: emit(node.expression, expressionContext), + expressionCode: emit(node.expression, { + resultIndex: context.resultIndex + 1, + posIndex: context.posIndex + }), expressionResultVar: resultVar(context.resultIndex + 1), resultVar: resultVar(context.resultIndex) }