Skip to content

Commit 4e25f51

Browse files
committed
Fix php-parse script
1 parent a46b309 commit 4e25f51

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

bin/php-parse

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ $lexer = new PhpParser\Lexer\Emulative(array('usedAttributes' => array(
3131
)));
3232
$parser = (new PhpParser\ParserFactory)->create(
3333
PhpParser\ParserFactory::PREFER_PHP7,
34-
$lexer,
35-
array('throwOnError' => !$attributes['with-recovery'])
34+
$lexer
3635
);
3736
$dumper = new PhpParser\NodeDumper(['dumpComments' => true]);
3837
$prettyPrinter = new PhpParser\PrettyPrinter\Standard;
@@ -54,18 +53,23 @@ foreach ($files as $file) {
5453
echo "====> File $file:\n";
5554
}
5655

57-
try {
58-
$stmts = $parser->parse($code);
59-
foreach ($parser->getErrors() as $error) {
56+
if ($attributes['with-recovery']) {
57+
$errorHandler = new PhpParser\ErrorHandler\Collecting;
58+
$stmts = $parser->parse($code, $errorHandler);
59+
foreach ($errorHandler->getErrors() as $error) {
6060
$message = formatErrorMessage($error, $code, $attributes['with-column-info']);
6161
echo $message . "\n";
6262
}
6363
if (null === $stmts) {
6464
continue;
6565
}
66-
} catch (PhpParser\Error $error) {
67-
$message = formatErrorMessage($error, $code, $attributes['with-column-info']);
68-
die($message . "\n");
66+
} else {
67+
try {
68+
$stmts = $parser->parse($code);
69+
} catch (PhpParser\Error $error) {
70+
$message = formatErrorMessage($error, $code, $attributes['with-column-info']);
71+
die($message . "\n");
72+
}
6973
}
7074

7175
foreach ($operations as $operation) {

0 commit comments

Comments
 (0)