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<MyClass>($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<T<V> > // 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

<?php

// T = placeholder for syntax texting

interface Y {}
interface Z extends Y<T> {}

class K {}

class A extends K<T> implements Y, Z<T<T> >
{
         public function add<T>(K<J> > $a): Y<T>
         {
         }
}

function sample<T>(A<T> $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

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to