简体   繁体   English

用于Python的Python人类可读解析器

[英]ISO human-readable parser for Python in Python

I'm looking for a parser for Python (preferably v. 2.7) written in human-readable Python. 我正在寻找一个用人类可读的Python编写的Python解析器(最好是2.7版)。 Performance or flexibility are not important. 性能或灵活性并不重要。 The accuracy/correctness of the parsing and the clarity of the parser's code are far more important considerations here. 解析的准确性/正确性和解析器代码的清晰度在这里是更重要的考虑因素。

Searching online I've found a few parser generators that generate human-readable Python code, but I have not found the corresponding Python grammar to go with any of them (from what I could see, they all follow different grammar specification conventions). 在线搜索我发现了一些生成人类可读的Python代码的解析器生成器 ,但我没有找到相应的Python语法与它们中的任何一个(从我看到的,它们都遵循不同的语法规范约定)。 At any rate, even if I could find a suitable parser-generator/Python grammar combo, a readily available Python parser that fits my requirements (human-readable Python code) is naturally far more preferable. 无论如何,即使我能找到合适的解析器生成器/ Python语法组合,一个符合我要求(人类可读的Python代码)的现成Python 解析器自然要好得多。

Any suggestions? 有什么建议?

Thanks! 谢谢!

PyPy is a Python implementation written entirely in Python. PyPy是一个完全用Python编写的Python实现。 I am not an expert, but here's the link to their parser which - obviously - has been written in Python itself: 我不是专家,但这里是他们的解析器的链接 - 显然 - 用Python本身编写:

https://bitbucket.org/pypy/pypy/src/819faa2129a8/pypy/interpreter/pyparser https://bitbucket.org/pypy/pypy/src/819faa2129a8/pypy/interpreter/pyparser

I think you should invest your effort in ast . 我认为你应该把你的努力投入到ast An excerpt from the python docs. 来自python文档的摘录。

The ast module helps Python applications to process trees of the Python abstract syntax grammar. ast模块帮助Python应用程序处理Python抽象语法语法的树。 The abstract syntax itself might change with each Python release; 每个Python版本的抽象语法本身都可能会改变; this module helps to find out programmatically what the current grammar looks like. 这个模块有助于以编程方式找出当前语法的样子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM