Example #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();
     }
 }
Example #2
0
 /**
  * Parses the given token reader
  *
  * @param \vc\Data\Signature $signature The base data from which to build
  *      the method
  * @param \vc\Tokens\Access $access The token stream
  * @return \vc\Data\Routine\Method
  */
 public function parseMethod(\vc\Data\Signature $signature, \vc\Tokens\Access $access)
 {
     $method = $signature->buildMethod();
     // Continue iterating until we encounter a Function token
     while (TRUE) {
         $token = $access->peekToRequired(array(Token::T_STATIC, Token::T_ABSTRACT, Token::T_FINAL, Token::T_PUBLIC, Token::T_PROTECTED, Token::T_PRIVATE, Token::T_FUNCTION));
         // We don't want to consume the function token because the routine
         // parser looks for it. Break before we get a chance to pop it off
         // the stream
         if ($token->is(Token::T_FUNCTION)) {
             break;
         }
         $access->popToken();
         if ($token->is(array(Token::T_PUBLIC, Token::T_PROTECTED, Token::T_PRIVATE))) {
             $method->setVisibility(\vc\Data\Visibility::fromToken($token));
         } else {
             if ($token->is(Token::T_STATIC)) {
                 $method->setStatic(TRUE);
             } else {
                 if ($token->is(Token::T_ABSTRACT)) {
                     $method->setAbstract(TRUE);
                 } else {
                     if ($token->is(Token::T_FINAL)) {
                         $method->setFinal(TRUE);
                     }
                 }
             }
         }
     }
     $this->routine->parseRoutine($method, $access);
     return $method;
 }
Example #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;
 }
Example #4
0
 /**
  * Parse a function out of the given token reader
  *
  * @param \vc\Data\Routine $routine The object to fill with data
  * @param \vc\Tokens\Access $access The token access
  * @return NULL
  */
 public function parseRoutine(\vc\Data\Routine $routine, \vc\Tokens\Access $access)
 {
     $access->findRequired(array(Token::T_FUNCTION));
     $token = $access->peekToRequired(array(Token::T_STRING, Token::T_AMPERSAND, Token::T_PARENS_OPEN));
     // Handle routines that return a reference
     if ($token->is(Token::T_AMPERSAND)) {
         $routine->setReturnRef(TRUE);
         $access->popToken();
         $token = $access->peekToRequired(array(Token::T_STRING, Token::T_PARENS_OPEN));
     }
     // Names are optional because of anonymous methods
     if ($token->is(Token::T_STRING)) {
         $access->popToken();
         $routine->setName($token->getContent());
     }
     $routine->setArgs($this->args->parseArgs($access));
     $access->findRequired(array(Token::T_CURLY_OPEN, Token::T_SEMICOLON));
     $this->brackets->parseCurlies($access);
 }
Example #5
0
 /**
  * Parses a list of method arguments
  *
  * @param \vc\Tokens\Access $access
  * @return Array
  */
 public function parseArgs(\vc\Tokens\Access $access)
 {
     $access->findRequired(array(Token::T_PARENS_OPEN));
     $args = array();
     // Continue parsing until we hit a close parenthesis
     while (TRUE) {
         $type = $access->peekToRequired(array(Token::T_ARRAY, Token::T_STRING, Token::T_NS_SEPARATOR, Token::T_AMPERSAND, Token::T_VARIABLE, Token::T_PARENS_CLOSE));
         if ($type->is(Token::T_PARENS_CLOSE)) {
             break;
         }
         $args[] = $this->parseArg($access);
     }
     $access->popToken();
     return $args;
 }
Example #6
0
 /**
  * Parses a value from a token stream
  *
  * @param \vc\Tokens\Access $access
  * @return \vc\Data\Value
  */
 public function parseValue(\vc\Tokens\Access $access)
 {
     $token = $access->peekToRequired(array(Token::T_LNUMBER, Token::T_DNUMBER, Token::T_STRING, Token::T_START_HEREDOC, Token::T_CONSTANT_ENCAPSED_STRING, Token::T_ARRAY, Token::T_MINUS, Token::T_NS_SEPARATOR), array(Token::T_EQUALS));
     switch ($token->getType()) {
         // Strings
         case Token::T_CONSTANT_ENCAPSED_STRING:
             $access->popToken();
             return $this->parseString($token);
             // HereDocs
         // HereDocs
         case Token::T_START_HEREDOC:
             $access->popToken();
             return $this->parseHereDoc($access);
             // Negative numbers
         // Negative numbers
         case Token::T_MINUS:
             $access->popToken();
             $token = $access->findRequired(array(Token::T_LNUMBER, Token::T_DNUMBER));
             return $this->parseNumber(FALSE, $token);
             // Positive Numbers
         // Positive Numbers
         case Token::T_LNUMBER:
         case Token::T_DNUMBER:
             $access->popToken();
             return $this->parseNumber(TRUE, $token);
             // Keywords like true, false, null and relative constants
         // Keywords like true, false, null and relative constants
         case Token::T_STRING:
             return $this->parseKeyword($access, $token);
             // Absolute Constants
         // Absolute Constants
         case Token::T_NS_SEPARATOR:
             return $this->parseConstant($access);
             // Arrays
         // Arrays
         case Token::T_ARRAY:
             $access->popToken();
             return $this->parseArray($access);
         default:
             throw new \RuntimeException("Unexpected Type");
     }
 }