Esempio n. 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();
     }
 }
Esempio n. 2
0
 /**
  * Parses the given token reader
  *
  * @param \vc\Data\Type\IFace $iface The interface to fill with data
  * @param \vc\Tokens\Access $access The token access
  * @return NULL
  */
 public function parseMembers(\vc\Data\Type\IFace $iface, \vc\Tokens\Access $access)
 {
     $last = NULL;
     // Limit the token stream to just the current block scope
     $access = $access->untilBlockEnds();
     // Keep looking until we have consumed all the members of this class
     while ($access->hasToken()) {
         try {
             $token = $access->peekToRequired(array(Token::T_CONST, Token::T_STATIC, Token::T_FUNCTION, Token::T_PUBLIC, Token::T_PROTECTED, Token::T_PRIVATE));
         } catch (\vc\Tokens\Exception\UnexpectedEnd $err) {
             return NULL;
         }
         // This loop doesn't itself pop any tokens off, so this check just
         // ensures that the parsers below this one don't do anything
         // stupid.
         if ($token === $last) {
             throw new \RuntimeException('Possible Infinite Loop Detected. ' . 'Current token has already been parsed');
         }
         $last = $token;
         // Otherwise, we delegate to the appropraite parser
         if ($token->is(Token::T_CONST)) {
             $iface->addConstant($this->constant->parseConstant($access));
         } else {
             $iface->addMethod($this->method->parseMethod(new \vc\Data\Signature($token->getLine(), $access->getComment()), $access));
         }
     }
 }