From 8d5e0f80faa5708ef004370da8503ffc06d699c5 Mon Sep 17 00:00:00 2001 From: desIstUrGuad Date: Thu, 3 Apr 2025 18:47:26 +0000 Subject: [PATCH 1/2] le --- LE.md | 28 ++++++++++++++++++++++++++++ Zend/zend_language_scanner.l | 21 +++++++++++++++++---- le-test/simple-function.php | 3 +++ le-test/simple.php | 18 ++++++++++++++++++ t.php | 29 +++++++++++++++++------------ tree.php | 15 +-------------- 6 files changed, 84 insertions(+), 30 deletions(-) create mode 100644 le-test/simple-function.php create mode 100644 le-test/simple.php diff --git a/LE.md b/LE.md index 9411f746897f5..179c1986bd82a 100644 --- a/LE.md +++ b/LE.md @@ -1,5 +1,33 @@ # Generics syntax +``` +interface Comparable { + +} + +interface Equatable { + +} + +int implements Comparable, Equatable; + +class Foo { + + class Bar { + + } + +} + +enum FooBar { + + case Blum(int bam); + case Bam(T boom); + +} + +``` + ## Generic classes and interfaces ### Basic case diff --git a/Zend/zend_language_scanner.l b/Zend/zend_language_scanner.l index 72f2f0c938ac7..d6f6542300401 100644 --- a/Zend/zend_language_scanner.l +++ b/Zend/zend_language_scanner.l @@ -1395,6 +1395,7 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_ } "function" { + yy_push_state(ST_IN_FUNC_DEF); RETURN_TOKEN_WITH_IDENT(T_FUNCTION); } @@ -1537,14 +1538,21 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_ RETURN_TOKEN_WITH_IDENT(T_PRINT); } - "!🥖" { + "<" { + yy_push_state(ST_IN_GENERIC); RETURN_TOKEN(T_GENERIC_START); } - "!🥥" { + ">" { + yy_pop_state(); RETURN_TOKEN(T_GENERIC_END); } +{LABEL} { + RETURN_TOKEN_WITH_STR(T_STRING, 0); +} + + "class" { RETURN_TOKEN_WITH_IDENT(T_CLASS); } @@ -1588,7 +1596,7 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_ RETURN_TOKEN(T_NULLSAFE_OBJECT_OPERATOR); } -{WHITESPACE}+ { +{WHITESPACE}+ { goto return_whitespace; } @@ -1916,6 +1924,11 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_ RETURN_TOKEN(yytext[0]); } +"(" { + enter_nesting('('); + yy_pop_state(); +} + {TOKENS} { RETURN_TOKEN(yytext[0]); } @@ -2402,7 +2415,7 @@ inline_char_handler: RETURN_TOKEN(T_NS_SEPARATOR); } -{LABEL} { +{LABEL} { RETURN_TOKEN_WITH_STR(T_STRING, 0); } diff --git a/le-test/simple-function.php b/le-test/simple-function.php new file mode 100644 index 0000000000000..307fa2d5f8d03 --- /dev/null +++ b/le-test/simple-function.php @@ -0,0 +1,3 @@ +(): void {} \ No newline at end of file diff --git a/le-test/simple.php b/le-test/simple.php new file mode 100644 index 0000000000000..c91f3ec59713c --- /dev/null +++ b/le-test/simple.php @@ -0,0 +1,18 @@ + { + // 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; + } +} \ No newline at end of file diff --git a/t.php b/t.php index a3e35aa2b46fd..39f17badeb824 100644 --- a/t.php +++ b/t.php @@ -1,19 +1,24 @@ $this->serializer->serialize($obj), + $this->content + ); + } +} echo "hi\n"; \ No newline at end of file diff --git a/tree.php b/tree.php index 16fb675a5a960..d8098b708d534 100644 --- a/tree.php +++ b/tree.php @@ -1,18 +1,5 @@ , $le) - echo "hi\n";'); +function noOp(): void {}'); var_export($tokens); From f5f7dfff60409fb7d9fa7c51ab2c634372fccbab Mon Sep 17 00:00:00 2001 From: desIstUrGuad Date: Sat, 10 May 2025 16:07:29 +0000 Subject: [PATCH 2/2] wip --- Zend/zend_language_scanner.l | 34 +++++++++++++++++++----- le-test/{simple.php => simple-class.php} | 4 +-- t.php | 2 +- tree.php | 11 +++++--- 4 files changed, 37 insertions(+), 14 deletions(-) rename le-test/{simple.php => simple-class.php} (87%) diff --git a/Zend/zend_language_scanner.l b/Zend/zend_language_scanner.l index d6f6542300401..aa3381a8a580e 100644 --- a/Zend/zend_language_scanner.l +++ b/Zend/zend_language_scanner.l @@ -1538,12 +1538,12 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_ RETURN_TOKEN_WITH_IDENT(T_PRINT); } - "<" { + "<" { yy_push_state(ST_IN_GENERIC); RETURN_TOKEN(T_GENERIC_START); } - ">" { + ">" { yy_pop_state(); RETURN_TOKEN(T_GENERIC_END); } @@ -1554,9 +1554,19 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_ "class" { + yy_push_state(ST_IN_CLASS_DEF); RETURN_TOKEN_WITH_IDENT(T_CLASS); } + + +"{" { + yy_pop_state(); + yy_push_state(ST_IN_SCRIPTING); + enter_nesting('{'); + RETURN_TOKEN('{'); +} + "interface" { RETURN_TOKEN_WITH_IDENT(T_INTERFACE); } @@ -1578,11 +1588,11 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_ RETURN_TOKEN_WITH_IDENT(T_ENUM); } -"extends" { +"extends" { RETURN_TOKEN_WITH_IDENT(T_EXTENDS); } -"implements" { +"implements" { RETURN_TOKEN_WITH_IDENT(T_IMPLEMENTS); } @@ -1596,7 +1606,7 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_ RETURN_TOKEN(T_NULLSAFE_OBJECT_OPERATOR); } -{WHITESPACE}+ { +{WHITESPACE}+ { goto return_whitespace; } @@ -1738,9 +1748,14 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_ } "private" { + yy_push_state(ST_IN_PROPERTY_TYPE_DEF); RETURN_TOKEN_WITH_IDENT(T_PRIVATE); } + { + +} + "protected" { RETURN_TOKEN_WITH_IDENT(T_PROTECTED); } @@ -1925,8 +1940,13 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_ } "(" { - enter_nesting('('); yy_pop_state(); + enter_nesting(yytext[0]); + RETURN_TOKEN(yytext[0]); +} + +":"|"," { + RETURN_TOKEN(yytext[0]); } {TOKENS} { @@ -2415,7 +2435,7 @@ inline_char_handler: RETURN_TOKEN(T_NS_SEPARATOR); } -{LABEL} { +{LABEL} { RETURN_TOKEN_WITH_STR(T_STRING, 0); } diff --git a/le-test/simple.php b/le-test/simple-class.php similarity index 87% rename from le-test/simple.php rename to le-test/simple-class.php index c91f3ec59713c..73423ce0166f2 100644 --- a/le-test/simple.php +++ b/le-test/simple-class.php @@ -1,8 +1,6 @@ { +class GenericTestClass { // T can be used as type alias inside of 'GenericTestClass' public function __construct( private T $property diff --git a/t.php b/t.php index 39f17badeb824..50eb67b5c605b 100644 --- a/t.php +++ b/t.php @@ -1,6 +1,6 @@ > { private array $content = []; diff --git a/tree.php b/tree.php index d8098b708d534..934f17b7dd468 100644 --- a/tree.php +++ b/tree.php @@ -1,5 +1,10 @@ { + public Serializable $test; + function __construct() {} +} +'); -var_export($tokens); +var_export($classTokens); \ No newline at end of file