Browse Source

bug #2645 HHVM: handle T_HH_ERROR (keradus)

This PR was squashed before being merged into the 2.1 branch (closes #2645).

Discussion
----------

HHVM: handle T_HH_ERROR

Commits
-------

97b86c7 HHVM: handle T_HH_ERROR
Dariusz Ruminski 8 years ago
parent
commit
7ddcb5aa37
3 changed files with 15 additions and 0 deletions
  1. 1 0
      composer.json
  2. 4 0
      src/Tokenizer/Tokens.php
  3. 10 0
      tests/Tokenizer/TokensTest.php

+ 1 - 0
composer.json

@@ -23,6 +23,7 @@
         "symfony/finder": "^2.2 || ^3.0",
         "symfony/polyfill-php54": "^1.0",
         "symfony/polyfill-php55": "^1.3",
+        "symfony/polyfill-php70": "^1.0",
         "symfony/polyfill-xml": "^1.3",
         "symfony/process": "^2.3 || ^3.0",
         "symfony/stopwatch": "^2.5 || ^3.0"

+ 4 - 0
src/Tokenizer/Tokens.php

@@ -961,6 +961,10 @@ class Tokens extends \SplFixedArray
             $this->registerFoundToken($token);
         }
 
+        if (defined('T_HH_ERROR') && $this->isTokenKindFound(T_HH_ERROR)) {
+            throw new \ParseError('Parsing error, encountered "T_HH_ERROR".');
+        }
+
         $this->rewind();
         $this->changeCodeHash(self::calculateCodeHash($code));
         $this->changed = true;

+ 10 - 0
tests/Tokenizer/TokensTest.php

@@ -728,6 +728,16 @@ PHP;
         $tokens->findBlockEnd(Tokens::BLOCK_TYPE_DYNAMIC_VAR_BRACE, 0);
     }
 
+    public function testParsingWithHHError()
+    {
+        if (!defined('HHVM_VERSION')) {
+            $this->markTestSkipped('Skip tests for PHP compiler when running on non HHVM compiler.');
+        }
+
+        $this->setExpectedException('ParseError');
+        Tokens::fromCode('<?php# this will cause T_HH_ERROR');
+    }
+
     /**
      * @param null|Token[] $expected
      * @param null|Token[] $input