Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions LE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
# Generics syntax

```
interface Comparable {

}

interface Equatable {

}

int implements Comparable, Equatable;

class Foo {

class Bar {

}

}

enum FooBar<T> {

case Blum(int bam);
case Bam(T boom);

}

```

## Generic classes and interfaces

### Basic case
Expand Down
45 changes: 39 additions & 6 deletions Zend/zend_language_scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,7 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_
}

<ST_IN_SCRIPTING>"function" {
yy_push_state(ST_IN_FUNC_DEF);
RETURN_TOKEN_WITH_IDENT(T_FUNCTION);
}

Expand Down Expand Up @@ -1537,18 +1538,35 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_
RETURN_TOKEN_WITH_IDENT(T_PRINT);
}

<ST_IN_SCRIPTING> "!🥖" {
<ST_IN_FUNC_DEF,ST_IN_GENERIC,ST_IN_CLASS_DEF> "<" {
yy_push_state(ST_IN_GENERIC);
RETURN_TOKEN(T_GENERIC_START);
}

<ST_IN_SCRIPTING> "!🥥" {
<ST_IN_FUNC_DEF,ST_IN_GENERIC,ST_IN_CLASS_DEF> ">" {
yy_pop_state();
RETURN_TOKEN(T_GENERIC_END);
}

<ST_IN_GENERIC>{LABEL} {
RETURN_TOKEN_WITH_STR(T_STRING, 0);
}


<ST_IN_SCRIPTING>"class" {
yy_push_state(ST_IN_CLASS_DEF);
RETURN_TOKEN_WITH_IDENT(T_CLASS);
}



<ST_IN_CLASS_DEF>"{" {
yy_pop_state();
yy_push_state(ST_IN_SCRIPTING);
enter_nesting('{');
RETURN_TOKEN('{');
}

<ST_IN_SCRIPTING>"interface" {
RETURN_TOKEN_WITH_IDENT(T_INTERFACE);
}
Expand All @@ -1570,11 +1588,11 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_
RETURN_TOKEN_WITH_IDENT(T_ENUM);
}

<ST_IN_SCRIPTING>"extends" {
<ST_IN_CLASS_DEF>"extends" {
RETURN_TOKEN_WITH_IDENT(T_EXTENDS);
}

<ST_IN_SCRIPTING>"implements" {
<ST_IN_CLASS_DEF>"implements" {
RETURN_TOKEN_WITH_IDENT(T_IMPLEMENTS);
}

Expand All @@ -1588,7 +1606,7 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_
RETURN_TOKEN(T_NULLSAFE_OBJECT_OPERATOR);
}

<ST_IN_SCRIPTING,ST_LOOKING_FOR_PROPERTY>{WHITESPACE}+ {
<ST_IN_SCRIPTING,ST_LOOKING_FOR_PROPERTY,ST_IN_FUNC_DEF,ST_IN_GENERIC,ST_IN_CLASS_DEF>{WHITESPACE}+ {
goto return_whitespace;
}

Expand Down Expand Up @@ -1730,9 +1748,14 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_
}

<ST_IN_SCRIPTING>"private" {
yy_push_state(ST_IN_PROPERTY_TYPE_DEF);
RETURN_TOKEN_WITH_IDENT(T_PRIVATE);
}

<ST_IN_PROPERTY_TYPE_DEF> {

}

<ST_IN_SCRIPTING>"protected" {
RETURN_TOKEN_WITH_IDENT(T_PROTECTED);
}
Expand Down Expand Up @@ -1916,6 +1939,16 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_
RETURN_TOKEN(yytext[0]);
}

<ST_IN_FUNC_DEF>"(" {
yy_pop_state();
enter_nesting(yytext[0]);
RETURN_TOKEN(yytext[0]);
}

<ST_IN_GENERIC>":"|"," {
RETURN_TOKEN(yytext[0]);
}

<ST_IN_SCRIPTING>{TOKENS} {
RETURN_TOKEN(yytext[0]);
}
Expand Down Expand Up @@ -2402,7 +2435,7 @@ inline_char_handler:
RETURN_TOKEN(T_NS_SEPARATOR);
}

<ST_IN_SCRIPTING,ST_VAR_OFFSET>{LABEL} {
<ST_IN_SCRIPTING,ST_VAR_OFFSET,ST_IN_FUNC_DEF,ST_IN_CLASS_DEF>{LABEL} {
RETURN_TOKEN_WITH_STR(T_STRING, 0);
}

Expand Down
16 changes: 16 additions & 0 deletions le-test/simple-class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

class GenericTestClass<T: Serializable> {
// T can be used as type alias inside of 'GenericTestClass'
public function __construct(
private T $property
) {}

public function getMyT(): T {
return $this->property;
}

public function setMyT(T $newValue) {
$this->property = $newValue;
}
}
3 changes: 3 additions & 0 deletions le-test/simple-function.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

function noOp<T>(): void {}
23 changes: 19 additions & 4 deletions t.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
<?php
class test!🥖lebruh, bruh : LELE!🥥 {

class RandomAssSerializableContaier<T, K : Serialize<T, K, A>> {

private array $content = [];

public function __construct(
public string $lol
){
private K $serializer
) {}

public function add(T $toAdd)
{
$content[] = $toAdd;
}

public function asSerializedList(): array
{
return array_map(
fn ($obj) => $this->serializer->serialize($obj),
$this->content
);
}
}

$lelelele = new test("le");
echo "hi\n";
26 changes: 9 additions & 17 deletions tree.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
<?php
$tokens = token_get_all('<?php

class test!🥖bruh : LELE, lebruh!🥥 {
public function __construct(
public !🥖K!🥥 $lol
){
}
}

$t = new test!🥖bruh!🥥(new bruh(4));


$le = [new bruh()]
array_map(fn (test!🥖bruh!🥥 $klfe)=>, $le)
echo "hi\n";');

var_export($tokens);
$classTokens = token_get_all(
'<?php
class Test<T: Serializable, K> {
public Serializable<T> $test;
function __construct<T>() {}
}
');

var_export($classTokens);