Ejemplo n.º 1
0
 /**
  * Constructs a new missing value exception.
  *
  * @param PHP_Depend_TokenizerI $tokenizer The context tokenizer instance.
  */
 public function __construct(PHP_Depend_TokenizerI $tokenizer)
 {
     // Get wrong token
     $token = $tokenizer->next();
     // The parser must take care for this
     assert($token instanceof PHP_Depend_Token);
     $message = sprintf('Missing default value on line: %d, col: %d, file: %s.', $token->startLine, $token->startColumn, $tokenizer->getSourceFile());
     parent::__construct($message);
 }
Ejemplo n.º 2
0
 /**
  * Sets a new php source file.
  *
  * @param string $sourceFile A php source file.
  *
  * @return void
  */
 public function setSourceFile($sourceFile)
 {
     $storage = PHP_Depend_StorageRegistry::get(PHP_Depend::PARSER_STORAGE);
     $id = '$Id$-@package_version@';
     $key = md5_file($sourceFile);
     $group = get_class($this->_tokenizer);
     $tokens = $storage->restore($key, $group, $id);
     if (is_array($tokens)) {
         $this->_sourceFile = new PHP_Depend_Code_File($sourceFile);
         $this->_sourceFile->setTokens($tokens);
     } else {
         $this->_tokenizer->setSourceFile($sourceFile);
         $this->_sourceFile = $this->_tokenizer->getSourceFile();
         $tokens = $this->_sourceFile->getTokens();
         $storage->store($tokens, $key, $group, $id);
     }
     $this->_tokens = $tokens;
     $this->_index = 0;
     $this->_count = count($tokens);
 }
Ejemplo n.º 3
0
 /**
  * Parses a function name from the given tokenizer and returns the string
  * literal representing the function name. If no valid token exists in the
  * token stream, this method will throw an exception.
  *
  * @return string
  * @throws PHP_Depend_Parser_UnexpectedTokenException When the next available
  *         token does not represent a valid php function name.
  * @throws PHP_Depend_Parser_TokenStreamEndException When there is no next
  *         token available in the given token stream.
  */
 public function parse()
 {
     switch ($this->_tokenizer->peek()) {
         case PHP_Depend_TokenizerI::T_STRING:
         case PHP_Depend_TokenizerI::T_USE:
         case PHP_Depend_TokenizerI::T_GOTO:
         case PHP_Depend_TokenizerI::T_NULL:
         case PHP_Depend_TokenizerI::T_SELF:
         case PHP_Depend_TokenizerI::T_TRUE:
         case PHP_Depend_TokenizerI::T_FALSE:
         case PHP_Depend_TokenizerI::T_NAMESPACE:
         case PHP_Depend_TokenizerI::T_DIR:
         case PHP_Depend_TokenizerI::T_NS_C:
         case PHP_Depend_TokenizerI::T_PARENT:
             $token = $this->_tokenizer->next();
             $this->_tokenStack->add($token);
             return $token->image;
         case PHP_Depend_TokenizerI::T_EOF:
             throw new PHP_Depend_Parser_TokenStreamEndException($this->_tokenizer);
     }
     throw new PHP_Depend_Parser_UnexpectedTokenException($this->_tokenizer->next(), $this->_tokenizer->getSourceFile());
 }
Ejemplo n.º 4
0
 /**
  * Constructs a new end of token stream exception.
  *
  * @param PHP_Depend_TokenizerI $tokenizer The context tokenizer instance.
  */
 public function __construct(PHP_Depend_TokenizerI $tokenizer)
 {
     parent::__construct(sprintf('Unexpected end of token stream in file: %s.', $tokenizer->getSourceFile()));
 }
Ejemplo n.º 5
0
 /**
  * This method will consume all comment tokens from the token stream.
  *
  * @return void
  */
 private function _consumeComments()
 {
     $type = $this->_tokenizer->peek();
     while ($type == self::T_COMMENT || $type == self::T_DOC_COMMENT) {
         $this->_tokenStack->add($this->_tokenizer->next());
         $type = $this->_tokenizer->peek();
     }
 }