示例#1
0
文件: Parser.php 项目: kidaa30/redcat
 /**
  * Parse a use declaration.
  * @return UseDeclarationNode
  */
 private function useDeclaration()
 {
     $declaration = new UseDeclarationNode();
     $node = new NameNode();
     $this->tryMatch(T_NS_SEPARATOR, $node);
     $this->mustMatch(T_STRING, $node, NULL, TRUE)->getText();
     while ($this->tryMatch(T_NS_SEPARATOR, $node)) {
         $this->mustMatch(T_STRING, $node, NULL, TRUE)->getText();
     }
     $declaration->addChild($node, 'name');
     if ($this->tryMatch(T_AS, $declaration)) {
         $this->mustMatch(T_STRING, $declaration, 'alias', TRUE)->getText();
     }
     return $declaration;
 }
 public function testCreate()
 {
     $declaration = UseDeclarationNode::create('Cleese as Chapman');
     $this->assertEquals('Cleese', $declaration->getName()->getText());
     $this->assertEquals('Chapman', $declaration->getAlias()->getText());
 }