Skip to content

Commit 49058c4

Browse files
authored
Merge pull request #374 from TysonAndre/support-never
Support php 'never' type, change parsing of 'void'
2 parents 1261275 + 0d46605 commit 49058c4

9 files changed

+203
-3
lines changed

src/Parser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ public function __construct() {
144144
[TokenKind::ArrayKeyword, TokenKind::CallableKeyword, TokenKind::BoolReservedWord,
145145
TokenKind::FloatReservedWord, TokenKind::IntReservedWord, TokenKind::StringReservedWord,
146146
TokenKind::ObjectReservedWord, TokenKind::NullReservedWord, TokenKind::FalseReservedWord,
147-
TokenKind::TrueReservedWord,
148-
TokenKind::IterableReservedWord, TokenKind::MixedReservedWord]; // TODO update spec
149-
$this->returnTypeDeclarationTokens = \array_merge([TokenKind::VoidReservedWord, TokenKind::NullReservedWord, TokenKind::FalseReservedWord, TokenKind::TrueReservedWord, TokenKind::StaticKeyword], $this->parameterTypeDeclarationTokens);
147+
TokenKind::TrueReservedWord, TokenKind::IterableReservedWord, TokenKind::MixedReservedWord,
148+
TokenKind::VoidReservedWord, TokenKind::NeverReservedWord]; // TODO update spec
149+
$this->returnTypeDeclarationTokens = \array_merge([TokenKind::StaticKeyword], $this->parameterTypeDeclarationTokens);
150150
}
151151

152152
/**

src/TokenKind.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ class TokenKind {
175175
const NullReservedWord = 322;
176176
const MixedReservedWord = 340;
177177
const IterableReservedWord = 170;
178+
const NeverReservedWord = 341;
178179

179180
const ScriptSectionStartTag = 323;
180181
const ScriptSectionEndTag = 324;

src/TokenStringMaps.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class TokenStringMaps {
109109
"void" => TokenKind::VoidReservedWord,
110110
"iterable" => TokenKind::IterableReservedWord,
111111
"mixed" => TokenKind::MixedReservedWord,
112+
"never" => TokenKind::NeverReservedWord,
112113
];
113114

114115
const OPERATORS_AND_PUNCTUATORS = [
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
function example() : never {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"SourceFileNode": {
3+
"statementList": [
4+
{
5+
"InlineHtml": {
6+
"scriptSectionEndTag": null,
7+
"text": null,
8+
"scriptSectionStartTag": {
9+
"kind": "ScriptSectionStartTag",
10+
"textLength": 6
11+
}
12+
}
13+
},
14+
{
15+
"FunctionDeclaration": {
16+
"attributes": null,
17+
"functionKeyword": {
18+
"kind": "FunctionKeyword",
19+
"textLength": 8
20+
},
21+
"byRefToken": null,
22+
"name": {
23+
"kind": "Name",
24+
"textLength": 7
25+
},
26+
"openParen": {
27+
"kind": "OpenParenToken",
28+
"textLength": 1
29+
},
30+
"parameters": null,
31+
"closeParen": {
32+
"kind": "CloseParenToken",
33+
"textLength": 1
34+
},
35+
"colonToken": {
36+
"kind": "ColonToken",
37+
"textLength": 1
38+
},
39+
"questionToken": null,
40+
"returnTypeList": {
41+
"QualifiedNameList": {
42+
"children": [
43+
{
44+
"kind": "NeverReservedWord",
45+
"textLength": 5
46+
}
47+
]
48+
}
49+
},
50+
"compoundStatementOrSemicolon": {
51+
"CompoundStatementNode": {
52+
"openBrace": {
53+
"kind": "OpenBraceToken",
54+
"textLength": 1
55+
},
56+
"statements": [],
57+
"closeBrace": {
58+
"kind": "CloseBraceToken",
59+
"textLength": 1
60+
}
61+
}
62+
}
63+
}
64+
}
65+
],
66+
"endOfFileToken": {
67+
"kind": "EndOfFileToken",
68+
"textLength": 0
69+
}
70+
}
71+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
// These are fatal compile errors, not parse errors
3+
function u(never $g, void $u) {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
{
2+
"SourceFileNode": {
3+
"statementList": [
4+
{
5+
"InlineHtml": {
6+
"scriptSectionEndTag": null,
7+
"text": null,
8+
"scriptSectionStartTag": {
9+
"kind": "ScriptSectionStartTag",
10+
"textLength": 6
11+
}
12+
}
13+
},
14+
{
15+
"FunctionDeclaration": {
16+
"attributes": null,
17+
"functionKeyword": {
18+
"kind": "FunctionKeyword",
19+
"textLength": 8
20+
},
21+
"byRefToken": null,
22+
"name": {
23+
"kind": "Name",
24+
"textLength": 1
25+
},
26+
"openParen": {
27+
"kind": "OpenParenToken",
28+
"textLength": 1
29+
},
30+
"parameters": {
31+
"ParameterDeclarationList": {
32+
"children": [
33+
{
34+
"Parameter": {
35+
"attributes": null,
36+
"visibilityToken": null,
37+
"modifiers": null,
38+
"questionToken": null,
39+
"typeDeclarationList": {
40+
"QualifiedNameList": {
41+
"children": [
42+
{
43+
"kind": "NeverReservedWord",
44+
"textLength": 5
45+
}
46+
]
47+
}
48+
},
49+
"byRefToken": null,
50+
"dotDotDotToken": null,
51+
"variableName": {
52+
"kind": "VariableName",
53+
"textLength": 2
54+
},
55+
"equalsToken": null,
56+
"default": null
57+
}
58+
},
59+
{
60+
"kind": "CommaToken",
61+
"textLength": 1
62+
},
63+
{
64+
"Parameter": {
65+
"attributes": null,
66+
"visibilityToken": null,
67+
"modifiers": null,
68+
"questionToken": null,
69+
"typeDeclarationList": {
70+
"QualifiedNameList": {
71+
"children": [
72+
{
73+
"kind": "VoidReservedWord",
74+
"textLength": 4
75+
}
76+
]
77+
}
78+
},
79+
"byRefToken": null,
80+
"dotDotDotToken": null,
81+
"variableName": {
82+
"kind": "VariableName",
83+
"textLength": 2
84+
},
85+
"equalsToken": null,
86+
"default": null
87+
}
88+
}
89+
]
90+
}
91+
},
92+
"closeParen": {
93+
"kind": "CloseParenToken",
94+
"textLength": 1
95+
},
96+
"colonToken": null,
97+
"questionToken": null,
98+
"returnTypeList": null,
99+
"compoundStatementOrSemicolon": {
100+
"CompoundStatementNode": {
101+
"openBrace": {
102+
"kind": "OpenBraceToken",
103+
"textLength": 1
104+
},
105+
"statements": [],
106+
"closeBrace": {
107+
"kind": "CloseBraceToken",
108+
"textLength": 1
109+
}
110+
}
111+
}
112+
}
113+
}
114+
],
115+
"endOfFileToken": {
116+
"kind": "EndOfFileToken",
117+
"textLength": 0
118+
}
119+
}
120+
}

0 commit comments

Comments
 (0)