On Wed, Feb 18, 2015 at 7:22 AM, Dmitry Stogov <dmi...@zend.com> wrote:
> Hi, > > On Tue, Feb 17, 2015 at 2:46 PM, Alexander Lisachenko < > lisachenko...@gmail.com> wrote: > >> Hello, internals! >> >> I want to introduce a RFC for providing a userland API for accessing an >> Abstract Syntax Tree of the source code and to provide userland parser >> hooks for source code modification: >> https://wiki.php.net/rfc/parser-extension-api >> >> Thanks! >> > > The first part, describing https://github.com/nikic/php-ast , looks fine. > I see no problems including this extension into PHP-7.0 core distribution. > May be even making it required (like ext/reflection). > > Nikita, what do you think? > > The second part looks very interesting, however it has some uncovered > questions. > - API for AST modification > - AST validation (someone may insert "break" node in "parameter-list"). > > If you have enough experience, I would suggest you to try writing an > external extension that would implement this idea. > If you'll need some modification in PHP core (e.g adding callbacks), we > may consider including them in PHP-7.0. > > Thanks. Dmitry. > I agree with Dmitry. Exporting the AST to userland in PHP 7.0 would be nice. With Dmitry's work on assertions we even have a pretty printer for it, which allows us to convert the AST back to PHP code. The bits about intercepting compilation, modifying the AST and importing it back into the compiler are a LOT more complicated. Apart from many open design questions, this will also require quite a bit of implementation effort because we must be very careful with the many assumptions the compiler makes about the structure of the AST (otherwise -> segfaults). I'd prefer to delay this to a later PHP version (there's no problem to add it in a minor), preferably with a PoC extension being available beforehand. Alexander, I would recommend you to split this into two RFCs, one dealing only with AST export (and maybe pretty printing) and the second one with the compilation hooks. There's probably a few questions about the export API that should be discussed that will be forgotten if everyone focuses on the more complicated, and probably not yet relevant, question of compilation hooks. Nikita