Пример #1
0
 /**
  * @dataProvider provideTestHaltCompiler
  */
 public function testHandleHaltCompiler($code, $remaining)
 {
     $this->lexer->startLexing($code);
     while (PHPParser_Parser::T_HALT_COMPILER !== $this->lexer->getNextToken()) {
     }
     $this->assertEquals($this->lexer->handleHaltCompiler(), $remaining);
     $this->assertEquals(0, $this->lexer->getNextToken());
 }
Пример #2
0
 /**
  * Retrieves the next token and determines the associated attributes and
  * returns the token id.
  *
  * @param string   $value
  * @param string[] $startAttributes
  * @param string[] $endAttributes
  *
  * @return int
  */
 public function getNextToken(&$value = null, &$startAttributes = null, &$endAttributes = null)
 {
     $tokenId = parent::getNextToken($value, $startAttributes, $endAttributes);
     if ($this->isTokenScalar($tokenId)) {
         // store original value because the value itself will be interpreted
         // by PHP_Parser and we want the unformatted value
         $endAttributes['originalValue'] = $value;
     }
     return $tokenId;
 }
Пример #3
0
 public function getNextToken(&$value = null, &$startAttributes = null, &$endAttributes = null)
 {
     $token = parent::getNextToken($value, $startAttributes, $endAttributes);
     // replace new keywords by their respective tokens. This is not done
     // if we currently are in an object access (e.g. in $obj->namespace
     // "namespace" stays a T_STRING tokens and isn't converted to T_NAMESPACE)
     if (PHPParser_Parser::T_STRING === $token && !$this->inObjectAccess) {
         if (isset($this->newKeywords[strtolower($value)])) {
             return $this->newKeywords[strtolower($value)];
         }
         // backslashes are replaced by T_NS_SEPARATOR tokens
     } elseif (92 === $token) {
         // ord('\\')
         return PHPParser_Parser::T_NS_SEPARATOR;
         // keep track of whether we currently are in an object access (after ->)
     } elseif (PHPParser_Parser::T_OBJECT_OPERATOR === $token) {
         $this->inObjectAccess = true;
     } else {
         $this->inObjectAccess = false;
     }
     return $token;
 }
Пример #4
0
 public function getNextToken(&$value = null, &$startAttributes = null, &$endAttributes = null)
 {
     $tokenId = parent::getNextToken($value, $startAttributes, $endAttributes);
     $startAttributes['startOffset'] = $endAttributes['endOffset'] = $this->pos;
     return $tokenId;
 }