On 18/02/15 15:59, Nikita Popov wrote: > On Wed, Feb 18, 2015 at 7:22 AM, Dmitry Stogov <[email protected]> wrote: > >> Hi, >> >> On Tue, Feb 17, 2015 at 2:46 PM, Alexander Lisachenko < >> [email protected]> 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.
In this matter, how would it be? It'd be awesome if function expects an
AST tree object instead of a value:
function doQuery($table, *$where) {
$where = convert_ast_toSqlWhere($where);
}
doQuery("foobar", $col1 = "something" AND $col2 == $col3);
Or at least `ast(<expr>)`, although both would be nice to have.
>
> 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
>
--
César D. Rodas
Open Source developer
+595-983-161124
PGP: F9ED A265 A3AB C8A1 D145 7368 158A 0336 C707 0AA6
signature.asc
Description: OpenPGP digital signature
