Пример #1
0
 /**
  * Parses the given token reader
  *
  * @param \vc\Data\Object\Cls $class The class to fill with data
  * @param \vc\Tokens\Access $access The token access
  * @return NULL
  */
 public function parseSignature(\vc\Data\Type\Cls $class, \vc\Tokens\Access $access)
 {
     $sig = new \vc\Data\Signature($access->peekAtToken()->getLine(), $access->getComment());
     // Keep collecting tokens until we find one that differentiates this
     // signature between a method and a property. This isn't as strict
     // as it could be, but it's already complex
     while (TRUE) {
         $token = $access->peekToRequired(array(Token::T_STATIC, Token::T_PUBLIC, Token::T_PROTECTED, Token::T_PRIVATE, Token::T_ABSTRACT, Token::T_FINAL, Token::T_FUNCTION, Token::T_VAR, Token::T_VARIABLE));
         // These tokens denote a definite method
         if ($token->is(array(Token::T_ABSTRACT, Token::T_FINAL, Token::T_FUNCTION))) {
             $class->addMethod($this->methods->parseMethod($sig, $access));
             return;
         } else {
             if ($token->is(array(Token::T_VAR, Token::T_VARIABLE))) {
                 $class->addProperty($this->properties->parseProperty($sig, $access));
                 return;
             } else {
                 if ($token->is(array(Token::T_PUBLIC, Token::T_PROTECTED, Token::T_PRIVATE))) {
                     $sig->setVisibility(\vc\Data\Visibility::fromToken($token));
                 } else {
                     if ($token->is(Token::T_STATIC)) {
                         $sig->setStatic(TRUE);
                     }
                 }
             }
         }
         // By this point, we have already determined that this token isn't
         // needed downstream, so we can pop it safely
         $access->popToken();
     }
 }
Пример #2
0
 /**
  * Parse a class from token reader
  *
  * @param \vc\Tokens\Access $access The token access
  * @return \vc\Data\Routine\Func
  */
 public function parseClass(\vc\Tokens\Access $access)
 {
     $token = $access->findRequired(array(Token::T_CLASS, Token::T_ABSTRACT));
     $class = new \vc\Data\Type\Cls($token->getLine(), $access->getComment());
     // Extract the abstract flag from the class definition
     if ($token->is(Token::T_ABSTRACT)) {
         $class->setAbstract(TRUE);
         $access->findRequired(array(Token::T_CLASS));
     }
     // Searches for the name of the class
     $token = $access->findRequired(array(Token::T_STRING));
     // Set the name of the class
     $class->setName($token->getContent());
     // Look for parent classes and interfaces
     $token = $access->findRequired(array(Token::T_EXTENDS, Token::T_IMPLEMENTS, Token::T_CURLY_OPEN));
     // Add the parent class
     if ($token->is(Token::T_EXTENDS)) {
         $class->setExtends($this->path->parsePath($access));
         // Look for any interfaces
         $token = $access->findRequired(array(Token::T_IMPLEMENTS, Token::T_CURLY_OPEN));
     }
     // Add any interface implementations
     if ($token->is(Token::T_IMPLEMENTS)) {
         $class->setIFaces($this->pathList->parsePathList($access));
         $access->findRequired(array(Token::T_CURLY_OPEN));
     }
     // Finally, parse out the content of the class
     $this->members->parseMembers($class, $access);
     return $class;
 }
Пример #3
0
 /**
  * Parse a function out of the given token reader
  *
  * @param \vc\Tokens\Access $access The token access
  * @return \vc\Data\Routine\Func
  */
 public function parseFunc(\vc\Tokens\Access $access)
 {
     $token = $access->peekToRequired(array(Token::T_FUNCTION));
     $func = new \vc\Data\Routine\Func($token->getLine(), $access->getComment());
     $this->routine->parseRoutine($func, $access);
     return $func;
 }
Пример #4
0
 /**
  * Parse an interface from token reader
  *
  * @param \vc\Tokens\Access $access The token access
  * @return \vc\Data\Routine\Func
  */
 public function parseIFace(\vc\Tokens\Access $access)
 {
     $token = $access->findRequired(array(Token::T_INTERFACE));
     $iface = new \vc\Data\Type\IFace($token->getLine(), $access->getComment());
     // Searches for the name of the interface
     $token = $access->findRequired(array(Token::T_STRING));
     $iface->setName($token->getContent());
     // Look for any interfaces that this one extends
     $token = $access->findRequired(array(Token::T_EXTENDS, Token::T_CURLY_OPEN));
     if ($token->is(Token::T_EXTENDS)) {
         $iface->setExtends($this->pathList->parsePathList($access));
         $access->findRequired(array(Token::T_CURLY_OPEN));
     }
     // Finally, parse out the content of the class
     $this->members->parseMembers($iface, $access);
     return $iface;
 }