kjo
kjo

Reputation: 35301

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. 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). 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.

Any suggestions?

Thanks!

Upvotes: 3

Views: 213

Answers (2)

Abhijit
Abhijit

Reputation: 63707

I think you should invest your effort in ast. An excerpt from the python docs.

The ast module helps Python applications to process trees of the Python abstract syntax grammar. The abstract syntax itself might change with each Python release; this module helps to find out programmatically what the current grammar looks like.

Upvotes: 2

mac
mac

Reputation: 43031

PyPy is a Python implementation written entirely in Python. I am not an expert, but here's the link to their parser which - obviously - has been written in Python itself:

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

Upvotes: 3

Related Questions