Skip to content

Commit

Permalink
Merge pull request #78 from goaop/fix/use-lexer-for-new-parser
Browse files Browse the repository at this point in the history
Configure lexer to capture token positions for new parser
  • Loading branch information
lisachenko authored Aug 27, 2017
2 parents c60371e + d7b8b71 commit 34991a5
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/ReflectionEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,31 @@ class ReflectionEngine
*/
protected static $traverser = null;

/**
* @var null|Lexer
*/
protected static $lexer = null;

private function __construct() {}

public static function init(LocatorInterface $locator)
{
self::$lexer = new Lexer(['usedAttributes' => [
'comments',
'startLine',
'endLine',
'startTokenPos',
'endTokenPos',
'startFilePos',
'endFilePos'
]]);

$refParser = new \ReflectionClass(Parser::class);
$isNewParser = $refParser->isInterface();
if (!$isNewParser) {
self::$parser = new Parser(new Lexer(['usedAttributes' => [
'comments', 'startLine', 'endLine', 'startTokenPos', 'endTokenPos', 'startFilePos', 'endFilePos'
]]));
self::$parser = new Parser(self::$lexer);
} else {
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7, self::$lexer);
}

self::$traverser = $traverser = new NodeTraverser();
Expand Down

0 comments on commit 34991a5

Please sign in to comment.