php-parser/test.php

45 lines
900 B
PHP
Raw Normal View History

2011-04-18 19:02:30 +02:00
<?php
function __autoload($class) {
is_file($file = './lib/' . strtr($class, '_', '/') . '.php') && require_once $file;
}
echo '<pre>';
2011-05-30 19:21:25 +02:00
$parser = new Parser;
$prettyPrinter = new PrettyPrinter_Zend;
$nodeDumper = new NodeDumper;
2011-04-18 19:02:30 +02:00
// Output Demo
$stmts = $parser->parse(new Lexer(
2011-04-18 19:02:30 +02:00
'<?php
x::$y[z];
$x->y[z];
$x->y[z][k]->l()->m[t];
$x->y[z]();
$x->$y[z]();
$x->$$y[z]();'
2011-04-18 19:02:30 +02:00
),
function ($msg) {
echo $msg;
2011-04-18 19:02:30 +02:00
}
);
if (false !== $stmts) {
2011-05-30 19:21:25 +02:00
echo htmlspecialchars($nodeDumper->dump($stmts));
}
2011-04-18 19:02:30 +02:00
echo "\n\n";
2011-05-30 17:29:10 +02:00
$code = $prettyPrinter->pStmts(
$parser->parse(
2011-05-30 17:29:10 +02:00
new Lexer(file_get_contents(
2011-05-30 18:01:38 +02:00
'../symfonySandbox\src\vendor\symfony\src\Symfony\Components\Console\Input\InputDefinition.php'
2011-05-30 17:29:10 +02:00
)),
2011-05-29 12:20:47 +02:00
function ($msg) {
echo $msg;
}
)
2011-05-30 17:29:10 +02:00
);
echo htmlspecialchars($code);