/**
  * 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());
 }
Пример #2
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();
     }
 }
Пример #3
0
 /**
  * This method will consume the next token in the token stream. It will
  * throw an exception if the type of this token is not identical with
  * <b>$tokenType</b>.
  *
  * @param integer $tokenType The next expected token type.
  *
  * @return PHP_Depend_Token
  */
 protected function consumeToken($tokenType)
 {
     $token = $this->tokenizer->next();
     if ($token === self::T_EOF) {
         throw new PHP_Depend_Parser_TokenStreamEndException($this->tokenizer);
     } else {
         if ($token->type == $tokenType) {
             return $this->_tokenStack->add($token);
         }
     }
     throw new PHP_Depend_Parser_UnexpectedTokenException($token, $this->tokenizer->getSourceFile());
 }
Пример #4
0
 /**
  * testPopOnRootReturnsExpectedTokenArrayWithAllTokens
  *
  * @return void
  */
 public function testPopOnRootReturnsExpectedTokenArrayWithAllTokens()
 {
     $stack = new PHP_Depend_Parser_TokenStack();
     $stack->push();
     $expected = array($stack->add($this->createToken()), $stack->add($this->createToken()));
     $stack->push();
     $expected[] = $stack->add($this->createToken());
     $expected[] = $stack->add($this->createToken());
     $stack->pop();
     self::assertSame($expected, $stack->pop());
 }