On Tue, Apr 26, 2016 at 9:42 AM, Alexander Lisachenko < lisachenko...@gmail.com> wrote:
> Hello, internals! > > I'd like to bring this topic to the discussion again, because now we have > a shiny PHP7 engine and keep moving. PHP grammar becomes more complex and > internal AST representation isn't available for the userland developers, so > all static analysis tools suffering from the lack of native AST API for > that. Only possible way for that is to perform tokenization of source code > and then manually reconstruct an AST (thanks to the PHP-Parser and Nikita > for doing this job for us, developers) > > Several days ago, Dmitry published a RFC for native attributes, which can > be a great tool for building more complex stuff on top of this metadata. > However, all attribute expressions will be stored as an AST nodes, so we > need an AST API again to analyse, parse or compile AST back into the source > code for evaling, etc. > > It would be nice to push php-ast extension (or similar one) into the core, > providing an API via static class, for example "Php\Parser". > As an update here, I plan to create an RFC for bundling the php-ast extension (maybe with minor modifications) with php-src. This was planned for 7.1 anyway, and with the annotations RFC under discussion, this seems like a good time. However, I will limit this RFC to the current state of the extension, i.e. I will not include the ability to inject the AST back into the PHP compiler -- as already mentioned this is very complicated (due to validation concerns) and should be left for future scope. Some concerns like pretty printing (compiling AST back to PHP code) will also be left for userland (e.g. tpunt has a library for this), as doing this in core (on the exported AST) is unnecessarily complicated, fragile and not sufficiently flexible (e.g. with regard to formatting). I'll try to post an RFC for review this week. Regards, Nikita