Esempio n. 1
0
    private function initInstances()
    {
        $lexer = new PhpParser\Lexer(array('usedAttributes' => array('comments', 'startLine', 'endLine', 'startTokenPos', 'endTokenPos')));
        $this->parser = (new PhpParser\ParserFactory())->create(PhpParser\ParserFactory::PREFER_PHP5, $lexer);
        $visitor = new MyParserNodeVisitor($this->filename);
        $this->traverser = new PhpParser\NodeTraverser();
        $this->traverser->addVisitor($visitor);
    }
    private function myParser()
    {
        try {
            $stmts = $this->parser->parse(file_get_contents($this->filename));
            //print_r($stmts);
            //$visitor->setTokens($lexer->getTokens());
            $stmts = $this->traverser->traverse($stmts);
        } catch (PhpParser\Error $e) {
            echo 'Parse Error: ', $e->getMessage();
        }
    }
}
$d = $argv[1];
if (empty($d)) {
    $d = getcwd() . DIRECTORY_SEPARATOR . "test";
}
$ind = new Indexer($d);
if (is_dir($d)) {
    $ind->scan();
} else {
    $ind->scanFile($d);
}
//getcwd()