We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f767b9f commit f68e1a4Copy full SHA for f68e1a4
.editorconfig
@@ -0,0 +1,9 @@
1
+root = true
2
+
3
+[*.y]
4
+charset = utf-8
5
+end_of_line = lf
6
+insert_final_newline = true
7
+trim_trailing_whitespace = true
8
+indent_style = space
9
+indent_size = 4
grammar/php7.y
@@ -28,7 +28,7 @@ reserved_non_modifiers:
28
| T_FUNCTION | T_CONST | T_RETURN | T_PRINT | T_YIELD | T_LIST | T_SWITCH | T_ENDSWITCH | T_CASE | T_DEFAULT
29
| T_BREAK | T_ARRAY | T_CALLABLE | T_EXTENDS | T_IMPLEMENTS | T_NAMESPACE | T_TRAIT | T_INTERFACE | T_CLASS
30
| T_CLASS_C | T_TRAIT_C | T_FUNC_C | T_METHOD_C | T_LINE | T_FILE | T_DIR | T_NS_C | T_HALT_COMPILER | T_FN
31
- | T_MATCH
+ | T_MATCH | T_ENUM
32
;
33
34
semi_reserved:
@@ -356,6 +356,18 @@ class_declaration_statement:
356
$this->checkInterface($$, #3); }
357
| optional_attributes T_TRAIT identifier '{' class_statement_list '}'
358
{ $$ = Stmt\Trait_[$3, ['stmts' => $5, 'attrGroups' => $1]]; }
359
+ | optional_attributes T_ENUM identifier enum_scalar_type implements_list '{' class_statement_list '}'
360
+ { $$ = Stmt\Enum_[$3, ['scalarType' => $4, 'implements' => $5, 'stmts' => $7, 'attrGroups' => $1]];
361
+ $this->checkEnum($$, #3); }
362
+;
363
364
+enum_scalar_type:
365
+ /* empty */ { $$ = null; }
366
+ | ':' type { $$ = $2; }
367
368
+enum_case_expr:
369
370
+ | '=' expr { $$ = $2; }
371
372
373
class_entry_type:
@@ -637,6 +649,8 @@ class_statement:
637
649
{ $$ = Stmt\ClassMethod[$5, ['type' => $2, 'byRef' => $4, 'params' => $7, 'returnType' => $9, 'stmts' => $10, 'attrGroups' => $1]];
638
650
$this->checkClassMethod($$, #2); }
639
651
| T_USE class_name_list trait_adaptations { $$ = Stmt\TraitUse[$2, $3]; }
652
+ | optional_attributes T_CASE identifier enum_case_expr semi
653
+ { $$ = Stmt\EnumCase[$3, $4, $1]; }
640
654
| error { $$ = null; /* will be skipped */ }
641
655
642
656
grammar/tokens.y
@@ -83,6 +83,7 @@
83
%token T_CLASS
84
%token T_TRAIT
85
%token T_INTERFACE
86
+%token T_ENUM
87
%token T_EXTENDS
88
%token T_IMPLEMENTS
89
%token T_OBJECT_OPERATOR
lib/PhpParser/Node/Stmt/Class_.php
@@ -32,7 +32,7 @@ class Class_ extends ClassLike
* 'extends' => null : Name of extended class
* 'implements' => array(): Names of implemented interfaces
* 'stmts' => array(): Statements
35
- * '$attrGroups' => array(): PHP attribute groups
+ * 'attrGroups' => array(): PHP attribute groups
36
* @param array $attributes Additional attributes
37
*/
38
public function __construct($name, array $subNodes = [], array $attributes = []) {
lib/PhpParser/Node/Stmt/EnumCase.php
@@ -0,0 +1,37 @@
+<?php declare(strict_types=1);
+namespace PhpParser\Node\Stmt;
+use PhpParser\Node;
+use PhpParser\Node\AttributeGroup;
+class EnumCase extends Node\Stmt
+{
10
+ /** @var Node\Identifier Enum case name */
11
+ public $name;
12
+ /** @var Node\Expr|null Enum case expression */
13
+ public $expr;
14
+ /** @var Node\AttributeGroup[] PHP attribute groups */
15
+ public $attrGroups;
16
17
+ /**
18
+ * @param string|Node\Identifier $name Enum case name
19
+ * @param Node\Expr|null $expr Enum case expression
20
+ * @param AttributeGroup[] $attrGroups PHP attribute groups
21
+ * @param array $attributes Additional attributes
22
+ */
23
+ public function __construct($name, Node\Expr $expr = null, array $attrGroups = [], array $attributes = []) {
24
+ parent::__construct($attributes);
25
+ $this->name = \is_string($name) ? new Node\Identifier($name) : $name;
26
+ $this->expr = $expr;
27
+ $this->attrGroups = $attrGroups;
+ }
+ public function getSubNodeNames() : array {
+ return ['attrGroups', 'name', 'expr'];
+ public function getType() : string {
+ return 'Stmt_EnumCase';
+}
lib/PhpParser/Node/Stmt/Enum_.php
@@ -0,0 +1,40 @@
+class Enum_ extends ClassLike
+ /** @var null|Node\Identifier Scalar Type */
+ public $scalarType;
+ /** @var Node\Name[] Names of implemented interfaces */
+ public $implements;
+ * @param string|Node\Identifier|null $name Name
+ * @param array $subNodes Array of the following optional subnodes:
+ * 'scalarType' => null : Scalar type
+ * 'implements' => array() : Names of implemented interfaces
+ * 'stmts' => array() : Statements
+ * 'attrGroups' => array() : PHP attribute groups
+ public function __construct($name, array $subNodes = [], array $attributes = []) {
+ $this->scalarType = $subNodes['scalarType'] ?? null;
+ $this->implements = $subNodes['implements'] ?? [];
+ $this->stmts = $subNodes['stmts'] ?? [];
+ $this->attrGroups = $subNodes['attrGroups'] ?? [];
+ return ['attrGroups', 'name', 'scalarType', 'implements', 'stmts'];
+ return 'Stmt_Enum';
39
40
lib/PhpParser/Parser/Php5.php
@@ -193,9 +193,9 @@ class Php5 extends \PhpParser\ParserAbstract
193
"'`'",
194
"']'",
195
"'\"'",
196
+ "T_ENUM",
197
"T_NULLSAFE_OBJECT_OPERATOR",
- "T_ATTRIBUTE",
198
- "T_ENUM"
+ "T_ATTRIBUTE"
199
);
200
201
protected $tokenToSymbol = array(
@@ -235,10 +235,10 @@ class Php5 extends \PhpParser\ParserAbstract
235
94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
236
104, 105, 106, 107, 108, 109, 110, 111, 112, 113,
237
114, 115, 116, 117, 118, 119, 120, 121, 122, 123,
238
- 124, 125, 126, 127, 128, 129, 130, 131, 163, 132,
239
- 133, 134, 135, 136, 137, 138, 139, 140, 141, 142,
240
- 143, 144, 145, 146, 147, 148, 149, 150, 151, 152,
241
- 153, 164, 165
+ 124, 125, 126, 127, 128, 163, 129, 130, 131, 164,
+ 132, 133, 134, 135, 136, 137, 138, 139, 140, 141,
+ 142, 143, 144, 145, 146, 147, 148, 149, 150, 151,
+ 152, 153, 165
242
243
244
protected $action = array(
0 commit comments