任何用PHP编写的不错的PHP解析器? [英] Any decent PHP parser written in PHP?

查看:61
本文介绍了任何用PHP编写的不错的PHP解析器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了很多处理和分析PHP代码的工作.通常,我只是使用 Tokenizer 来执行此操作.对于大多数应用来说,这已经足够了.但是有时使用词法分析器解析不够可靠(显然).

I do lots of work manipulating and analyzing PHP code. Normally I just use the Tokenizer to do this. For most applications this is sufficient. But sometimes parsing using a lexer just isn't reliable enough (obviously).

因此,我正在寻找一些用PHP编写的PHP解析器.我发现 hnw/PhpParser kumatch/stagehand-php-parser .两者都是通过 zend_language_parser.y 自动转换为PHP而不是.y文件而创建的C(然后编译为LALR(1)解析器).但是,这种自动转换无法使用.

Thus I am looking for some PHP parser written in PHP. I found hnw/PhpParser and kumatch/stagehand-php-parser. Both are created by an automated conversion of zend_language_parser.y to a .y file with PHP instead of C (and then compiled to a LALR(1) parser). But this automated conversion just can't be worked with.

那么,有没有用PHP编写的不错的PHP解析器? (对于PHP 5.2,我需要一个,对于5.3,我需要一个.但是,其中一个也是一个很好的起点.)

So, is there any decent PHP parser written in PHP? (I need one for PHP 5.2 and one for 5.3. But just one of them would be a good starting point, too.)

推荐答案

在这里没有找到完整而稳定的解析器后,我决定自己写一个.结果如下:

After no complete and stable parser was found here I decided to write one myself. Here is the result:

PHP解析器 :用PHP编写的PHP解析器

PHP-Parser: A PHP parser written in PHP

该项目支持解析为PHP 5.2和PHP 7.1之间的任何PHP版本编写的代码.

The project supports parsing code written for any PHP version between PHP 5.2 and PHP 7.1.

除了解析器本身之外,该库还提供了一些相关组件:

Apart from the parser itself the library provides some related components:

  • 将AST编译回PHP (漂亮打印")
  • 用于遍历和更改AST的基础结构
  • 与XML的串行化(以及以人类可读形式进行转储)
  • 名称空间名称(别名等)的解析
  • Compilation of the AST back to PHP ("pretty printing")
  • Infrastructure for traversing and changing the AST
  • Serialization to and from XML (as well as dumping in a human readable form)
  • Resolution of namespaced names (aliases etc.)

有关用法概述,请参见基本组件的用法" 文档的部分.

For an usage overview see the "Usage of basic components" section of the documentation.

这篇关于任何用PHP编写的不错的PHP解析器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆