diff --git a/src/Languages/DocComment/DocCommentLanguage.php b/src/Languages/DocComment/DocCommentLanguage.php index 82bef52..40994f3 100644 --- a/src/Languages/DocComment/DocCommentLanguage.php +++ b/src/Languages/DocComment/DocCommentLanguage.php @@ -5,14 +5,8 @@ namespace Tempest\Highlight\Languages\DocComment; use Tempest\Highlight\Languages\Base\BaseLanguage; -use Tempest\Highlight\Languages\DocComment\Injections\GenericTypeInjection; -use Tempest\Highlight\Languages\DocComment\Patterns\DocCommentGenericTypePattern; -use Tempest\Highlight\Languages\DocComment\Patterns\DocCommentParamTypePattern; -use Tempest\Highlight\Languages\DocComment\Patterns\DocCommentReturnTypePattern; use Tempest\Highlight\Languages\DocComment\Patterns\DocCommentTagPattern; -use Tempest\Highlight\Languages\DocComment\Patterns\DocCommentTemplateTypePattern; -use Tempest\Highlight\Languages\DocComment\Patterns\DocCommentVariablePattern; -use Tempest\Highlight\Languages\DocComment\Patterns\DocCommentVarTypePattern; +use Tempest\Highlight\Languages\Php\Injections\PhpGenericTypeInjection; class DocCommentLanguage extends BaseLanguage { @@ -20,7 +14,7 @@ public function getInjections(): array { return [ ...parent::getInjections(), - new GenericTypeInjection(), + new PhpGenericTypeInjection(), ]; } @@ -29,12 +23,6 @@ public function getPatterns(): array return [ ...parent::getPatterns(), new DocCommentTagPattern(), - new DocCommentParamTypePattern(), - new DocCommentVarTypePattern(), - new DocCommentReturnTypePattern(), - new DocCommentTemplateTypePattern(), - new DocCommentGenericTypePattern(), - new DocCommentVariablePattern(), ]; } } diff --git a/src/Languages/DocComment/Injections/DocCommentInjection.php b/src/Languages/Php/Injections/PhpDocCommentInjection.php similarity index 58% rename from src/Languages/DocComment/Injections/DocCommentInjection.php rename to src/Languages/Php/Injections/PhpDocCommentInjection.php index 6fc3e46..ba1121b 100644 --- a/src/Languages/DocComment/Injections/DocCommentInjection.php +++ b/src/Languages/Php/Injections/PhpDocCommentInjection.php @@ -2,13 +2,14 @@ declare(strict_types=1); -namespace Tempest\Highlight\Languages\DocComment\Injections; +namespace Tempest\Highlight\Languages\Php\Injections; use Tempest\Highlight\Highlighter; use Tempest\Highlight\Injection; use Tempest\Highlight\IsInjection; +use Tempest\Highlight\Languages\Php\PhpDocCommentLanguage; -final readonly class DocCommentInjection implements Injection +final readonly class PhpDocCommentInjection implements Injection { use IsInjection; @@ -19,6 +20,6 @@ public function getPattern(): string public function parseContent(string $content, Highlighter $highlighter): string { - return $highlighter->parse($content, 'doc'); + return $highlighter->parse($content, new PhpDocCommentLanguage()); } } diff --git a/src/Languages/DocComment/Injections/GenericTypeInjection.php b/src/Languages/Php/Injections/PhpGenericTypeInjection.php similarity index 90% rename from src/Languages/DocComment/Injections/GenericTypeInjection.php rename to src/Languages/Php/Injections/PhpGenericTypeInjection.php index 8c03979..6a00632 100644 --- a/src/Languages/DocComment/Injections/GenericTypeInjection.php +++ b/src/Languages/Php/Injections/PhpGenericTypeInjection.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace Tempest\Highlight\Languages\DocComment\Injections; +namespace Tempest\Highlight\Languages\Php\Injections; use Tempest\Highlight\Escape; use Tempest\Highlight\Highlighter; use Tempest\Highlight\Injection; use Tempest\Highlight\Tokens\TokenTypeEnum; -final readonly class GenericTypeInjection implements Injection +final readonly class PhpGenericTypeInjection implements Injection { public function parse(string $content, Highlighter $highlighter): string { diff --git a/src/Languages/DocComment/Patterns/DocCommentGenericTypePattern.php b/src/Languages/Php/Patterns/PhpDocCommentGenericTypePattern.php similarity index 78% rename from src/Languages/DocComment/Patterns/DocCommentGenericTypePattern.php rename to src/Languages/Php/Patterns/PhpDocCommentGenericTypePattern.php index 11cc1ae..b6116fe 100644 --- a/src/Languages/DocComment/Patterns/DocCommentGenericTypePattern.php +++ b/src/Languages/Php/Patterns/PhpDocCommentGenericTypePattern.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tempest\Highlight\Languages\DocComment\Patterns; +namespace Tempest\Highlight\Languages\Php\Patterns; use Tempest\Highlight\IsPattern; use Tempest\Highlight\Pattern; @@ -10,7 +10,7 @@ use Tempest\Highlight\Tokens\TokenTypeEnum; #[PatternTest(input: '@param class-string $className', output: 'T')] -final readonly class DocCommentGenericTypePattern implements Pattern +final readonly class PhpDocCommentGenericTypePattern implements Pattern { use IsPattern; diff --git a/src/Languages/DocComment/Patterns/DocCommentParamTypePattern.php b/src/Languages/Php/Patterns/PhpDocCommentParamTypePattern.php similarity index 81% rename from src/Languages/DocComment/Patterns/DocCommentParamTypePattern.php rename to src/Languages/Php/Patterns/PhpDocCommentParamTypePattern.php index 0f07df8..ca31672 100644 --- a/src/Languages/DocComment/Patterns/DocCommentParamTypePattern.php +++ b/src/Languages/Php/Patterns/PhpDocCommentParamTypePattern.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tempest\Highlight\Languages\DocComment\Patterns; +namespace Tempest\Highlight\Languages\Php\Patterns; use Tempest\Highlight\IsPattern; use Tempest\Highlight\Pattern; @@ -11,7 +11,7 @@ #[PatternTest(input: '@param array|string $concrete', output: 'array|string')] #[PatternTest(input: '@param \\Foo $concrete', output: '\\Foo')] -final readonly class DocCommentParamTypePattern implements Pattern +final readonly class PhpDocCommentParamTypePattern implements Pattern { use IsPattern; diff --git a/src/Languages/DocComment/Patterns/DocCommentReturnTypePattern.php b/src/Languages/Php/Patterns/PhpDocCommentReturnTypePattern.php similarity index 80% rename from src/Languages/DocComment/Patterns/DocCommentReturnTypePattern.php rename to src/Languages/Php/Patterns/PhpDocCommentReturnTypePattern.php index be8744a..9bac9bc 100644 --- a/src/Languages/DocComment/Patterns/DocCommentReturnTypePattern.php +++ b/src/Languages/Php/Patterns/PhpDocCommentReturnTypePattern.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tempest\Highlight\Languages\DocComment\Patterns; +namespace Tempest\Highlight\Languages\Php\Patterns; use Tempest\Highlight\IsPattern; use Tempest\Highlight\Pattern; @@ -11,7 +11,7 @@ #[PatternTest(input: '@return array|string', output: 'array|string')] #[PatternTest(input: '@return \\Foo', output: '\\Foo')] -final readonly class DocCommentReturnTypePattern implements Pattern +final readonly class PhpDocCommentReturnTypePattern implements Pattern { use IsPattern; diff --git a/src/Languages/DocComment/Patterns/DocCommentTemplateTypePattern.php b/src/Languages/Php/Patterns/PhpDocCommentTemplateTypePattern.php similarity index 77% rename from src/Languages/DocComment/Patterns/DocCommentTemplateTypePattern.php rename to src/Languages/Php/Patterns/PhpDocCommentTemplateTypePattern.php index 544e5b3..38578a9 100644 --- a/src/Languages/DocComment/Patterns/DocCommentTemplateTypePattern.php +++ b/src/Languages/Php/Patterns/PhpDocCommentTemplateTypePattern.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tempest\Highlight\Languages\DocComment\Patterns; +namespace Tempest\Highlight\Languages\Php\Patterns; use Tempest\Highlight\IsPattern; use Tempest\Highlight\Pattern; @@ -10,7 +10,7 @@ use Tempest\Highlight\Tokens\TokenTypeEnum; #[PatternTest(input: '@template T', output: 'T')] -final readonly class DocCommentTemplateTypePattern implements Pattern +final readonly class PhpDocCommentTemplateTypePattern implements Pattern { use IsPattern; diff --git a/src/Languages/DocComment/Patterns/DocCommentVarTypePattern.php b/src/Languages/Php/Patterns/PhpDocCommentVarTypePattern.php similarity index 81% rename from src/Languages/DocComment/Patterns/DocCommentVarTypePattern.php rename to src/Languages/Php/Patterns/PhpDocCommentVarTypePattern.php index cd8a269..5e2749a 100644 --- a/src/Languages/DocComment/Patterns/DocCommentVarTypePattern.php +++ b/src/Languages/Php/Patterns/PhpDocCommentVarTypePattern.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tempest\Highlight\Languages\DocComment\Patterns; +namespace Tempest\Highlight\Languages\Php\Patterns; use Tempest\Highlight\IsPattern; use Tempest\Highlight\Pattern; @@ -11,7 +11,7 @@ #[PatternTest(input: '@var array|string $concrete', output: 'array|string')] #[PatternTest(input: '@var \\Foo $concrete', output: '\\Foo')] -final readonly class DocCommentVarTypePattern implements Pattern +final readonly class PhpDocCommentVarTypePattern implements Pattern { use IsPattern; diff --git a/src/Languages/DocComment/Patterns/DocCommentVariablePattern.php b/src/Languages/Php/Patterns/PhpDocCommentVariablePattern.php similarity index 84% rename from src/Languages/DocComment/Patterns/DocCommentVariablePattern.php rename to src/Languages/Php/Patterns/PhpDocCommentVariablePattern.php index 82019af..bd2d915 100644 --- a/src/Languages/DocComment/Patterns/DocCommentVariablePattern.php +++ b/src/Languages/Php/Patterns/PhpDocCommentVariablePattern.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tempest\Highlight\Languages\DocComment\Patterns; +namespace Tempest\Highlight\Languages\Php\Patterns; use Tempest\Highlight\IsPattern; use Tempest\Highlight\Pattern; @@ -13,7 +13,7 @@ #[PatternTest(input: '@param $concrete', output: '$concrete')] #[PatternTest(input: '@var Foo $concrete', output: '$concrete')] #[PatternTest(input: '@var $concrete', output: '$concrete')] -final readonly class DocCommentVariablePattern implements Pattern +final readonly class PhpDocCommentVariablePattern implements Pattern { use IsPattern; diff --git a/src/Languages/Php/PhpDocCommentLanguage.php b/src/Languages/Php/PhpDocCommentLanguage.php new file mode 100644 index 0000000..5bad572 --- /dev/null +++ b/src/Languages/Php/PhpDocCommentLanguage.php @@ -0,0 +1,29 @@ +assertSame( $expected, - $highlighter->parse($content, 'doc'), + $highlighter->parse($content, new PhpDocCommentLanguage()), ); } diff --git a/tests/targets/test.md b/tests/targets/test.md index 85e7252..5ca455e 100644 --- a/tests/targets/test.md +++ b/tests/targets/test.md @@ -1,13 +1,12 @@ ```php -final readonly class BookController -{ - #[Post(uri: '/books/create')] - public function store(BookRequest $request): Response - { - $book = map($request)->to(Book::class)->save(); - - return response() - ->redirect(uri([self::class, 'show'], id: $book->id)); - } -} +/** + * This function will do some things + * + * @template T + * @param class-string $className the class' name + * @param int $id + * @return T|null + * + * That's about all + */ ``` \ No newline at end of file