-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a10a69c
commit 7b05772
Showing
5 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TypeLang\PHPDoc\Tag\Content; | ||
|
||
use TypeLang\PHPDoc\Exception\InvalidTagException; | ||
use TypeLang\PHPDoc\Tag\Content; | ||
|
||
/** | ||
* @template-extends Applicator<non-empty-string> | ||
*/ | ||
final class IdentifierApplicator extends Applicator | ||
{ | ||
private readonly OptionalIdentifierApplicator $id; | ||
|
||
/** | ||
* @param non-empty-string $tag | ||
*/ | ||
public function __construct( | ||
private readonly string $tag, | ||
) { | ||
$this->id = new OptionalIdentifierApplicator(); | ||
} | ||
|
||
/** | ||
* @return non-empty-string | ||
* | ||
* @throws InvalidTagException | ||
*/ | ||
public function __invoke(Content $lexer): string | ||
{ | ||
return ($this->id)($lexer) | ||
?? throw $lexer->getTagException(\sprintf( | ||
'Tag @%s contains an incorrect identifier value', | ||
$this->tag, | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TypeLang\PHPDoc\Tag\Content; | ||
|
||
use TypeLang\PHPDoc\Tag\Content; | ||
|
||
/** | ||
* @template-extends Applicator<non-empty-string|null> | ||
*/ | ||
final class OptionalIdentifierApplicator extends Applicator | ||
{ | ||
/** | ||
* @return non-empty-string|null | ||
*/ | ||
public function __invoke(Content $lexer): ?string | ||
{ | ||
if ($lexer->value === '') { | ||
return null; | ||
} | ||
|
||
\preg_match('/([a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)\b/u', $lexer->value, $matches); | ||
|
||
if (\count($matches) !== 2 || $matches[1] === '') { | ||
return null; | ||
} | ||
|
||
$lexer->shift(\strlen($matches[0])); | ||
|
||
return $matches[1]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters