Exemplo n.º 1
0
    function it_should_create_a_rule_from_a_node()
    {
        $ruleNode = new RuleNode('Foo', '"expression"', new RuleReferenceNode('Bar'));
        $ruleCode = <<<EOS
protected function parseFoo()
{
    \$_position = \$this->position;

    if (isset(\$this->cache['Foo'][\$_position])) {
        \$_success = \$this->cache['Foo'][\$_position]['success'];
        \$this->position = \$this->cache['Foo'][\$_position]['position'];
        \$this->value = \$this->cache['Foo'][\$_position]['value'];

        return \$_success;
    }

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

    \$this->cache['Foo'][\$_position] = array(
        'success' => \$_success,
        'position' => \$this->position,
        'value' => \$this->value
    );

    if (!\$_success) {
        \$this->report(\$_position, "expression");
    }

    return \$_success;
}
EOS;
        $ruleNode->accept($this->getWrappedObject());
        $this->getResult()->shouldBe($ruleCode);
    }
Exemplo n.º 2
0
 function it_should_accept_a_visitor(RuleNode $rule, VisitorInterface $visitor)
 {
     $rule->accept($visitor)->shouldBeCalled();
     $visitor->visitGrammar($this)->shouldBeCalled();
     $this->accept($visitor);
 }