Merge pull request #398 from dantleech/enum-interface-cluase
Support Enum Interface clause
This commit is contained in:
Коммит
84ce745a39
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
namespace Microsoft\PhpParser\Node;
|
||||
|
||||
use Microsoft\PhpParser\Node;
|
||||
use Microsoft\PhpParser\Token;
|
||||
|
||||
class EnumInterfaceClause extends Node {
|
||||
/** @var Token */
|
||||
public $implementsKeyword;
|
||||
|
||||
/** @var DelimitedList\QualifiedNameList|null */
|
||||
public $interfaceNameList;
|
||||
|
||||
const CHILD_NAMES = [
|
||||
'implementsKeyword',
|
||||
'interfaceNameList'
|
||||
];
|
||||
}
|
|
@ -10,6 +10,7 @@ use Microsoft\PhpParser\ClassLike;
|
|||
use Microsoft\PhpParser\NamespacedNameInterface;
|
||||
use Microsoft\PhpParser\NamespacedNameTrait;
|
||||
use Microsoft\PhpParser\Node\AttributeGroup;
|
||||
use Microsoft\PhpParser\Node\EnumInterfaceClause;
|
||||
use Microsoft\PhpParser\Node\StatementNode;
|
||||
use Microsoft\PhpParser\Node\EnumMembers;
|
||||
use Microsoft\PhpParser\Token;
|
||||
|
@ -23,6 +24,9 @@ class EnumDeclaration extends StatementNode implements NamespacedNameInterface,
|
|||
/** @var Token */
|
||||
public $enumKeyword;
|
||||
|
||||
/** @var EnumInterfaceClause|null */
|
||||
public $enumInterfaceClause;
|
||||
|
||||
/** @var Token */
|
||||
public $name;
|
||||
|
||||
|
@ -41,6 +45,7 @@ class EnumDeclaration extends StatementNode implements NamespacedNameInterface,
|
|||
'name',
|
||||
'colonToken',
|
||||
'enumType',
|
||||
'enumInterfaceClause',
|
||||
'enumMembers',
|
||||
];
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ use Microsoft\PhpParser\Node\ClassInterfaceClause;
|
|||
use Microsoft\PhpParser\Node\ClassMembersNode;
|
||||
use Microsoft\PhpParser\Node\ConstElement;
|
||||
use Microsoft\PhpParser\Node\EnumCaseDeclaration;
|
||||
use Microsoft\PhpParser\Node\EnumInterfaceClause;
|
||||
use Microsoft\PhpParser\Node\EnumMembers;
|
||||
use Microsoft\PhpParser\Node\Expression;
|
||||
use Microsoft\PhpParser\Node\Expression\{
|
||||
|
@ -3737,11 +3738,27 @@ class Parser {
|
|||
?: new MissingToken(TokenKind::EnumType, $this->token->fullStart);
|
||||
}
|
||||
|
||||
$enumDeclaration->enumInterfaceClause = $this->parseEnumInterfaceClause($enumDeclaration);
|
||||
$enumDeclaration->enumMembers = $this->parseEnumMembers($enumDeclaration);
|
||||
|
||||
return $enumDeclaration;
|
||||
}
|
||||
|
||||
private function parseEnumInterfaceClause(EnumDeclaration $enumDeclaration): ?EnumInterfaceClause {
|
||||
$enumInterfaceClause = new EnumInterfaceClause();
|
||||
$enumInterfaceClause->parent = $enumDeclaration;
|
||||
$enumInterfaceClause->implementsKeyword = $this->eatOptional1(TokenKind::ImplementsKeyword);
|
||||
|
||||
if ($enumInterfaceClause->implementsKeyword === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$enumInterfaceClause->interfaceNameList =
|
||||
$this->parseQualifiedNameList($enumInterfaceClause);
|
||||
return $enumInterfaceClause;
|
||||
}
|
||||
|
||||
|
||||
private function parseEnumMembers($parentNode) {
|
||||
$enumMembers = new EnumMembers();
|
||||
$enumMembers->parent = $parentNode;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
},
|
||||
"colonToken": null,
|
||||
"enumType": null,
|
||||
"enumInterfaceClause": null,
|
||||
"enumMembers": {
|
||||
"EnumMembers": {
|
||||
"openBrace": {
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
"kind": "IntReservedWord",
|
||||
"textLength": 3
|
||||
},
|
||||
"enumInterfaceClause": null,
|
||||
"enumMembers": {
|
||||
"EnumMembers": {
|
||||
"openBrace": {
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
},
|
||||
"colonToken": null,
|
||||
"enumType": null,
|
||||
"enumInterfaceClause": null,
|
||||
"enumMembers": {
|
||||
"EnumMembers": {
|
||||
"openBrace": {
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
"kind": "StringReservedWord",
|
||||
"textLength": 6
|
||||
},
|
||||
"enumInterfaceClause": null,
|
||||
"enumMembers": {
|
||||
"EnumMembers": {
|
||||
"openBrace": {
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
"kind": "EnumType",
|
||||
"textLength": 0
|
||||
},
|
||||
"enumInterfaceClause": null,
|
||||
"enumMembers": {
|
||||
"EnumMembers": {
|
||||
"openBrace": {
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
"kind": "IntReservedWord",
|
||||
"textLength": 3
|
||||
},
|
||||
"enumInterfaceClause": null,
|
||||
"enumMembers": {
|
||||
"EnumMembers": {
|
||||
"openBrace": {
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
<?php
|
||||
enum Foo: int implements Foo
|
||||
{
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
[]
|
|
@ -0,0 +1,80 @@
|
|||
{
|
||||
"SourceFileNode": {
|
||||
"statementList": [
|
||||
{
|
||||
"InlineHtml": {
|
||||
"scriptSectionEndTag": null,
|
||||
"text": null,
|
||||
"scriptSectionStartTag": {
|
||||
"kind": "ScriptSectionStartTag",
|
||||
"textLength": 6
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"EnumDeclaration": {
|
||||
"attributes": null,
|
||||
"enumKeyword": {
|
||||
"kind": "EnumKeyword",
|
||||
"textLength": 4
|
||||
},
|
||||
"name": {
|
||||
"kind": "Name",
|
||||
"textLength": 3
|
||||
},
|
||||
"colonToken": {
|
||||
"kind": "ColonToken",
|
||||
"textLength": 1
|
||||
},
|
||||
"enumType": {
|
||||
"kind": "IntReservedWord",
|
||||
"textLength": 3
|
||||
},
|
||||
"enumInterfaceClause": {
|
||||
"EnumInterfaceClause": {
|
||||
"implementsKeyword": {
|
||||
"kind": "ImplementsKeyword",
|
||||
"textLength": 10
|
||||
},
|
||||
"interfaceNameList": {
|
||||
"QualifiedNameList": {
|
||||
"children": [
|
||||
{
|
||||
"QualifiedName": {
|
||||
"globalSpecifier": null,
|
||||
"relativeSpecifier": null,
|
||||
"nameParts": [
|
||||
{
|
||||
"kind": "Name",
|
||||
"textLength": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"enumMembers": {
|
||||
"EnumMembers": {
|
||||
"openBrace": {
|
||||
"kind": "OpenBraceToken",
|
||||
"textLength": 1
|
||||
},
|
||||
"enumMemberDeclarations": [],
|
||||
"closeBrace": {
|
||||
"kind": "CloseBraceToken",
|
||||
"textLength": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"endOfFileToken": {
|
||||
"kind": "EndOfFileToken",
|
||||
"textLength": 0
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче