@@ -31,8 +31,7 @@ $lexer = new PhpParser\Lexer\Emulative(array('usedAttributes' => array(
31
31
)));
32
32
$ parser = (new PhpParser \ParserFactory )->create (
33
33
PhpParser \ParserFactory::PREFER_PHP7 ,
34
- $ lexer ,
35
- array ('throwOnError ' => !$ attributes ['with-recovery ' ])
34
+ $ lexer
36
35
);
37
36
$ dumper = new PhpParser \NodeDumper (['dumpComments ' => true ]);
38
37
$ prettyPrinter = new PhpParser \PrettyPrinter \Standard ;
@@ -54,18 +53,23 @@ foreach ($files as $file) {
54
53
echo "====> File $ file: \n" ;
55
54
}
56
55
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 ) {
60
60
$ message = formatErrorMessage ($ error , $ code , $ attributes ['with-column-info ' ]);
61
61
echo $ message . "\n" ;
62
62
}
63
63
if (null === $ stmts ) {
64
64
continue ;
65
65
}
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
+ }
69
73
}
70
74
71
75
foreach ($ operations as $ operation ) {
0 commit comments