Skip to content

Commit 7ff8145

Browse files
committed
Support php 8.2 true type
https://wiki.php.net/rfc/true-type
1 parent 17a63a0 commit 7ff8145

File tree

4 files changed

+129
-1
lines changed

4 files changed

+129
-1
lines changed

src/Parser.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +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,
147148
TokenKind::IterableReservedWord, TokenKind::MixedReservedWord]; // TODO update spec
148-
$this->returnTypeDeclarationTokens = \array_merge([TokenKind::VoidReservedWord, TokenKind::NullReservedWord, TokenKind::FalseReservedWord, TokenKind::StaticKeyword], $this->parameterTypeDeclarationTokens);
149+
$this->returnTypeDeclarationTokens = \array_merge([TokenKind::VoidReservedWord, TokenKind::NullReservedWord, TokenKind::FalseReservedWord, TokenKind::TrueReservedWord, TokenKind::StaticKeyword], $this->parameterTypeDeclarationTokens);
149150
}
150151

151152
/**

tests/cases/parser/true.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
function identity(true $x): true { return $x; }

tests/cases/parser/true.php.diag

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

tests/cases/parser/true.php.tree

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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": 8
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": "TrueReservedWord",
44+
"textLength": 4
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+
}
61+
},
62+
"closeParen": {
63+
"kind": "CloseParenToken",
64+
"textLength": 1
65+
},
66+
"colonToken": {
67+
"kind": "ColonToken",
68+
"textLength": 1
69+
},
70+
"questionToken": null,
71+
"returnTypeList": {
72+
"QualifiedNameList": {
73+
"children": [
74+
{
75+
"kind": "TrueReservedWord",
76+
"textLength": 4
77+
}
78+
]
79+
}
80+
},
81+
"compoundStatementOrSemicolon": {
82+
"CompoundStatementNode": {
83+
"openBrace": {
84+
"kind": "OpenBraceToken",
85+
"textLength": 1
86+
},
87+
"statements": [
88+
{
89+
"ReturnStatement": {
90+
"returnKeyword": {
91+
"kind": "ReturnKeyword",
92+
"textLength": 6
93+
},
94+
"expression": {
95+
"Variable": {
96+
"dollar": null,
97+
"name": {
98+
"kind": "VariableName",
99+
"textLength": 2
100+
}
101+
}
102+
},
103+
"semicolon": {
104+
"kind": "SemicolonToken",
105+
"textLength": 1
106+
}
107+
}
108+
}
109+
],
110+
"closeBrace": {
111+
"kind": "CloseBraceToken",
112+
"textLength": 1
113+
}
114+
}
115+
}
116+
}
117+
}
118+
],
119+
"endOfFileToken": {
120+
"kind": "EndOfFileToken",
121+
"textLength": 0
122+
}
123+
}
124+
}

0 commit comments

Comments
 (0)