From 4e25f515819e1b04064e1063d4424e4db746543e Mon Sep 17 00:00:00 2001
From: Nikita Popov <nikita.ppv@googlemail.com>
Date: Sun, 16 Oct 2016 22:19:33 +0200
Subject: [PATCH] Fix php-parse script

---
 bin/php-parse | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/bin/php-parse b/bin/php-parse
index 2d547473..dc35a68d 100755
--- a/bin/php-parse
+++ b/bin/php-parse
@@ -31,8 +31,7 @@ $lexer = new PhpParser\Lexer\Emulative(array('usedAttributes' => array(
 )));
 $parser = (new PhpParser\ParserFactory)->create(
     PhpParser\ParserFactory::PREFER_PHP7,
-    $lexer,
-    array('throwOnError' => !$attributes['with-recovery'])
+    $lexer
 );
 $dumper = new PhpParser\NodeDumper(['dumpComments' => true]);
 $prettyPrinter = new PhpParser\PrettyPrinter\Standard;
@@ -54,18 +53,23 @@ foreach ($files as $file) {
         echo "====> File $file:\n";
     }
 
-    try {
-        $stmts = $parser->parse($code);
-        foreach ($parser->getErrors() as $error) {
+    if ($attributes['with-recovery']) {
+        $errorHandler = new PhpParser\ErrorHandler\Collecting;
+        $stmts = $parser->parse($code, $errorHandler);
+        foreach ($errorHandler->getErrors() as $error) {
             $message = formatErrorMessage($error, $code, $attributes['with-column-info']);
             echo $message . "\n";
         }
         if (null === $stmts) {
             continue;
         }
-    } catch (PhpParser\Error $error) {
-        $message = formatErrorMessage($error, $code, $attributes['with-column-info']);
-        die($message . "\n");
+    } else {
+        try {
+            $stmts = $parser->parse($code);
+        } catch (PhpParser\Error $error) {
+            $message = formatErrorMessage($error, $code, $attributes['with-column-info']);
+            die($message . "\n");
+        }
     }
 
     foreach ($operations as $operation) {