You should be familiar with PHP projects written in plain PHP, or in C++, but what about a parser for the PHP programming language written in Go! ? Kind of crazy project you said ? but it exists and it’s a nearly complete PHP parser that Stephen Searles wrote !

The screenshot below from the console demo, shows how the PHP parser interpret the code on the fly. The parser actually support most of PHP 5.4 features with 85% having test coverage and 67% coverage with full unit tests.  The most important goal at this point is to move the parser further to solidly support the full set of PHP 5.6 features. That’s already a great job !

php-parser

A project under heavy development, that could be a great addition to the PHP ecosystem. Since the project didn’t get any update since December 2014, we asked Stephen about the project status :

“The project is still active. I haven’t had time to dive deep into some of the current tasks in a while, but it’s very much on my mind. There’s plenty of contributor-friendly work if others want to move it forward sooner. Additionally, we have been using it at Shipwire for a few small static analysis checks.”

When asked about the next direction of the project Stephen said :

“A formatter is the most direct goal right now”

A formatter is the most direct goal right now. What underlies that is even more important to me: the ability to translate an AST into readable source code. Beyond that, I would love to see a transpiler, but of course, that’s a more lofty goal.”

The project could open lots of new opportunities to the effort of the PHP-FIG group – and we will be back on the PHP-FIG subject with a more detailed article really soon. Some of the project features that are currently work in progress include :

  • Lexer and Parser: these pieces are quite useable and haven’t seen more than minor changes for a while. They do have notable gaps, though (e.g. namespaces).
  • Code search and symbol lookup: basic idea implemented, many many details missing
  • Code formatting: basic idea implemented, formatting needs to narrow down to PSR-2

Fork the project on github,
Read an introduction here about the parser for PHP written in Go,
And make sure you check the demo console online !

LEAVE A REPLY

Please enter your comment!
Please enter your name here