diff --git a/composer.json b/composer.json index 78827f66..fe9fc3e8 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ }, "require-dev": { "nette/tester": "^2.4", - "nikic/php-parser": "^4.15", + "nikic/php-parser": "^5.0", "tracy/tracy": "^2.8", "phpstan/phpstan": "^1.0", "jetbrains/phpstorm-attributes": "dev-master" diff --git a/src/PhpGenerator/Extractor.php b/src/PhpGenerator/Extractor.php index a6259dab..4452136c 100644 --- a/src/PhpGenerator/Extractor.php +++ b/src/PhpGenerator/Extractor.php @@ -46,9 +46,8 @@ private function parseCode(string $code): void throw new Nette\InvalidStateException('The input string is not a PHP code.'); } - $this->code = Nette\Utils\Strings::normalizeNewlines($code); - $lexer = new PhpParser\Lexer\Emulative(['usedAttributes' => ['startFilePos', 'endFilePos', 'comments']]); - $parser = (new ParserFactory)->create(ParserFactory::ONLY_PHP7, $lexer); + $this->code = Nette\Utils\Strings::unixNewLines($code); + $parser = (new ParserFactory)->createForNewestSupportedVersion(); $stmts = $parser->parse($this->code); $traverser = new PhpParser\NodeTraverser; diff --git a/tests/PhpGenerator/fixtures/extractor.php b/tests/PhpGenerator/fixtures/extractor.php index 936b5c0a..d8d80890 100644 --- a/tests/PhpGenerator/fixtures/extractor.php +++ b/tests/PhpGenerator/fixtures/extractor.php @@ -18,7 +18,7 @@ function comment1() function comment2() { // comment - 'bar'; + "bar"; } function comment3()