Esempio n. 1
0
 function it_should_accept_a_visitor(RuleNode $rule, VisitorInterface $visitor)
 {
     $rule->accept($visitor)->shouldBeCalled();
     $visitor->visitGrammar($this)->shouldBeCalled();
     $this->accept($visitor);
 }
Esempio n. 2
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);
    }
Esempio n. 3
0
    public function visitRule(RuleNode $node)
    {
        $this->scope = array();
        $this->results[] = <<<EOS
protected function parse{$node->getIdentifier()}()
{
    \$_position = \$this->position;

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

        return \$_success;
    }

    {$this->indent($this->getResult())}

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

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

    return \$_success;
}
EOS;
    }