Skip to content

Commit 54ac1d6

Browse files
committed
Improve combinators
1 parent 8a3e6f2 commit 54ac1d6

15 files changed

Lines changed: 38 additions & 40 deletions

libs/phpdoc/src/DocBlock/Combinator/AccessCombinator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Reads an access level, that is one of the "public", "protected" or
1414
* "private" keywords.
1515
*
16-
* @implements CombinatorInterface<Visibility>
16+
* @template-implements CombinatorInterface<Visibility>
1717
*/
1818
final readonly class AccessCombinator implements CombinatorInterface
1919
{

libs/phpdoc/src/DocBlock/Combinator/AuthorNameCombinator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/**
1212
* Reads an author name, that is everything up to an optional "<email>".
1313
*
14-
* @implements CombinatorInterface<non-empty-string>
14+
* @template-implements CombinatorInterface<non-empty-string>
1515
*/
1616
final readonly class AuthorNameCombinator implements CombinatorInterface
1717
{

libs/phpdoc/src/DocBlock/Combinator/CallableTypeCombinator.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace TypeLang\PhpDoc\DocBlock\Combinator;
66

7-
use TypeLang\Parser\TypeParserInterface;
87
use TypeLang\PhpDoc\DocBlock\Reference\TypeReference;
98
use TypeLang\PhpDoc\Parser\Grammar\CombinatorInterface;
109
use TypeLang\PhpDoc\Parser\Grammar\Cursor;
@@ -14,23 +13,15 @@
1413
/**
1514
* Reads a type and accepts it only when it is a callable, so that a plain word
1615
* (which would parse as a type) is left for the following combinators.
17-
*
18-
* @implements CombinatorInterface<TypeReference>
1916
*/
20-
final readonly class CallableTypeCombinator implements CombinatorInterface
17+
final readonly class CallableTypeCombinator extends TypeCombinator
2118
{
2219
public const string NAME = 'CallableType';
2320

24-
private TypeCombinator $types;
25-
26-
public function __construct(TypeParserInterface $types)
27-
{
28-
$this->types = new TypeCombinator($types);
29-
}
30-
21+
#[\Override]
3122
public function __invoke(Cursor $cursor): TypeReference
3223
{
33-
$type = ($this->types)($cursor);
24+
$type = parent::__invoke($cursor);
3425

3526
if (!$type->type instanceof CallableTypeNode) {
3627
throw new NoMatchException('Expected a callable type');

libs/phpdoc/src/DocBlock/Combinator/DescriptionCombinator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* There is nothing to read when only whitespace is left, so wrap it in
1818
* {@see OptionalityRule} to make the description optional.
1919
*
20-
* @implements CombinatorInterface<DescriptionInterface>
20+
* @template-implements CombinatorInterface<DescriptionInterface>
2121
*/
2222
final readonly class DescriptionCombinator implements CombinatorInterface
2323
{

libs/phpdoc/src/DocBlock/Combinator/EmailCombinator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/**
1212
* Reads an email address up to its closing ">".
1313
*
14-
* @implements CombinatorInterface<non-empty-string>
14+
* @template-implements CombinatorInterface<non-empty-string>
1515
*/
1616
final readonly class EmailCombinator implements CombinatorInterface
1717
{

libs/phpdoc/src/DocBlock/Combinator/IntegerCombinator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/**
1212
* Reads a non-negative integer.
1313
*
14-
* @implements CombinatorInterface<int<0, max>>
14+
* @template-implements CombinatorInterface<int<0, max>>
1515
*/
1616
final readonly class IntegerCombinator implements CombinatorInterface
1717
{

libs/phpdoc/src/DocBlock/Combinator/IssueNameCombinator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Reads an issue identifier, that is a run of letters, digits, underscores,
1313
* dashes and dots.
1414
*
15-
* @implements CombinatorInterface<non-empty-string>
15+
* @template-implements CombinatorInterface<non-empty-string>
1616
*/
1717
final readonly class IssueNameCombinator implements CombinatorInterface
1818
{

libs/phpdoc/src/DocBlock/Combinator/NameCombinator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/**
1212
* Reads a template parameter name, that is a single identifier.
1313
*
14-
* @implements CombinatorInterface<non-empty-string>
14+
* @template-implements CombinatorInterface<non-empty-string>
1515
*/
1616
final readonly class NameCombinator implements CombinatorInterface
1717
{

libs/phpdoc/src/DocBlock/Combinator/TypeCombinator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
*
1717
* The result pairs the parsed type with the source text it was read from.
1818
*
19-
* @implements CombinatorInterface<TypeReference>
19+
* @template-implements CombinatorInterface<TypeReference>
2020
*/
21-
final readonly class TypeCombinator implements CombinatorInterface
21+
readonly class TypeCombinator implements CombinatorInterface
2222
{
2323
public const string NAME = 'Type';
2424

libs/phpdoc/src/DocBlock/Combinator/UriCombinator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/**
1414
* Reads a URI, that is a well-formed word as defined by RFC 3986.
1515
*
16-
* @implements CombinatorInterface<UriReference>
16+
* @template-implements CombinatorInterface<UriReference>
1717
*/
1818
final readonly class UriCombinator implements CombinatorInterface
1919
{

0 commit comments

Comments
 (0)