Пример #1
0
    function it_should_create_a_sequence_from_a_node()
    {
        $sequenceNode = new SequenceNode(array(new RuleReferenceNode('Foo'), new RuleReferenceNode('Bar')));
        $sequenceCode = <<<EOS
\$_value1 = array();

\$_success = \$this->parseFoo();

if (\$_success) {
    \$_value1[] = \$this->value;

    \$_success = \$this->parseBar();
}

if (\$_success) {
    \$_value1[] = \$this->value;

    \$this->value = \$_value1;
}
EOS;
        $sequenceNode->accept($this->getWrappedObject());
        $this->getResult()->shouldBe($sequenceCode);
    }
Пример #2
0
    public function visitSequence(SequenceNode $node)
    {
        $value = $this->id('value');
        $pieces = $this->getResults($node->getLength());
        $result = <<<EOS
{$value} = array();

{$pieces[0]}
EOS;
        foreach (array_slice($pieces, 1) as $piece) {
            $result .= <<<EOS


if (\$_success) {
    {$value}[] = \$this->value;

    {$this->indent($piece)}
}
EOS;
        }
        $result .= <<<EOS


if (\$_success) {
    {$value}[] = \$this->value;

    \$this->value = {$value};
}
EOS;
        $this->results[] = $result;
    }