1# phply 2 3phply is a parser for the PHP programming language written using PLY, a 4Lex/YACC-style parser generator toolkit for Python. 5 6## Why? 7 8Good question. Because I'm crazy. Because it seemed possible. 9 10Things I'm interested in doing with it: 11 12* Converting PHP code to Python 13* Running PHP templates in a Python environment 14* Learning more about parsing "industrial" languages, warts and all 15 16## What does it stand for? 17 18* phply -> PHP PLY 19* phply -> PHP Hypertext Preprocessor Python Lex YACC 20* phply -> PHP Hypertext Preprocessor Hypertext Preprocessor Python Lex Yet Another Compiler Compiler 21* (... to be completed ...) 22 23## How do you pronounce it? 24 25If you're conservative, it's pronounced "pee aich ply". If you're liberal, 26it's "fiply". And if you're anarchist, pronounce it however you want. Who am I 27to tell you what to do? 28 29## What's working? 30 31* Lexer matching the standard PHP lexer token-for-token 32* Parser and abstract syntax tree for most of the PHP grammar 33* Script to convert PHP source to JSON-based ASTs 34* Script to convert PHP source to Jinja2 source (experimental) 35 36## What's not? 37 38Some things can't be parsed yet. They are getting fewer by the day, but there 39is still a fair amount of work to do: 40 41* Labels and goto 42* Some other stuff, probably 43 44## Who's working on it? 45 46See the [AUTHORS](https://github.com/viraptor/phply/blob/master/AUTHORS) file. 47 48## Troubleshooting 49 50### Couldn't create 'phply.parsetab' 51 52Phply relies on `ply` to generate and cache some tables required for the parser. 53These have been generated with the latest available version of ply for the phply 54release. If you installed phply under a different user and a new `ply` was 55released, the parsetab file cannot be automatically updated. Your options are 56to: 57 58* raise an issue for phply 59* rebuild the package yourself 60 61## How do I use it? 62 63* Lexer test: python phply/phplex.py 64* Parser test: python phply/phpparse.py 65* JSON dump: cd tools; python php2json.py < input.php > output.json 66* Jinja2 conversion: cd tools; python php2jinja.py < input.php > output.html 67* Fork me on GitHub and start hacking :) 68