Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83077 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 47879 invoked from network); 18 Feb 2015 14:59:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Feb 2015 14:59:50 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.172 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 74.125.82.172 mail-we0-f172.google.com Received: from [74.125.82.172] ([74.125.82.172:39476] helo=mail-we0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 82/67-18888-4E8A4E45 for ; Wed, 18 Feb 2015 09:59:49 -0500 Received: by wesx3 with SMTP id x3so1658186wes.6 for ; Wed, 18 Feb 2015 06:59:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=pqbE0GvRJ2wIvbG0ZFR2EaqYbUjCc5w6I+qwj7faMf0=; b=ftYpM0xo4fqenf/bllZVwowCHlCKuFzJ2IHAFmxaSG86Zv9EaxPYV01JPEUjqmYopC I6ALR4EbJaRHLD/o2iqZrJjl97LQyQTIyUS/1Xq0w8NnFLSUxmWqRpEI1BVzXtJfbanv 7Fb+0Eg1Ea5i6dHkuEdzJ7rMZC+xRI8/O0s0Y/I2FEZiJg7HaeGW1qvaCMrNGVgoArrS diHu+5clcuxTMvRUUsYQLK/g65VhHLRlloa98SrzHv9JX7YFjR8GvhQsXyZqad2S1oWB dOru36URPsYD8zAD+NXgFlWwGsTubhl0Tfwg/E9PFfgqUPV69FFOeGGNsnaAcJfrVFHw uRqQ== MIME-Version: 1.0 X-Received: by 10.194.71.175 with SMTP id w15mr66655531wju.16.1424271585744; Wed, 18 Feb 2015 06:59:45 -0800 (PST) Received: by 10.27.10.168 with HTTP; Wed, 18 Feb 2015 06:59:45 -0800 (PST) In-Reply-To: References: Date: Wed, 18 Feb 2015 15:59:45 +0100 Message-ID: To: Dmitry Stogov Cc: Alexander Lisachenko , Nikita Popov , PHP internals list Content-Type: multipart/alternative; boundary=047d7bfcf000ee9d29050f5e11ff Subject: Re: [PHP-DEV] [RFC][Discussion] Parser extension API From: nikita.ppv@gmail.com (Nikita Popov) --047d7bfcf000ee9d29050f5e11ff Content-Type: text/plain; charset=UTF-8 On Wed, Feb 18, 2015 at 7:22 AM, Dmitry Stogov wrote: > Hi, > > On Tue, Feb 17, 2015 at 2:46 PM, Alexander Lisachenko < > lisachenko.it@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 --047d7bfcf000ee9d29050f5e11ff--