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.
redux
David Majda 11 years ago
parent 379f5c5eef
commit c6efb337f1

@ -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), {

Loading…
Cancel
Save