From c6efb337f10a9f0e8b8dd3a8c7d02e58d9ac0c04 Mon Sep 17 00:00:00 2001 From: David Majda Date: Sat, 17 Aug 2013 14:07:35 +0200 Subject: [PATCH] Fix bytecode built for nested sequences inside actions In the bytecode generator, the |context.action| property wasn't correctly reset when generating bytecode for sequence elements. As a result, when a sequence was wrapped in an action and it contained another sequence as an element, the generator thought that the inner sequence was wrapped in an action too. For example, the following grammar: start = ("a" "b") "c" { return "x"; } was compiled as if it looked like this: start = ("a" "b" { return "x"; }) "c" { return "x"; } This commit fixes the problem by resetting |context.action| correctly. Fixes GH-168. --- lib/compiler/passes/generate-bytecode.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/compiler/passes/generate-bytecode.js b/lib/compiler/passes/generate-bytecode.js index f2d00ba..3a88b29 100644 --- a/lib/compiler/passes/generate-bytecode.js +++ b/lib/compiler/passes/generate-bytecode.js @@ -364,7 +364,11 @@ module.exports = function(ast, options) { processedCount = node.elements.length - elements.slice(1).length; return buildSequence( - generate(elements[0], context), + generate(elements[0], { + sp: context.sp, + env: context.env, + action: null + }), buildCondition( [op.IF_NOT_ERROR], buildElementsCode(elements.slice(1), {