Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83078 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 53654 invoked from network); 18 Feb 2015 15:06:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Feb 2015 15:06:55 -0000 Authentication-Results: pb1.pair.com header.from=cesar@rodas.me; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=cesar@rodas.me; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain rodas.me designates 109.74.200.116 as permitted sender) X-PHP-List-Original-Sender: cesar@rodas.me X-Host-Fingerprint: 109.74.200.116 li147-116.members.linode.com Received: from [109.74.200.116] ([109.74.200.116:41619] helo=li147-116.members.linode.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E5/B8-18888-D8AA4E45 for ; Wed, 18 Feb 2015 10:06:54 -0500 Message-ID: <54E4AA80.6050205@rodas.me> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rodas.me; s=mail; t=1424272010; bh=Ewp/RuKAlG9IfGu6c7C2EqRokeRkZTvf9J242XS8CkY=; h=Date:From:To:Subject:References:In-Reply-To:From; b=MsrQ+4NrmKQNDRv5wxWJ/vLkstSB5/g0eIa26/pBJYYa847k/eZC8RgqepfVPePwe 5qzooOIPSdcGzMiDNGZO0sjt2qRGutF0agJCPjKYNghCg+xwiykpElqz60kezrmSLR w8+qHWC8szZc42UBkrYGHWnF6gObAOa3cavKvJwI= Date: Wed, 18 Feb 2015 16:06:40 +0100 MIME-Version: 1.0 To: internals@lists.php.net References: In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Kl1jXR90i4juekXalglNMkK3eMmDaKE8M" Subject: Re: [PHP-DEV] [RFC][Discussion] Parser extension API From: cesar@rodas.me (Cesar Rodas) --Kl1jXR90i4juekXalglNMkK3eMmDaKE8M Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 18/02/15 15:59, Nikita Popov wrote: > 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 parse= r >>> 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 fi= ne. >> I see no problems including this extension into PHP-7.0 core distribut= ion. >> 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")= =2E >> >> 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), w= e >> 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 w= ork > 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 =3D convert_ast_toSqlWhere($where); } doQuery("foobar", $col1 =3D "something" AND $col2 =3D=3D $col3); Or at least `ast()`, although both would be nice to have. > > The bits about intercepting compilation, modifying the AST and importin= g 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= =2E > > Alexander, I would recommend you to split this into two RFCs, one deali= ng > only with AST export (and maybe pretty printing) and the second one wit= h > the compilation hooks. There's probably a few questions about the expor= t > 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 > --=20 C=C3=A9sar D. Rodas Open Source developer +595-983-161124 PGP: F9ED A265 A3AB C8A1 D145 7368 158A 0336 C707 0AA6 --Kl1jXR90i4juekXalglNMkK3eMmDaKE8M Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJU5KqAAAoJEBWKAzbHBwqm1vIQAJ1iHcfa+mSYk6JzqLu1YTKY hDNd26E3vbAnoRtRDX5nzYxaGIRTySwK7hTSOrFI6QrR7TCLNHSxDTGo6NBy4pHc iuhGAi+ABtK2DRdwgoyrvCRbmXNBTSQ1+pI1/nt8rp79RO4sBGUUpWybqb/2i2tj DClFVfe95XWsKM9tYB0OspMa90CjnzNC8EOpMuML0hNo3een+ENLFup3gL6wv223 L9Q6bM12M/FTSrYV610OKOy7U26Xnm3kBwim56YIZ7M1YUN7C7q13CjDnZjw6DGx Zszs5iGhuakyN5pRqJ8w/6T7H5in7bJ2wWv3AYy7ejZFf0qFDglQbMyu7FJ3rxWg lIMG/QSzh7Y1tDxA0TGJmoiyKuhALuXwLLq05TL4qGjtDBmf/TSGk23agiFJ0nT/ RpcQbf9YMgCWyv0f8IkyZRTfkkwXynD6f3rXhzPpP9lnKAqw1C+B6AQf4Yrsmf0f xph1LaeuwNDh+cBPTalXIyNdu5zofTp7QujjG2zcoU3tbv7Oie72rG/rlf9t8A45 OgDmGqOIbtEWp6iaxKZ2OA8NdCID+tqMT+ONzr+GSZV5AuNAD4ma4Iv3D0ewVHRX vmmCEU2Cc6CmICmqMLxBeLZNCL1Prpd1WxbhXYETWgZXOW6sb47GtpS9jegCUvte 7QiqF36+vItOjS9IkyBV =hjAy -----END PGP SIGNATURE----- --Kl1jXR90i4juekXalglNMkK3eMmDaKE8M--