Skip to content

Commit 8d5e0f8

Browse files
desIstUrGuaddesIstUrGuad
authored andcommitted
le
1 parent 761b4be commit 8d5e0f8

File tree

6 files changed

+84
-30
lines changed

6 files changed

+84
-30
lines changed

LE.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
11
# Generics syntax
22

3+
```
4+
interface Comparable {
5+
6+
}
7+
8+
interface Equatable {
9+
10+
}
11+
12+
int implements Comparable, Equatable;
13+
14+
class Foo {
15+
16+
class Bar {
17+
18+
}
19+
20+
}
21+
22+
enum FooBar<T> {
23+
24+
case Blum(int bam);
25+
case Bam(T boom);
26+
27+
}
28+
29+
```
30+
331
## Generic classes and interfaces
432

533
### Basic case

Zend/zend_language_scanner.l

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,7 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_
13951395
}
13961396

13971397
<ST_IN_SCRIPTING>"function" {
1398+
yy_push_state(ST_IN_FUNC_DEF);
13981399
RETURN_TOKEN_WITH_IDENT(T_FUNCTION);
13991400
}
14001401

@@ -1537,14 +1538,21 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_
15371538
RETURN_TOKEN_WITH_IDENT(T_PRINT);
15381539
}
15391540

1540-
<ST_IN_SCRIPTING> "!🥖" {
1541+
<ST_IN_FUNC_DEF,ST_IN_GENERIC> "<" {
1542+
yy_push_state(ST_IN_GENERIC);
15411543
RETURN_TOKEN(T_GENERIC_START);
15421544
}
15431545

1544-
<ST_IN_SCRIPTING> "!🥥" {
1546+
<ST_IN_FUNC_DEF,ST_IN_GENERIC> ">" {
1547+
yy_pop_state();
15451548
RETURN_TOKEN(T_GENERIC_END);
15461549
}
15471550

1551+
<ST_IN_GENERIC>{LABEL} {
1552+
RETURN_TOKEN_WITH_STR(T_STRING, 0);
1553+
}
1554+
1555+
15481556
<ST_IN_SCRIPTING>"class" {
15491557
RETURN_TOKEN_WITH_IDENT(T_CLASS);
15501558
}
@@ -1588,7 +1596,7 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_
15881596
RETURN_TOKEN(T_NULLSAFE_OBJECT_OPERATOR);
15891597
}
15901598

1591-
<ST_IN_SCRIPTING,ST_LOOKING_FOR_PROPERTY>{WHITESPACE}+ {
1599+
<ST_IN_SCRIPTING,ST_LOOKING_FOR_PROPERTY, ST_IN_FUNC_DEF>{WHITESPACE}+ {
15921600
goto return_whitespace;
15931601
}
15941602

@@ -1916,6 +1924,11 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_
19161924
RETURN_TOKEN(yytext[0]);
19171925
}
19181926

1927+
<ST_IN_FUNC_DEF>"(" {
1928+
enter_nesting('(');
1929+
yy_pop_state();
1930+
}
1931+
19191932
<ST_IN_SCRIPTING>{TOKENS} {
19201933
RETURN_TOKEN(yytext[0]);
19211934
}
@@ -2402,7 +2415,7 @@ inline_char_handler:
24022415
RETURN_TOKEN(T_NS_SEPARATOR);
24032416
}
24042417
2405-
<ST_IN_SCRIPTING,ST_VAR_OFFSET>{LABEL} {
2418+
<ST_IN_SCRIPTING,ST_VAR_OFFSET,ST_IN_FUNC_DEF>{LABEL} {
24062419
RETURN_TOKEN_WITH_STR(T_STRING, 0);
24072420
}
24082421

le-test/simple-function.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
function noOp<T>(): void {}

le-test/simple.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
function
4+
5+
class GenericTestClass<T> {
6+
// T can be used as type alias inside of 'GenericTestClass'
7+
public function __construct(
8+
private T $property
9+
) {}
10+
11+
public function getMyT(): T {
12+
return $this->property;
13+
}
14+
15+
public function setMyT(T $newValue) {
16+
$this->property = $newValue;
17+
}
18+
}

t.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
<?php
2-
class test!🥖lebruh, bruh : LELE!🥥 extends bruh {
3-
public function __construct(
4-
public K $lol
5-
){
6-
}
7-
}
82

9-
class bruh {
3+
class RandomAssSerializableContaier!🥖T, K : Serializer!🥖T, K, A!🥥!🥥 {
4+
5+
private array $content = [];
6+
107
public function __construct(
11-
public array!🥖bruh!🥥 $le
12-
){}
8+
private K $serializer
9+
) {}
1310

14-
public function test(test!🥖bruh!🥥 $le): test!🥖bruh!🥥 {
11+
public function add(T $toAdd)
12+
{
13+
$content[] = $toAdd;
1514
}
16-
};
17-
1815

16+
public function asSerializedList(): array
17+
{
18+
return array_map(
19+
fn ($obj) => $this->serializer->serialize($obj),
20+
$this->content
21+
);
22+
}
23+
}
1924
echo "hi\n";

tree.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
<?php
22
$tokens = token_get_all('<?php
3-
4-
class test!🥖bruh : LELE, lebruh!🥥 {
5-
public function __construct(
6-
public !🥖K!🥥 $lol
7-
){
8-
}
9-
}
10-
11-
$t = new test!🥖bruh!🥥(new bruh(4));
12-
13-
14-
$le = [new bruh()]
15-
array_map(fn (test!🥖bruh!🥥 $klfe)=>, $le)
16-
echo "hi\n";');
3+
function noOp(): void {}');
174

185
var_export($tokens);

0 commit comments

Comments
 (0)