From 30ab31c3537b36fa10d71809d730cb2234684f56 Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Thu, 26 Oct 2023 19:25:56 +0200 Subject: [PATCH] Syntactic support for type aliases --- src/main/php/lang/ast/syntax/PHP.class.php | 4 ++++ .../php/lang/ast/unittest/parse/NamespacesTest.class.php | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/src/main/php/lang/ast/syntax/PHP.class.php b/src/main/php/lang/ast/syntax/PHP.class.php index 430fe4a..3f22be3 100755 --- a/src/main/php/lang/ast/syntax/PHP.class.php +++ b/src/main/php/lang/ast/syntax/PHP.class.php @@ -603,6 +603,10 @@ public function __construct() { $names[$import]= $parse->token->value; $parse->scope->import($import, $parse->token->value); $parse->forward(); + } else if ('=' === $parse->token->value) { + $parse->forward(); + $type= 'type'; + $names[$import]= $this->type($parse, false); } else { $names[$import]= null; $parse->scope->import($import); diff --git a/src/test/php/lang/ast/unittest/parse/NamespacesTest.class.php b/src/test/php/lang/ast/unittest/parse/NamespacesTest.class.php index 0266cfd..243a16c 100755 --- a/src/test/php/lang/ast/unittest/parse/NamespacesTest.class.php +++ b/src/test/php/lang/ast/unittest/parse/NamespacesTest.class.php @@ -1,6 +1,7 @@ assertParsed( + [new UseStatement('type', ['Name' => new IsUnion([new IsLiteral('string'), new IsLiteral('null')])], self::LINE)], + 'use Name = string|null;' + ); + } } \ No newline at end of file