Generate AST of a PHP source file

前端 未结 5 2027
梦毁少年i
梦毁少年i 2021-01-01 17:26

I want to parse a PHP source file, into an AST (preferably as a nested array of instructions).

I basically want to convert things like

f($a, $b + 1)
         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-01 17:57

    Well, you can look at the answers from Parsing and Printing PHP Code and Generating PHP code (from Parser Tokens): basically PEAR's PHP_Beautifier package at http://pear.php.net/package/PHP_Beautifier can be extended to do what you want, but it sounds like it requires some heavy lifting.

    And if you're not constrained to PHP then http://www.eclipse.org/pdt/articles/ast/PHP_AST.html walks you through using the Eclipse PHP module's AST parser.

提交回复
热议问题