Skip to content

Commit

Permalink
Syntactic support for type aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Oct 26, 2023
1 parent 08c725e commit 30ab31c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/php/lang/ast/syntax/PHP.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions src/test/php/lang/ast/unittest/parse/NamespacesTest.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace lang\ast\unittest\parse;

use lang\ast\nodes\{NamespaceDeclaration, UseStatement};
use lang\ast\types\{IsLiteral, IsUnion};
use test\{Assert, Test};

class NamespacesTest extends ParseTest {
Expand Down Expand Up @@ -100,4 +101,12 @@ public function use_const() {
'use const MODIFIER_STATIC;'
);
}

#[Test]
public function use_type() {
$this->assertParsed(
[new UseStatement('type', ['Name' => new IsUnion([new IsLiteral('string'), new IsLiteral('null')])], self::LINE)],
'use Name = string|null;'
);
}
}

0 comments on commit 30ab31c

Please sign in to comment.