Ejemplo n.º 1
0
 /**
  * @dataProvider provideTestParse
  */
 public function testParse($name, $code, $dump)
 {
     $parser = new PHPParser_Parser(new PHPParser_Lexer_Emulative());
     $dumper = new PHPParser_NodeDumper();
     $stmts = $parser->parse($code);
     $this->assertEquals($this->canonicalize($dump), $this->canonicalize($dumper->dump($stmts)), $name);
 }
Ejemplo n.º 2
0
function snowscript_to_php($code, $debug = false, $return = false, $namespace = "Anonymous")
{
    $lexer = new Snowscript_Lexer($code . "\n");
    if ($debug) {
        debug_lexer($lexer);
    }
    $parser = new PHPParser_Parser();
    $prettyPrinter = new PHPParser_PrettyPrinter_Zend();
    $stmts = $parser->parse($lexer);
    $traverser = new PHPParser_NodeTraverser();
    $scope_traverser = new Snowscript_Visitors_Scope($namespace);
    $traverser->addVisitor($scope_traverser);
    $stmts = $traverser->traverse($stmts);
    $nodeDumper = new PHPParser_NodeDumper();
    if ($debug) {
        $nodeDumper = new PHPParser_NodeDumper();
        echo $nodeDumper->dump($stmts) . "\n";
    }
    $php = $prettyPrinter->prettyPrint($stmts) . "\n";
    if ($return) {
        return $php;
    } else {
        print "<?php\n" . $php;
    }
}
Ejemplo n.º 3
0
function php_to_php($code, $debug = false)
{
    $lexer = new PHPParser_Lexer($code . "\n");
    $parser = new PHPParser_Parser();
    $prettyPrinter = new PHPParser_PrettyPrinter_Zend();
    $stmts = $parser->parse($lexer);
    $nodeDumper = new PHPParser_NodeDumper();
    echo $nodeDumper->dump($stmts);
}
Ejemplo n.º 4
0
    {
        return preg_match('~\\.php(?:\\.cache)?$~', $path) && false === strpos($path, 'skeleton');
    }
} elseif ('PHP' === $TEST_TYPE) {
    function filter_func($path)
    {
        return preg_match('~\\.phpt$~', $path);
    }
} else {
    showHelp('Test type must be either "Symfony" or "PHP"!');
}
require_once dirname(__FILE__) . '/../lib/PHPParser/Autoloader.php';
PHPParser_Autoloader::register();
$parser = new PHPParser_Parser(new PHPParser_Lexer_Emulative());
$prettyPrinter = new PHPParser_PrettyPrinter_Default();
$nodeDumper = new PHPParser_NodeDumper();
$parseFail = $ppFail = $compareFail = $count = 0;
$readTime = $parseTime = $ppTime = $reparseTime = $compareTime = 0;
$totalStartTime = microtime(true);
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($DIR), RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
    if (!filter_func($file)) {
        continue;
    }
    $startTime = microtime(true);
    $code = file_get_contents($file);
    $readTime += microtime(true) - $startTime;
    if ('PHP' === $TEST_TYPE) {
        if (preg_match('~(?:
# skeleton files
  ext.gmp.tests.001
| ext.skeleton.tests.001
 /**
  * @expectedException        InvalidArgumentException
  * @expectedExceptionMessage Can only dump nodes and arrays.
  */
 public function testError()
 {
     $dumper = new PHPParser_NodeDumper();
     $dumper->dump(new stdClass());
 }