function it_should_create_a_choice_from_a_node() { $choiceNode = new ChoiceNode(array(new RuleReferenceNode('Foo'), new RuleReferenceNode('Bar'))); $choiceCode = <<<EOS \$_position1 = \$this->position; \$_cut2 = \$this->cut; \$this->cut = false; \$_success = \$this->parseFoo(); if (!\$_success && !\$this->cut) { \$this->position = \$_position1; \$_success = \$this->parseBar(); } \$this->cut = \$_cut2; EOS; $choiceNode->accept($this->getWrappedObject()); $this->getResult()->shouldBe($choiceCode); }
public function visitChoice(ChoiceNode $node) { $position = $this->id('position'); $cut = $this->id('cut'); $pieces = $this->getResults($node->getLength()); $result = <<<EOS {$position} = \$this->position; {$cut} = \$this->cut; \$this->cut = false; {$pieces[0]} EOS; foreach (array_slice($pieces, 1) as $piece) { $result .= <<<EOS if (!\$_success && !\$this->cut) { \$this->position = {$position}; {$this->indent($piece)} } EOS; } $result .= <<<EOS \$this->cut = {$cut}; EOS; $this->results[] = $result; }