function it_should_create_an_extended_grammar_from_a_node() { $grammarNode = new GrammarNode('FooFile', array(new RuleNode('Foo', '"Foo"', new RuleReferenceNode('Bar')))); $grammarNode->setNamespace('Acme\\Factory'); $grammarNode->setImports(array('Acme\\FactoryInterface', 'Acme\\BaseFile')); $grammarNode->setBase('BaseFile'); $grammarCode = <<<EOS namespace Acme\\Factory; use Acme\\FactoryInterface; use Acme\\BaseFile; class FooFile extends BaseFile { 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, "Foo"); } return \$_success; } } EOS; $grammarNode->accept($this->getWrappedObject()); $this->getResult()->shouldBe($grammarCode); }
function it_should_parse_namespaces_and_imports() { $tree = new GrammarNode('TestFile', array(new RuleNode('File', "'File'", new LiteralNode('"foo"', false)))); $tree->setNamespace('Acme\\Test'); $tree->setImports(array('Acme\\Factory')); $tree->setStartSymbol('File'); $this->parse('namespace Acme\\Test; use Acme\\Factory; grammar TestFile { start File = "foo"; }')->shouldBeLike($tree); }