Пример #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);
 }
Пример #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;
    }
}
Пример #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);
}
Пример #4
0
    if ($SHOW_PROGRESS) {
        echo substr(str_pad('Testing file ' . $count . ': ' . substr($file, strlen($DIR)), 79), 0, 79), "\r";
    }
    try {
        $startTime = microtime(true);
        $stmts = $parser->parse($code);
        $parseTime += microtime(true) - $startTime;
        $startTime = microtime(true);
        $code = '<?php' . "\n" . $prettyPrinter->prettyPrint($stmts);
        $ppTime += microtime(true) - $startTime;
        try {
            $startTime = microtime(true);
            $ppStmts = $parser->parse($code);
            $reparseTime += microtime(true) - $startTime;
            $startTime = microtime(true);
            $same = $nodeDumper->dump($stmts) == $nodeDumper->dump($ppStmts);
            $compareTime += microtime(true) - $startTime;
            if (!$same) {
                echo $file, ":\n    Result of initial parse and parse after pretty print differ\n";
                ++$compareFail;
            }
        } catch (PHPParser_Error $e) {
            echo $file, ":\n    Parse of pretty print failed with message: {$e->getMessage()}\n";
            ++$ppFail;
        }
    } catch (PHPParser_Error $e) {
        echo $file, ":\n    Parse failed with message: {$e->getMessage()}\n";
        ++$parseFail;
    }
}
if (0 === $parseFail && 0 === $ppFail && 0 === $compareFail) {
 /**
  * @expectedException        InvalidArgumentException
  * @expectedExceptionMessage Can only dump nodes and arrays.
  */
 public function testError()
 {
     $dumper = new PHPParser_NodeDumper();
     $dumper->dump(new stdClass());
 }