1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-11-30 04:19:30 +01:00

Add ability to pass code directly to php-parse.php

This commit is contained in:
nikic 2014-09-28 13:14:37 +02:00
parent 88e2d42ba4
commit 16dff7c2e6

View File

@ -29,13 +29,18 @@ $traverser = new PhpParser\NodeTraverser();
$traverser->addVisitor(new PhpParser\NodeVisitor\NameResolver);
foreach ($files as $file) {
if (strpos($file, '<?php') === 0) {
$code = $file;
echo "====> Code $code\n";
} else {
if (!file_exists($file)) {
die("File $file does not exist.\n");
}
echo "====> File $file:\n";
$code = file_get_contents($file);
echo "====> File $file:\n";
}
try {
$stmts = $parser->parse($code);
} catch (PhpParser\Error $e) {
@ -69,6 +74,10 @@ Usage:
php php-parse.php [operations] file1.php [file2.php ...]
The file arguments can also be replaced with a code string:
php php-parse.php [operations] "<?php code"
Operations is a list of the following options (--dump by default):
--dump -d Dump nodes using NodeDumper