Skip to content

Commit

Permalink
Add support for DNF types (#862)
Browse files Browse the repository at this point in the history
(cherry picked from commit 9b2a01a)
  • Loading branch information
Girgias authored and nikic committed Sep 3, 2022
1 parent b30e7e7 commit a951e9e
Show file tree
Hide file tree
Showing 6 changed files with 1,085 additions and 856 deletions.
38 changes: 28 additions & 10 deletions grammar/php7.y
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ type_expr:
type { $$ = $1; }
| '?' type { $$ = Node\NullableType[$2]; }
| union_type { $$ = Node\UnionType[$1]; }
| intersection_type { $$ = Node\IntersectionType[$1]; }
| intersection_type { $$ = $1; }
;

type:
Expand All @@ -585,34 +585,52 @@ type_without_static:
| T_CALLABLE { $$ = Node\Identifier['callable']; }
;

union_type_element:
type { $$ = $1; }
| '(' intersection_type ')' { $$ = $2; }
;

union_type:
type '|' type { init($1, $3); }
| union_type '|' type { push($1, $3); }
union_type_element '|' union_type_element { init($1, $3); }
| union_type '|' union_type_element { push($1, $3); }
;

union_type_without_static_element:
type_without_static { $$ = $1; }
| '(' intersection_type_without_static ')' { $$ = $2; }
;

union_type_without_static:
type_without_static '|' type_without_static { init($1, $3); }
| union_type_without_static '|' type_without_static { push($1, $3); }
union_type_without_static_element '|' union_type_without_static_element { init($1, $3); }
| union_type_without_static '|' union_type_without_static_element { push($1, $3); }
;

intersection_type:
intersection_type_list:
type T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG type { init($1, $3); }
| intersection_type T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG type
| intersection_type_list T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG type
{ push($1, $3); }
;

intersection_type_without_static:
intersection_type:
intersection_type_list { $$ = Node\IntersectionType[$1]; }
;

intersection_type_without_static_list:
type_without_static T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG type_without_static
{ init($1, $3); }
| intersection_type_without_static T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG type_without_static
| intersection_type_without_static_list T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG type_without_static
{ push($1, $3); }
;

intersection_type_without_static:
intersection_type_without_static_list { $$ = Node\IntersectionType[$1]; }
;

type_expr_without_static:
type_without_static { $$ = $1; }
| '?' type_without_static { $$ = Node\NullableType[$2]; }
| union_type_without_static { $$ = Node\UnionType[$1]; }
| intersection_type_without_static { $$ = Node\IntersectionType[$1]; }
| intersection_type_without_static { $$ = $1; }
;

optional_type_without_static:
Expand Down
2 changes: 1 addition & 1 deletion lib/PhpParser/Node/UnionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class UnionType extends ComplexType
/**
* Constructs a union type.
*
* @param (Identifier|Name)[] $types Types
* @param (Identifier|Name|IntersectionType)[] $types Types
* @param array $attributes Additional attributes
*/
public function __construct(array $types, array $attributes = []) {
Expand Down
Loading

0 comments on commit a951e9e

Please sign in to comment.