Skip to content

Commit

Permalink
Configure lexer to capture token positions for new parser too
Browse files Browse the repository at this point in the history
  • Loading branch information
lisachenko committed Aug 27, 2017
1 parent c60371e commit d7b8b71
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

1 comment on commit d7b8b71

@loren-osborn
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lisachenko, looks good... 👍

Please sign in to comment.