Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88499 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 46262 invoked from network); 25 Sep 2015 19:31:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Sep 2015 19:31:53 -0000 X-Host-Fingerprint: 68.118.157.39 68-118-157-39.dhcp.mdsn.wi.charter.com Received: from [68.118.157.39] ([68.118.157.39:21542] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 35/C5-31991-821A5065 for ; Fri, 25 Sep 2015 15:31:53 -0400 Message-ID: <35.C5.31991.821A5065@pb1.pair.com> To: internals@lists.php.net References: Date: Fri, 25 Sep 2015 14:31:49 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 68.118.157.39 Subject: Re: RFC: Generics From: me@stephencoakley.com (Stephen Coakley) On 09/24/2015 03:43 PM, Dominic Grostate wrote: > Hi Ben & Internals, > > I spent most of today and yesterday just getting used to the parser > language. > I was able to implement the basic syntax on most of the constructs, just to > get a partial proof of concept going. > > https://github.com/orolyn/php-src/commit/ee731240eab1e5986152cadaaca6d3e5b921ba7d > > The generic patterns aren't actually used, this simply "allows" them to be > present. Also I haven't yet cleaned up the memory leaks. > The hitch I ran into however was function calls. > > add_to_collection($collection, $object); // Sorry for the rather > pointless example. > > This potentially matches an expression, therefore yacc can't use it. > > Another (minor) but annoying issue is that nested generics need to be > written like: > > A > // Note the space before the last '>' > Else it will match T_SL > > I don't know if either of these issues can be neatly corrected, ##parsers > told me it was impossible without some > major hackery, so this might warrant discussion on the tokens used to > define generic delimitation. > > Anyway see parsable example below. > > Dominic > > > // T = placeholder for syntax texting > > interface Y {} > interface Z extends Y {} > > class K {} > > class A extends K implements Y, Z > > { > public function add(K > $a): Y > { > } > } > > function sample(A $a) { > echo 'OK' . PHP_EOL; > } > > sample(new A()); > I know this is just some experimentation, but requiring a space in nested templates would be ugly, so we'd want to figure something out to get around that. C++ initially required a space as well and it confuses people still to this day. Thanks for doing this work so far. -- Stephen