Skip to content

Commit 6399a77

Browse files
committed
Support parsing php 8.1 enum doc comments
Requires php/php-src#6984 (php 8.1 has no public alphas yet)
1 parent b8fa288 commit 6399a77

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

ast_data.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,8 @@ zend_string *ast_kind_child_name(zend_ast_kind kind, uint32_t child) {
658658
switch (child) {
659659
case 0: return AST_STR(str_name);
660660
case 1: return AST_STR(str_expr);
661-
case 2: return AST_STR(str_attributes);
661+
case 2: return AST_STR(str_docComment);
662+
case 3: return AST_STR(str_attributes);
662663
}
663664
return NULL;
664665
case ZEND_AST_METHOD_CALL:

scripts/generate_ast_data.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
'ZEND_AST_MATCH' => ['cond', 'stmts'],
135135
'ZEND_AST_MATCH_ARM' => ['cond', 'expr'],
136136
'ZEND_AST_NAMED_ARG' => ['name', 'expr'],
137-
'ZEND_AST_ENUM_CASE' => ['name', 'expr', 'attributes'],
137+
'ZEND_AST_ENUM_CASE' => ['name', 'expr', 'docComment', 'attributes'],
138138

139139
/* 3 child nodes */
140140
'ZEND_AST_METHOD_CALL' => ['expr', 'method', 'args'],

tests/php81_enums.phpt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ enum HasValue: int {
1616
1717
#[MyAttribute(1)]
1818
enum NoValue {
19+
/** Case doc comment */
1920
#[OtherAttribute()]
2021
case FOO;
2122
}
@@ -39,6 +40,7 @@ AST_STMT_LIST
3940
0: AST_ENUM_CASE
4041
name: "FOO"
4142
expr: 42
43+
docComment: null
4244
attributes: null
4345
1: AST_CLASS_CONST_DECL
4446
flags: MODIFIER_PUBLIC (%d)
@@ -61,6 +63,7 @@ AST_STMT_LIST
6163
0: AST_ENUM_CASE
6264
name: "FOO"
6365
expr: null
66+
docComment: "/** Case doc comment */"
6467
attributes: AST_ATTRIBUTE_LIST
6568
0: AST_ATTRIBUTE_GROUP
6669
0: AST_ATTRIBUTE
@@ -80,6 +83,7 @@ AST_STMT_LIST
8083
0: AST_ENUM_CASE
8184
name: "FOO"
8285
expr: 42
86+
docComment: null
8387
attributes: null
8488
1: AST_CLASS_CONST_GROUP
8589
flags: MODIFIER_PUBLIC (%d)
@@ -106,6 +110,7 @@ AST_STMT_LIST
106110
0: AST_ENUM_CASE
107111
name: "FOO"
108112
expr: null
113+
docComment: "/** Case doc comment */"
109114
attributes: AST_ATTRIBUTE_LIST
110115
0: AST_ATTRIBUTE_GROUP
111116
0: AST_ATTRIBUTE
@@ -133,6 +138,7 @@ AST_STMT_LIST
133138
0: AST_ENUM_CASE
134139
name: "FOO"
135140
expr: 42
141+
docComment: null
136142
attributes: null
137143
1: AST_CLASS_CONST_GROUP
138144
flags: MODIFIER_PUBLIC (%d)
@@ -161,6 +167,7 @@ AST_STMT_LIST
161167
0: AST_ENUM_CASE
162168
name: "FOO"
163169
expr: null
170+
docComment: "/** Case doc comment */"
164171
attributes: AST_ATTRIBUTE_LIST
165172
0: AST_ATTRIBUTE_GROUP
166173
0: AST_ATTRIBUTE

0 commit comments

Comments
 (0)