Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntactic support for type aliases #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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;'
);
}
}
Loading