mirror of
https://github.com/danog/PHP-Parser.git
synced 2024-12-02 09:17:58 +01:00
Add php-parse --with-positions
To invoke NodeDumper in dumpPositions mode
This commit is contained in:
parent
70319e27ee
commit
d5eebf7214
@ -33,7 +33,10 @@ $parser = (new PhpParser\ParserFactory)->create(
|
|||||||
PhpParser\ParserFactory::PREFER_PHP7,
|
PhpParser\ParserFactory::PREFER_PHP7,
|
||||||
$lexer
|
$lexer
|
||||||
);
|
);
|
||||||
$dumper = new PhpParser\NodeDumper(['dumpComments' => true]);
|
$dumper = new PhpParser\NodeDumper([
|
||||||
|
'dumpComments' => true,
|
||||||
|
'dumpPositions' => $attributes['with-positions'],
|
||||||
|
]);
|
||||||
$prettyPrinter = new PhpParser\PrettyPrinter\Standard;
|
$prettyPrinter = new PhpParser\PrettyPrinter\Standard;
|
||||||
$serializer = new PhpParser\Serializer\XML;
|
$serializer = new PhpParser\Serializer\XML;
|
||||||
|
|
||||||
@ -75,7 +78,7 @@ foreach ($files as $file) {
|
|||||||
foreach ($operations as $operation) {
|
foreach ($operations as $operation) {
|
||||||
if ('dump' === $operation) {
|
if ('dump' === $operation) {
|
||||||
echo "==> Node dump:\n";
|
echo "==> Node dump:\n";
|
||||||
echo $dumper->dump($stmts), "\n";
|
echo $dumper->dump($stmts, $code), "\n";
|
||||||
} elseif ('pretty-print' === $operation) {
|
} elseif ('pretty-print' === $operation) {
|
||||||
echo "==> Pretty print:\n";
|
echo "==> Pretty print:\n";
|
||||||
echo $prettyPrinter->prettyPrintFile($stmts), "\n";
|
echo $prettyPrinter->prettyPrintFile($stmts), "\n";
|
||||||
@ -117,6 +120,7 @@ Operations is a list of the following options (--dump by default):
|
|||||||
--var-dump var_dump() nodes (for exact structure)
|
--var-dump var_dump() nodes (for exact structure)
|
||||||
-N, --resolve-names Resolve names using NodeVisitor\NameResolver
|
-N, --resolve-names Resolve names using NodeVisitor\NameResolver
|
||||||
-c, --with-column-info Show column-numbers for errors (if available)
|
-c, --with-column-info Show column-numbers for errors (if available)
|
||||||
|
-P, --with-positions Show positions in node dumps
|
||||||
-r, --with-recovery Use parsing with error recovery
|
-r, --with-recovery Use parsing with error recovery
|
||||||
-h, --help Display this page
|
-h, --help Display this page
|
||||||
|
|
||||||
@ -135,6 +139,7 @@ function parseArgs($args) {
|
|||||||
$files = array();
|
$files = array();
|
||||||
$attributes = array(
|
$attributes = array(
|
||||||
'with-column-info' => false,
|
'with-column-info' => false,
|
||||||
|
'with-posititions' => false,
|
||||||
'with-recovery' => false,
|
'with-recovery' => false,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -169,6 +174,10 @@ function parseArgs($args) {
|
|||||||
case '-c';
|
case '-c';
|
||||||
$attributes['with-column-info'] = true;
|
$attributes['with-column-info'] = true;
|
||||||
break;
|
break;
|
||||||
|
case '--with-positions':
|
||||||
|
case '-P':
|
||||||
|
$attributes['with-positions'] = true;
|
||||||
|
break;
|
||||||
case '--with-recovery':
|
case '--with-recovery':
|
||||||
case '-r':
|
case '-r':
|
||||||
$attributes['with-recovery'] = true;
|
$attributes['with-recovery'] = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user