Example #1
0
 /**
  * Parses a single argument and returns the data that is created
  *
  * @param \vc\Tokens\Access $access
  * @return \vc\Data\Arg
  */
 private function parseArg(\vc\Tokens\Access $access)
 {
     $arg = new \vc\Data\Arg();
     // We've already ensured this token is an appropriate type in the
     // calling method, so we don't need to do any extensive checking
     $token = $access->peekAtToken();
     // Parse out any type hinting
     if ($token->is(array(Token::T_ARRAY, Token::T_STRING, Token::T_NS_SEPARATOR))) {
         $arg->setType($token->is(Token::T_ARRAY) ? 'array' : $this->path->parsePath($access));
         $access->popToken();
         $token = $access->peekToRequired(array(Token::T_AMPERSAND, Token::T_VARIABLE));
     }
     // Check to see if this argument is being passed by reference
     if ($token->is(Token::T_AMPERSAND)) {
         $arg->setReference(TRUE);
         $access->popToken();
         $token = $access->peekToRequired(array(Token::T_VARIABLE));
     }
     // Grab the name of the argument. Up to this point, it has only been
     // peeked at, so we need to remove it from the list
     $arg->setVariable($token->getContent());
     $access->popToken();
     // Look for a default value for this argument
     $token = $access->find(array(Token::T_EQUALS));
     if ($token && $token->is(Token::T_EQUALS)) {
         $arg->setDefault($this->value->parseValue($access));
     }
     // Pop the comma off the list if one exists
     $access->find(array(Token::T_COMMA));
     return $arg;
 }
Example #2
0
 /**
  * Put together the namespace path and get an access object for reading the
  * namespace
  *
  * Collect the path to this namespace until an ending token is found. This
  * ending token denotes whether this namespace is wrapped in curlies or not.
  *
  * @param \vc\Data\NSpace $nspace The namespace to append to
  * @param \vc\Tokens\Access $access The token access
  * @return \vc\Tokens\Access The access object for reading the namespace
  */
 private function buildNS(\vc\Data\NSpace $nspace, \vc\Tokens\Access $access)
 {
     $nspace->setNamespace($this->path->parsePath($access));
     $token = $access->findRequired(array(Token::T_SEMICOLON, Token::T_CURLY_OPEN));
     if ($token->is(Token::T_CURLY_OPEN)) {
         return $access->untilBlockEnds();
     } else {
         return $access->untilTokens(array(Token::T_NAMESPACE));
     }
 }
Example #3
0
 /**
  * Parses the given token reader
  *
  * @param \vc\Tokens\Access $access The token access
  * @return \vc\Data\Alias Returns the created alias
  */
 public function parseAlias(\vc\Tokens\Access $access)
 {
     $access->findRequired(array(Token::T_USE));
     $alias = new \vc\Data\Alias($this->path->parsePath($access));
     $as = $access->find(array(Token::T_AS));
     if ($as) {
         $alias->setAlias($this->path->parsePath($access));
     }
     $access->findRequired(array(Token::T_SEMICOLON));
     return $alias;
 }
Example #4
0
 /**
  * Parses a constant
  *
  * @param \vc\Tokens\Access $access
  * @return \vc\Data\Value
  */
 private function parseConstant(\vc\Tokens\Access $access)
 {
     $path = $this->path->parsePath($access);
     $token = $access->peekTo(array(Token::T_SEMICOLON, Token::T_DOUBLE_COLON));
     if ($token && $token->is(Token::T_DOUBLE_COLON)) {
         $access->popToken();
         $path .= '::';
         $token = $access->findRequired(array(Token::T_STRING));
         $path .= $token->getContent();
     }
     return new \vc\Data\Value($path, 'constant');
 }
Example #5
0
 /**
  * Parses a list of namespace paths
  *
  * @param \vc\Tokens\Access $access The token access
  * @return Array Returns an array of Namespace Path Strings
  */
 public function parsePathList(\vc\Tokens\Access $access)
 {
     $paths = array();
     // Keep looping until we encounter a curlie brace
     while (TRUE) {
         $paths[] = $this->path->parsePath($access);
         $token = $access->peekToRequired(array(Token::T_COMMA, Token::T_CURLY_OPEN));
         if ($token->is(Token::T_COMMA)) {
             $access->popToken();
         } else {
             break;
         }
     }
     return $paths;
 }
Example #6
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;
 }